2022-11-13 11:37:09 -05:00
var modName = "mods/more_fairies.js" ;
var runAfterAutogenMod = "mods/runAfterAutogen and onload restructure.js" ;
var libraryMod = "mods/code_library.js" ;
var feyAndMoreMod = "mods/fey_and_more.js" ;
2022-01-22 19:05:41 -05:00
2022-11-13 11:37:09 -05:00
if ( enabledMods . includes ( runAfterAutogenMod ) && enabledMods . includes ( libraryMod ) && enabledMods . includes ( feyAndMoreMod ) ) {
//keep old fairies
2022-01-22 19:05:41 -05:00
elements . acid _fairy = {
name : "acid fairy" ,
color : [ "#e2f777" , "#d1ff94" , "#d8f7c1" ] ,
behavior : [
"XX|M1|M1" ,
"XX|FX%5|XX" ,
"XX|CR:acid%0.5 AND CR:fairy_dust%0.005 AND M1|M1" ,
] ,
state : "solid" ,
category : "fey" ,
}
elements . oil _fairy = {
name : "oil fairy" ,
color : [ "#636360" , "#a6956f" , "#a3816d" , "#cfc191" ] ,
behavior : [
"XX|M1|M1" ,
"XX|FX%5|XX" ,
"XX|CR:oil%0.5 AND CR:fairy_dust%0.005 AND M1|M1" ,
] ,
state : "solid" ,
category : "fey" ,
}
elements . honey _fairy = {
name : "honey fairy" ,
color : [ "#ffeaa6" , "#ffe987" , "#f2e7c2" ] ,
behavior : [
"XX|M1|M1" ,
"XX|FX%5|XX" ,
"XX|CR:honey%0.5 AND CR:fairy_dust%0.005 AND M1|M1" ,
] ,
state : "solid" ,
category : "fey" ,
}
2022-11-13 13:07:46 -05:00
var excludedFairyElements = [ ]
var backupCategoryWhitelist = [ "land" , "powders" , "weapons" , "food" , "life" , "corruption" , "states" , "fey" , "Fantastic Creatures" , "dyes" , "energy liquids" , "random liquids" , "random gases" , "random rocks" ] ;
var backupElementWhitelist = [ "mercury" , "chalcopyrite_ore" , "chalcopyrite_dust" , "copper_concentrate" , "fluxed_copper_concentrate" , "unignited_pyrestone" , "ignited_pyrestone" , "everfire_dust" , "extinguished_everfire_dust" , "mistake" , "polusium_oxide" , "vaporized_polusium_oxide" , "glowstone_dust" , "redstone_dust" , "soul_mud" , "wet_soul_sand" , "nitrogen_snow" , "fusion_catalyst" , "coal" , "coal_coke" , "blast_furnace_fuel" , "molten_mythril" ] ;
//forces elements that logically should be fairied, but are refused even though the condition is true, to be fairied
function defaultFairyCondition ( name ) {
if ( typeof ( elements [ name ] ) !== "object" ) {
throw new Error ( ` Nonexistent element ${ name } ` ) ;
} ;
var info = elements [ name ] ;
//console.log(`${name} (${JSON.stringify(elements[name])})`);
if ( typeof ( info . state ) === "undefined" ) {
var state = null ;
} else {
var state = info . state ;
} ;
if ( typeof ( info . category ) === "undefined" ) {
var category = "other" ;
} else {
var category = info . category ;
} ;
if ( excludedFairyElements . includes ( name ) ) {
return false
} ;
var include = false ;
if ( [ "liquid" , "gas" ] . includes ( state ) ) {
include = true ;
} ;
if ( info . movable ) {
include = true ;
} ;
if ( backupCategoryWhitelist . includes ( category ) ) {
include = true ;
} ;
if ( backupElementWhitelist . includes ( name ) ) {
include = true ;
} ;
if ( category . includes ( "mudstone" ) ) {
include = true ;
} ;
//console.log(include);
return include ;
} ;
2022-11-13 11:37:09 -05:00
if ( urlParams . get ( 'fairyIncludeRandom' ) !== null ) { //if the variable exists at all
fairyIncludeRandom = true
} else { //if it doesn't (and it returns null)
fairyIncludeRandom = false
}
//Generator function
function tryJoin ( stringOrArray , joiner ) {
//console.log(`tryJoin: ${stringOrArray}`);
if ( typeof ( stringOrArray ) === "string" ) {
//console.log("tryJoin: String");
return stringOrArray ;
} else if ( Array . isArray ( stringOrArray ) ) {
//console.log("tryJoin: Array");
return stringOrArray . join ( joiner ) ;
} else {
throw new TypeError ( ` Unexpected type: ${ typeof ( stringOrArray ) } ` ) ;
} ;
} ;
2022-01-22 19:05:41 -05:00
2022-11-13 11:37:09 -05:00
//Standalone generator
function generateFairy ( fairyElements , isAfterScriptLoading = false ) { //it can be a single element, though
//To specify an array fairy, have the array be inside another array.
/ * F o r r e a s o n s r e l a t e d t o h o w e l e m e n t c o l o r s a r e l o a d e d , i f t h i s f u n c t i o n i s b e i n g r u n f r o m a J S m o d f i l e , i s A f t e r S c r i p t L o a d i n g s h o u l d b e f a l s e .
Otherwise , you ' ll get TypeErrors for some reason when trying to place your fairy . If this is being run after the game has loaded ( e . g . in the console ) ,
then isAfterScriptLoading should be true or you might also get TypeErrors ( this latter case was a bit inconsistent when I tested it , but
the former case wasn ' t . * * isAfterScriptLoading must be false when this function is run from a JS mod file * * . * /
if ( typeof ( fairyElements ) === "string" ) { //it should be an array, so string check
//console.log("String detected");
if ( fairyElements . includes ( "," ) ) { //comma-separated string?
//console.log("Splitting string to array");
fairyElements = fairyElements . split ( "," ) ; //,SS to array
} else {
//console.log("Wrapping string in array");
fairyElements = [ fairyElements ] ; //single string to array
} ;
} ;
for ( aaf = 0 ; aaf < fairyElements . length ; aaf ++ ) {
var elementOfFairy = fairyElements [ aaf ] ;
var startColor ;
var randomExcl = 0 ;
//console.log("randomExcl set")
//console.log(elementOfFairy);
2022-01-22 19:05:41 -05:00
2022-11-13 11:37:09 -05:00
var fairyName ;
2022-01-22 19:05:41 -05:00
2022-11-13 11:37:09 -05:00
if ( typeof ( elementOfFairy === "string" ) ) { //comma separated string check
if ( elementOfFairy . includes ( "," ) ) { //if it is
elementOfFairy = elementOfFairy . split ( "," ) ; //to array
elementOfFairy = elementOfFairy . filter ( function ( e ) { //strip nonexistent elements
return typeof ( elements [ e ] ) === "object" ;
} ) ;
} ;
} ;
if ( Array . isArray ( elementOfFairy ) ) {
fairyName = ` ${ elementOfFairy . join ( "_" ) } _fairy ` ; //auto placer element name
//array case color concatenator and excludeRandom handler
startColor = [ ] ;
//console.log(elementOfFairy);
for ( ll = 0 ; ll < elementOfFairy . length ; ll ++ ) {
if ( typeof ( elements [ elementOfFairy [ ll ] ] . excludeRandom !== "undefined" ) ) { //if excludeRandom exists (prevent TypeError)
if ( elements [ elementOfFairy [ ll ] ] . excludeRandom ) { //it it's true
randomExcl = 1 ; //the whole array fairy is excluded
//console.log("array nyet" + elementOfFairy);
} ;
} ;
//console.log(elementOfFairy[ll]);
startColor = startColor . concat ( elements [ elementOfFairy [ ll ] ] . color ) ;
} ;
} else { //they should all be strings, so here
fairyName = ` ${ elementOfFairy } _fairy ` ; //auto placer element name
startColor = elements [ elementOfFairy ] . color ;
if ( typeof ( elements [ elementOfFairy ] . excludeRandom !== "undefined" ) ) { //if excludeRandom exists (prevent TypeError)
if ( elements [ elementOfFairy ] . excludeRandom ) { //it it's true
//console.log("nyet " + elementOfFairy);
randomExcl = 1 ; //the fairy is excluded
} else {
//console.log("allow " + elementOfFairy);
randomExcl = 0 ;
} ;
} ;
} ;
//Color gen
if ( Array . isArray ( startColor ) ) { //Average arrays, make colors rgb()
startColor = averageRgbPrefixedColorArray ( startColor ) ;
} else {
startColor = rgbHexCatcher ( startColor ) ;
} ;
//console.log(`rgbStringToObject(${startColor}) from more_fairies.js`)
var newColorObjectArray = [ ] ;
var newColorArray = [ ] ;
for ( i = 0 ; i < elements . fairy . color . length ; i ++ ) {
var newFairyColorlet = elements . fairy . color [ i ] ;
var newColor = multiplyColors ( startColor , newFairyColorlet ) ;
var newColorJSON = multiplyColors ( startColor , newFairyColorlet , "json" ) ;
newColorArray . push ( newColor ) ;
newColorObjectArray . push ( newColorJSON ) ;
} ;
//End color gen
//The fairy
//console.log(elementOfFairy);
var firstInfo , firstTemp ;
if ( Array . isArray ( elementOfFairy ) ) {
firstInfo = elements [ elementOfFairy [ 0 ] ] ;
firstTemp = airTemp ;
if ( typeof ( firstInfo . temp ) !== "undefined" ) {
firstTemp = firstInfo . temp ;
} ;
} else {
firstInfo = elements [ elementOfFairy ] ;
firstTemp = airTemp ;
if ( typeof ( firstInfo . temp ) !== "undefined" ) {
firstTemp = firstInfo . temp ;
} ;
} ;
elementOfFairy = tryJoin ( elementOfFairy , "," ) ;
//console.log(elementOfFairy);
if ( ! elementExists ( fairyName ) ) {
elements [ fairyName ] = {
color : newColorArray ,
insulate : true ,
colorObject : newColorObjectArray ,
behavior : [
[ "XX" , "M1" , "M1" ] ,
[ "XX" , "FX%5" , "XX" ] ,
[ "XX" , ` CR: ${ elementOfFairy } %0.5 AND CR:fairy_dust%0.005 AND M1 ` , "M1" ]
] ,
category : "auto_fey" ,
temp : firstTemp ,
hardness : 1 ,
} ;
if ( typeof ( eLists ) === "undefined" ) {
eLists = { } ;
} ;
if ( typeof ( eLists . FAIRY ) === "undefined" ) {
eLists . FAIRY = [ ] ;
} ;
eLists . FAIRY . push ( fairyName ) ;
if ( ! randomExcl ) {
if ( typeof ( fairyChoices ) === "undefined" ) {
fairyChoices = [ ]
} ;
if ( ! fairyChoices . includes ( fairyName ) ) {
fairyChoices . push ( fairyName ) ;
} ;
}
if ( fairyIncludeRandom ) {
randomExcl ? elements [ fairyName ] . excludeRandom = true : elements [ fairyName ] . excludeRandom = false ;
} else {
elements [ fairyName ] . excludeRandom = true ;
} ;
if ( isAfterScriptLoading ) {
elementCount ++ ; //increment for new fairy element
createElementButton ( fairyName ) ;
elements [ fairyName ] . id = nextid ++ ;
document . getElementById ( "extraInfo" ) . innerHTML = "<small><p>There are " + elementCount + " elements, including " + hiddenCount + " hidden ones.</p><p>©2021-" + new Date ( ) . getFullYear ( ) + ". All Rights Reserved. <a href='https://r74n.com'>R74n</a></p></small>" ; //update extra info counts (and the copyright year, due to the method used)
} ;
} ;
} ;
2022-01-22 19:05:41 -05:00
} ;
2022-11-13 11:37:09 -05:00
runAfterAutogen ( function ( ) {
fairyArray = Object . keys ( elements ) . filter ( function ( e ) { //same criteria as spouts
2022-11-13 13:07:46 -05:00
return ( defaultFairyCondition ( e ) ) ;
2022-11-13 11:37:09 -05:00
} ) ;
generateFairy ( fairyArray , false ) ;
} ) ;
elements . spawn _random _fairy = {
color : [ "#3e5f8a" , "#a334ec" , "#ea96f9" , "#a6ecf6" , "#70ebc8" , "#d9286b" , "#7eed91" , "#a18b30" ] ,
behavior : behaviors . WALL ,
category : "special" ,
excludeRandom : true ,
tick : function ( pixel ) {
changePixel ( pixel , fairyChoices [ Math . floor ( Math . random ( ) * fairyChoices . length ) ] )
} ,
} ;
//Post-generation tasks
2022-11-13 13:00:07 -05:00
//Manual eLists.FAIRY updates
eLists . FAIRY . push ( "acid_fairy" ) ;
eLists . FAIRY . push ( "oil_fairy" ) ;
eLists . FAIRY . push ( "honey_fairy" ) ;
2022-11-13 11:37:09 -05:00
//Revamp fairykill
behaviors . FAIRYKILL _OLD = behaviors . FAIRYKILL ;
behaviors . FAIRYKILL = function ( pixel ) {
if ( pixel . start === pixelTicks ) { return }
if ( pixel . charge && elements [ pixel . element ] . behaviorOn ) {
pixelTick ( pixel )
2022-01-22 19:05:41 -05:00
}
2022-11-13 11:37:09 -05:00
var ignore = [ ] ;
if ( typeof ( elements [ pixel . element ] . ignore ) !== "undefined" ) {
ignore = elements [ pixel . element ] . ignore ;
} ;
for ( i = 0 ; i < adjacentCoords . length ; i ++ ) {
var coord = adjacentCoords [ i ] ;
var offsetX = coord [ 0 ] ;
var offsetY = coord [ 1 ] ;
var newX = pixel . x + offsetX ;
var newY = pixel . y + offsetY ;
if ( ! isEmpty ( newX , newY , true ) ) {
var newPixel = pixelMap [ newX ] [ newY ] ;
var newElement = newPixel . element ;
var isIgnored = ( newElement === ignore || ignore . includes ( newElement ) )
if ( eLists . FAIRY . includes ( newElement ) && ! isIgnored ) {
deletePixel ( newX , newY ) ;
} ;
} ;
} ;
doDefaults ( pixel ) ;
} ;
//Add ignores
var ignoreArray = [ "acid" , "iron" , "silver" , "steel" , "tungstensteel" , "void" , "liquid_void" , "chute" , "vute" , "drute" , "drolute" , "volute" , "alkahest" , "acid_gas" ] ;
for ( l = 0 ; l < ignoreArray . length ; l ++ ) {
var name = ignoreArray [ l ] ;
var fairyName = ` ${ ignoreArray [ l ] } _fairy ` ;
if ( elementExists ( name ) && elementExists ( fairyName ) ) {
var baseInfo = elements [ name ] ;
if ( typeof ( baseInfo . ignore ) === "undefined" ) {
baseInfo . ignore = [ ] ;
} else if ( typeof ( baseInfo . ignore ) === "string" ) {
baseInfo . ignore = [ baseInfo . ignore ] ;
} ;
baseInfo . ignore . push ( fairyName ) ;
} ;
} ;
//Add updated fairykills
var fairykillElements = [ "iron" , "silver" , "steel" , "tungstensteel" ] ;
for ( q = 0 ; q < fairykillElements . length ; q ++ ) {
var name = fairykillElements [ q ] ;
if ( elementExists ( name ) ) {
elements [ name ] . behavior = behaviors . FAIRYKILL ;
} ;
2022-01-22 19:05:41 -05:00
} ;
2022-11-13 11:37:09 -05:00
} else {
if ( ! enabledMods . includes ( runAfterAutogenMod ) ) { enabledMods . splice ( enabledMods . indexOf ( modName ) , 0 , runAfterAutogenMod ) } ;
if ( ! enabledMods . includes ( libraryMod ) ) { enabledMods . splice ( enabledMods . indexOf ( modName ) , 0 , libraryMod ) } ;
if ( ! enabledMods . includes ( feyAndMoreMod ) ) { enabledMods . splice ( enabledMods . indexOf ( modName ) , 0 , feyAndMoreMod ) } ;
alert ( ` The " ${ runAfterAutogenMod } ", " ${ libraryMod } ", and " ${ feyAndMoreMod } " mods are required; any missing mods in this list have been automatically inserted (reload for this to take effect). ` )
localStorage . setItem ( "enabledMods" , JSON . stringify ( enabledMods ) ) ;
} ;