-
-
Notifications
You must be signed in to change notification settings - Fork 83
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
12 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,21 +1,17 @@ | ||
import type { APIEmbedField } from 'discord.js'; | ||
|
||
export const calculateAmountOfTrue = (array: boolean[]) => { | ||
// get the amount of true values before endIndex, stopping at the first false value | ||
for (let i = array.length - 1; i >= 0; i--) { | ||
if (!array[i]) { | ||
return array.length - i; | ||
} | ||
} | ||
|
||
return array.length - 1; | ||
}; | ||
|
||
export function calculateInlineIndex(fields: APIEmbedField[], currentFieldIndex: number) { | ||
// get the amount of inline fields before the current field without gaps | ||
const inlineFieldsBefore = fields.slice(0, currentFieldIndex).map((e) => e.inline ?? false); | ||
const startIndex = currentFieldIndex - 1; | ||
|
||
const amount = calculateAmountOfTrue(inlineFieldsBefore) + 1; | ||
for (let i = startIndex; i >= 0; i--) { | ||
const field = fields[i]; | ||
if (!field) continue; | ||
|
||
if (field.inline === false) { | ||
const amount = startIndex - i; | ||
return (amount % 3) + 1; | ||
} | ||
} | ||
|
||
return (amount % 3) + 1; | ||
return (currentFieldIndex % 3) + 1; | ||
} |