Changeset View
Changeset View
Standalone View
Standalone View
binaries/data/mods/public/globalscripts/AttackEffects.js
Property | Old Value | New Value |
---|---|---|
svn:executable | * \ No newline at end of property | null |
// TODO: could be worth putting this in json files someday | /** | ||||||||||
const g_EffectTypes = ["Damage", "Capture", "ApplyStatus"]; | * This class provides a cache for accessing attack effects stored in JSON files. | ||||||||||
const g_EffectReceiver = { | */ | ||||||||||
"Damage": { | class AttackEffects | ||||||||||
"IID": "IID_Health", | { | ||||||||||
"method": "TakeDamage" | constructor() | ||||||||||
}, | { | ||||||||||
"Capture": { | let effectsDataObj = {}; | ||||||||||
"IID": "IID_Capturable", | this.effectReceivers = []; | ||||||||||
bb: why do we need this object? Seems like it is only used for checking duplicate codes, but that… | |||||||||||
"method": "Capture", | this.effectSounds = {}; | ||||||||||
"sound": "capture" | |||||||||||
}, | for (let filename of Engine.ListDirectoryFiles("simulation/data/attack_effects", "*.json", false)) | ||||||||||
"ApplyStatus": { | { | ||||||||||
"IID": "IID_StatusEffectsReceiver", | let data = Engine.ReadJSONFile(filename); | ||||||||||
"method": "ApplyStatus" | if (!data) | ||||||||||
continue; | |||||||||||
if (effectsDataObj[data.code]) | |||||||||||
{ | |||||||||||
error("Encountered two effect types with the code " + data.name + "."); | |||||||||||
continue; | |||||||||||
} | |||||||||||
effectsDataObj[data.code] = data; | |||||||||||
this.effectReceivers.push({ | |||||||||||
"type": data.code, | |||||||||||
"IID": data.IID, | |||||||||||
"method": data.method | |||||||||||
}); | |||||||||||
this.effectSounds[data.code] = data.sound || ""; | |||||||||||
} | |||||||||||
let effDataSort = (a, b) => a.order < b.order ? -1 : a.order > b.order ? 1 : 0; | |||||||||||
let effSort = (a, b) => effDataSort( | |||||||||||
effectsDataObj[a.type], | |||||||||||
effectsDataObj[b.type] | |||||||||||
Done Inline Actions
bb: | |||||||||||
); | |||||||||||
this.effectReceivers.sort(effSort); | |||||||||||
deepfreeze(this.effectReceivers); | |||||||||||
Done Inline ActionsHang on. Forget about the comment above, but you just stored the data under the code in an object and now search in an array with the same content for the correct code. While you could just query the correct code in the object. bb: Hang on. Forget about the comment above, but you just stored the data under the code in an… | |||||||||||
deepfreeze(this.effectSounds); | |||||||||||
} | |||||||||||
/** | |||||||||||
* @return {Object[]} - The effects possible with their data. | |||||||||||
*/ | |||||||||||
Receivers() | |||||||||||
{ | |||||||||||
return this.effectReceivers; | |||||||||||
} | |||||||||||
/** | |||||||||||
* @param {string} type - The type of effect to get the receiving sound for. | |||||||||||
* @return {string} - The name of the soundgroup to play. | |||||||||||
*/ | |||||||||||
GetSound(type) | |||||||||||
Done Inline ActionsI will forsee I want a function returning the whole this.effectReceivers. But that is easily added when requested bb: I will forsee I want a function returning the whole `this.effectReceivers`. But that is easily… | |||||||||||
{ | |||||||||||
return this.effectSounds[type] || ""; | |||||||||||
} | |||||||||||
} | } | ||||||||||
Done Inline ActionsNot sure if I'm in favor of the "attacked" hardcoding here. Also attackEffects without a sound tag should imho play no sound instead of a default. Maybe just move it to the json's too? bb: Not sure if I'm in favor of the "attacked" hardcoding here. Also attackEffects without a sound… | |||||||||||
}; |
Wildfire Games · Phabricator
why do we need this object? Seems like it is only used for checking duplicate codes, but that can be done directly from this.effectTypes or this.effectReceivers.