Line data Source code
1 : /** 2 : * This class provides a cache for accessing attack effects stored in JSON files. 3 : */ 4 : class AttackEffects 5 : { 6 : constructor() 7 : { 8 1 : let effectsDataObj = {}; 9 1 : this.effectReceivers = []; 10 : 11 1 : for (let filename of Engine.ListDirectoryFiles("simulation/data/attack_effects", "*.json", false)) 12 : { 13 2 : let data = Engine.ReadJSONFile(filename); 14 2 : if (!data) 15 0 : continue; 16 : 17 2 : if (effectsDataObj[data.code]) 18 : { 19 0 : error("Encountered two effect types with the code " + data.name + "."); 20 0 : continue; 21 : } 22 : 23 2 : effectsDataObj[data.code] = data; 24 : 25 2 : this.effectReceivers.push({ 26 : "type": data.code, 27 : "IID": data.IID, 28 : "method": data.method 29 : }); 30 : } 31 : 32 1 : let effDataSort = (a, b) => a.order < b.order ? -1 : a.order > b.order ? 1 : 0; 33 1 : let effSort = (a, b) => effDataSort( 34 : effectsDataObj[a.type], 35 : effectsDataObj[b.type] 36 : ); 37 1 : this.effectReceivers.sort(effSort); 38 : 39 1 : deepfreeze(this.effectReceivers); 40 : } 41 : 42 : /** 43 : * @return {Object[]} - The effects possible with their data. 44 : */ 45 : Receivers() 46 : { 47 1 : return this.effectReceivers; 48 : } 49 : }