Created
June 14, 2016 13:32
-
-
Save sfentress/ada05abe65c4587e1daa53e303b6c2eb to your computer and use it in GitHub Desktop.
Traits from filename
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var img = org.getImageName(), // "st_m_wing_allLimb_a5_flair_noHorn_noRostral_bogbreath.png" | |
imgArr = img.split("_"), // ["st", "m", "wing", "allLimb", "a5", "flair", "noHorn", "noRostral", "bogbreath.png"] | |
traitCodes = { | |
st: "Steel", | |
co: "Copper", | |
ar: "Silver", | |
go: "Gold", | |
ch: "Charcoal", | |
ea: "Lava", | |
du: "Ash", | |
sa: "Sand", | |
wing: "Wings", | |
noWing: "No wings", | |
a5: "Five armor", | |
a3: "Three armor", | |
a1: "One armor", | |
a0: "No armor", | |
flair: "Long tail", | |
kink: "Kinked tail", | |
short: "Short tail", | |
horn: "Horns", | |
noHorn: "No horns", | |
rostral: "Nose spike", | |
noRostral: "No nose spike", | |
"bogbreath.png": "Bog breath", | |
"healthy.png": "Healthy" | |
}, | |
traits = imgArr.map(function(code) { | |
if (traitCodes[code]) | |
return traitCodes[code]; | |
else return code; | |
}); | |
// => ["Steel", "m", "Wings", "allLimb", "Five armor", "Long tail", "No horns", "No nose spike", "Bog breath"] | |
traits.remove(1); // remove "m" or "f" | |
// change the single-value version of the limbs trait into two separate traits | |
// for forelimbs and hindlimbs | |
var forelimbTrait = "No forelimbs", | |
hindlimbTrait = "No hindlimbs"; | |
if (traits[2] == "forelimbs") { | |
forelimbTrait = "Forelimbs"; | |
} else if (traits[2] == "hindlimbs") { | |
hindlimbTrait = "Hindlimbs"; | |
} else if (traits[2] == "allLimb") { | |
forelimbTrait = "Forelimbs"; | |
hindlimbTrait = "Hindlimbs"; | |
} | |
traits.splice(2, 1 forelimbTrait, hindlimbTrait); | |
console.log(traits); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment