Allow boolean to be interpreted as numeric 1

This commit is contained in:
b 2021-04-06 14:53:24 -07:00
parent 30eb3df121
commit f920e29c99
2 changed files with 20 additions and 9 deletions

View file

@ -5,6 +5,10 @@ function checkBool(v) {
} }
function checkNum(v) { function checkNum(v) {
if (typeof v === 'boolean') {
if (v) return 1;
return 0;
}
if (typeof v !== 'number') throw new Error(`Expected number, but got ${typeof v}`); if (typeof v !== 'number') throw new Error(`Expected number, but got ${typeof v}`);
return v; return v;
} }
@ -261,6 +265,9 @@ function staticCheck(expType, term) {
if (expType === 'any' || expType === term.type) { if (expType === 'any' || expType === term.type) {
return true; return true;
} }
if (expType === 'number' && term.type === 'boolean') {
return true;
}
throw new Error(`Expected ${expType}, but got ${term.type}`); throw new Error(`Expected ${expType}, but got ${term.type}`);
} }

View file

@ -3,19 +3,23 @@ realSpeeds = [] # TODO
atkSpd = 6 atkSpd = 6
#spellCycle = [1, 2, 1, 2, 0] #spellCycle = [1, 0, 1, 1, 0, 1, 1, 0, 1, 1, 0, 1, 1, 0, 1, 1, 0, 1, 2, 2]
#spellDelay = [0.5, 0.5, 0.5, 0.5, 0] #spellDelay = [0.5, 0, 0.5, 0.5, 0, 0.5, 0.5, 0, 0.5, 0.5, 0, 0.5, 0.5, 0, 0.5, 0.5, 0, 0.5, 1, 0.5]
spellCycle = [-1, 1, 0, 2, 1, 1] spellCycle = [1, 0, 1, 1, 1, 1, 1, 1, 1, 1, 0, 1, 1, 1, 1, 1, 1, 1, 2, 2]
spellDelay = [0.4312345, 0, 0.4, 0.4, 0.4, 0.4] spellDelay = [0.5, 0, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 1, 0.5]
#spellCycle = [-1, 1, 0, 2, 1, 1]
#spellDelay = [0.4312345, 0, 0.4, 0.4, 0.4, 0.4]
#spellCycle = [9, 0, 9, 0, 10, 0, 0] #spellCycle = [9, 0, 9, 0, 10, 0, 0]
#spellDelay = [0, 1.4, 0, 1.4, 0, 1.3, 1.3] #spellDelay = [0, 1.4, 0, 1.4, 0, 1.3, 1.3]
delayCycle = [1.2, 0, 0.4, 0.4, 0.4, 0.4] #delayCycle = [1.2, 0, 0.4, 0.4, 0.4, 0.4]
spellCycle = spellCycle*8 #spellCycle = spellCycle*8
spellDelay = spellDelay*4 + delayCycle + spellDelay*2 + delayCycle #spellDelay = spellDelay*4 + delayCycle + spellDelay*2 + delayCycle
simulation_end = 100 simulation_end = 100
manaRegens = [5, 0, 15] #manaRegens = [5, 0, 15]
manaSteals = [9, 13, 0] #manaSteals = [9, 13, 0]
manaRegens = [0, 0]
manaSteals = [8, 11]
import random import random
import math import math