mirror of
https://github.com/raeleus/Hashtag-DnD.git
synced 2025-07-05 13:10:28 -04:00
Don't allow duplicate names with #setupenemy
This commit is contained in:
parent
125001bec3
commit
31a469c5ae
2 changed files with 24 additions and 1 deletions
14
Library.js
14
Library.js
|
@ -886,6 +886,20 @@ function createEnemy(name, health, ac, damage, initiative, ...spells) {
|
|||
return enemy
|
||||
}
|
||||
|
||||
function getUniqueName(name) {
|
||||
const letters = ["A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z"]
|
||||
var letterIndex = 0
|
||||
|
||||
var newName
|
||||
var enemyMatches
|
||||
do {
|
||||
newName = `${name} ${letters[letterIndex++]}`
|
||||
enemyMatches = state.enemies.filter(x => x.name.toLowerCase() == newName.toLowerCase())
|
||||
} while (enemyMatches.length > 0 && letterIndex < letters.length)
|
||||
|
||||
return newName
|
||||
}
|
||||
|
||||
function createInitiativeOrder() {
|
||||
state.initiativeOrder = []
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue