JSON as JS for C2
by Sam Fereday
JavaScript
/* I'm thinking about looking in to construct again, but rather than use json, just use js literals. Not overly hot about the idea, but it it means there's no need to use any sort of xhr stuff... let's see how complex it gets. By the way this is for that thousand floors idea that I've been toying with.
So this would be assigned as a plugin that loads right at app run time, that way everything's ready. You wouldn't save your user-specific stuff here by the way. That belongs in the realms of local storage or whatever other stuff that C2 is rocking at this point in time.
Frankly I have no idea why it's so hard to use JSON in C2, but I guess they had their reasons at some point.
The set up is fairly simple. A mass of data with some getters. Setters belong to your save data and volatile data, which we could also store in here temporarily at least and send the payload to save whenever we kick it off.
JSON can be integrated later on if a better way is found of course.
Also, since it's very game specific, we can just make custom methods that tap directly in to the bits we want. You can use models if you wish, but again, not much point probably.
... I'll clean it all up later. WIP!
*/
/// Types
// Stat modifiers - used by both items and abilities
var statTypes = {
addsHP: 0,
addsMP: 1,
addInt: 2,
addStr: 3,
addDef: 4
}
// Damage modifiers - used by both traps and abilities
var damageTypes = {
physical: 0,
nonElement: 1,
lightningElement: 2,
iceElement: 3,
fireElement: 4,
earthElement: 5,
waterElement: 6,
shadowElement: 7,
lightElement: 8
}
// Step types - used by all things, good for knowing attack or heal types, etc
var stepTypes = {
overTime: 0,
instTime: 1
}
/// Data storage class that holds it all together
var DS = function(){
// Fixed data (cannot or should not be modified at any point during game).
this.pickupData = [];
this.trapData = [];
this.enemyData = [];
this.abilityData = [];
// Volatile data (can be...