pineafan | 34369e6 | 2022-05-18 16:52:37 +0100 | [diff] [blame] | 1 | import getEmojiByName from "./getEmojiByName.js"; |
| 2 | |
TheCodedProf | 4a088b1 | 2023-06-06 15:29:59 -0400 | [diff] [blame^] | 3 | function pageIndicator(amount: number, selected: number, showDetails?: boolean, disabled?: boolean | string | boolean[]) { |
pineafan | 34369e6 | 2022-05-18 16:52:37 +0100 | [diff] [blame] | 4 | let out = ""; |
TheCodedProf | 4a088b1 | 2023-06-06 15:29:59 -0400 | [diff] [blame^] | 5 | // disabled = disabled ? "GRAY." : ""; |
| 6 | // If disabled is a string, make a list of booleans the same length as amount. |
| 7 | if (!Array.isArray(disabled)) disabled = new Array(amount).fill(disabled); |
| 8 | // If the length is wrong, fill extra with false |
| 9 | if (disabled.length !== amount) { disabled = disabled.concat(new Array(amount).fill(false)); } |
| 10 | const grey = disabled.map((x) => (x ? "GRAY." : "")); |
pineafan | e23c4ec | 2022-07-27 21:56:27 +0100 | [diff] [blame] | 11 | if (amount === 1) { |
TheCodedProf | 4a088b1 | 2023-06-06 15:29:59 -0400 | [diff] [blame^] | 12 | out += getEmojiByName("TRACKS.SINGLE." + grey[0] + (selected === 0 ? "ACTIVE" : "INACTIVE")); |
pineafan | 34369e6 | 2022-05-18 16:52:37 +0100 | [diff] [blame] | 13 | } else { |
| 14 | for (let i = 0; i < amount; i++) { |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame] | 15 | out += getEmojiByName( |
| 16 | "TRACKS.HORIZONTAL." + |
Skyler Grey | da16adf | 2023-03-05 10:22:12 +0000 | [diff] [blame] | 17 | (i === 0 ? "LEFT" : i === amount - 1 ? "RIGHT" : "MIDDLE") + |
| 18 | "." + |
TheCodedProf | 4a088b1 | 2023-06-06 15:29:59 -0400 | [diff] [blame^] | 19 | grey[i] + |
Skyler Grey | da16adf | 2023-03-05 10:22:12 +0000 | [diff] [blame] | 20 | (i === selected ? "ACTIVE" : "INACTIVE") |
pineafan | 34369e6 | 2022-05-18 16:52:37 +0100 | [diff] [blame] | 21 | ); |
| 22 | } |
| 23 | } |
| 24 | if (showDetails) { |
| 25 | out += " Page " + selected + " of " + amount; |
| 26 | } |
| 27 | return out; |
| 28 | } |
| 29 | |
Skyler Grey | da16adf | 2023-03-05 10:22:12 +0000 | [diff] [blame] | 30 | export const verticalTrackIndicator = ( |
| 31 | position: number, |
| 32 | active: string | boolean, |
| 33 | size: number, |
| 34 | disabled: string | boolean |
| 35 | ) => { |
TheCodedProf | b5e9d55 | 2023-01-29 15:43:26 -0500 | [diff] [blame] | 36 | active = active ? "ACTIVE" : "INACTIVE"; |
TheCodedProf | 46518a4 | 2023-02-18 17:08:23 -0500 | [diff] [blame] | 37 | disabled = disabled ? "GRAY." : ""; |
TheCodedProf | b5e9d55 | 2023-01-29 15:43:26 -0500 | [diff] [blame] | 38 | if (position === 0 && size === 1) return "TRACKS.SINGLE." + disabled + active; |
| 39 | if (position === size - 1) return "TRACKS.VERTICAL.BOTTOM." + disabled + active; |
| 40 | if (position === 0) return "TRACKS.VERTICAL.TOP." + disabled + active; |
| 41 | return "TRACKS.VERTICAL.MIDDLE." + disabled + active; |
| 42 | }; |
| 43 | |
| 44 | export const createVerticalTrack = (items: string[], active: boolean[], disabled?: boolean[]) => { |
| 45 | let out = ""; |
| 46 | if (!disabled) disabled = new Array(items.length).fill(false); |
| 47 | for (let i = 0; i < items.length; i++) { |
| 48 | out += getEmojiByName(verticalTrackIndicator(i, active[i] ?? false, items.length, disabled[i] ?? false)); |
| 49 | out += items[i] + "\n"; |
| 50 | } |
| 51 | return out; |
Skyler Grey | da16adf | 2023-03-05 10:22:12 +0000 | [diff] [blame] | 52 | }; |
TheCodedProf | b5e9d55 | 2023-01-29 15:43:26 -0500 | [diff] [blame] | 53 | |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame] | 54 | export default pageIndicator; |