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