2022-10-08 22:11:59 -04:00
var modName = "mods/spouts.js" ;
var runAfterAutogenMod = "mods/runAfterAutogen and onload restructure.js" ;
2022-11-12 22:08:04 -05:00
var libraryMod = "mods/code_library.js" ;
2022-04-21 13:38:47 -04:00
2022-11-12 22:08:04 -05:00
if ( enabledMods . includes ( runAfterAutogenMod ) && enabledMods . includes ( libraryMod ) ) {
2022-12-19 10:35:14 -05:00
//Generate spouts
if ( urlParams . get ( 'generateSpouts' ) !== null ) { //if the variable exists at all
generateSpouts = true
} else { //if it doesn't (and it returns null)
generateSpouts = false
}
2022-10-08 22:11:59 -04:00
if ( urlParams . get ( 'spoutIncludeRandom' ) !== null ) { //if the variable exists at all
spoutIncludeRandom = true
} else { //if it doesn't (and it returns null)
spoutIncludeRandom = false
}
2022-04-21 13:38:47 -04:00
2022-11-14 17:06:51 -05:00
eLists . SPOUT = [ "spout" , "udder" , "torch" ] ;
2022-11-13 13:07:20 -05:00
var excludedSpoutElements = [ "ketchup" , "liquid_cloner" , "fire_cloner" ]
2022-11-14 17:06:51 -05:00
var includedSpouts = [ "ketchup_spout" , "spout" , "udder" , "torch" ]
2022-11-13 13:07:20 -05:00
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 spouted, but are refused even though the condition is true, to be spouted
function defaultSpoutCondition ( 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 ( excludedSpoutElements . 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-12 13:11:22 -05:00
//Generator function
//Standalone generator
function generateSpout ( spoutElements , isAfterScriptLoading = false ) { //it can be a single element, though
//To specify an array spout, 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 spout . 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 ( spoutElements ) === "string" ) { //it should be an array, so string check
//console.log("String detected");
if ( spoutElements . includes ( "," ) ) { //comma-separated string?
//console.log("Splitting string to array");
spoutElements = spoutElements . split ( "," ) ; //,SS to array
} else {
//console.log("Wrapping string in array");
spoutElements = [ spoutElements ] ; //single string to array
} ;
2022-11-02 16:59:53 -04:00
} ;
2022-11-12 13:11:22 -05:00
for ( aaf = 0 ; aaf < spoutElements . length ; aaf ++ ) {
var elementOfSpout = spoutElements [ aaf ] ;
var startColor ;
var randomExcl = 0 ;
2022-12-19 10:35:14 -05:00
var isNocheer = 0 ;
2022-11-12 13:11:22 -05:00
//console.log("randomExcl set")
//console.log(elementOfSpout);
var spoutName ;
if ( typeof ( elementOfSpout === "string" ) ) { //comma separated string check
if ( elementOfSpout . includes ( "," ) ) { //if it is
elementOfSpout = elementOfSpout . split ( "," ) ; //to array
elementOfSpout = elementOfSpout . filter ( function ( e ) { //strip nonexistent elements
return typeof ( elements [ e ] ) === "object" ;
} ) ;
} ;
} ;
if ( Array . isArray ( elementOfSpout ) ) {
spoutName = ` ${ elementOfSpout . join ( "_" ) } _spout ` ; //auto placer element name
//array case color concatenator and excludeRandom handler
startColor = [ ] ;
//console.log(elementOfSpout);
for ( ll = 0 ; ll < elementOfSpout . length ; ll ++ ) {
if ( typeof ( elements [ elementOfSpout [ ll ] ] . excludeRandom !== "undefined" ) ) { //if excludeRandom exists (prevent TypeError)
if ( elements [ elementOfSpout [ ll ] ] . excludeRandom ) { //it it's true
randomExcl = 1 ; //the whole array spout is excluded
//console.log("array nyet" + elementOfSpout);
} ;
} ;
//console.log(elementOfSpout[ll]);
startColor = startColor . concat ( elements [ elementOfSpout [ ll ] ] . color ) ;
} ;
2022-12-19 10:35:14 -05:00
for ( ll = 0 ; ll < elementOfSpout . length ; ll ++ ) {
if ( typeof ( elements [ elementOfSpout [ ll ] ] . nocheer !== "undefined" ) ) { //if nocheer exists (prevent TypeError)
if ( elements [ elementOfSpout [ ll ] ] . nocheer ) { //it it's true
isNocheer = 1 ; //the whole array spout is excluded
//console.log("array nyet" + elementOfSpout);
} ;
} ;
//console.log(elementOfSpout[ll]);
startColor = startColor . concat ( elements [ elementOfSpout [ ll ] ] . color ) ;
} ;
2022-11-12 13:11:22 -05:00
} else { //they should all be strings, so here
spoutName = ` ${ elementOfSpout } _spout ` ; //auto placer element name
startColor = elements [ elementOfSpout ] . color ;
if ( typeof ( elements [ elementOfSpout ] . excludeRandom !== "undefined" ) ) { //if excludeRandom exists (prevent TypeError)
if ( elements [ elementOfSpout ] . excludeRandom ) { //it it's true
//console.log("nyet " + elementOfSpout);
randomExcl = 1 ; //the spout is excluded
} else {
//console.log("allow " + elementOfSpout);
randomExcl = 0 ;
} ;
} ;
2022-12-19 10:35:14 -05:00
if ( typeof ( elements [ elementOfSpout ] . nocheer !== "undefined" ) ) { //if nocheer exists (prevent TypeError)
if ( elements [ elementOfSpout ] . nocheer ) { //it it's true
//console.log("nyet " + elementOfSpout);
isNocheer = 1 ; //the spout is excluded
} else {
//console.log("allow " + elementOfSpout);
isNocheer = 0 ;
} ;
} ;
2022-11-12 13:11:22 -05:00
} ;
//Color gen
if ( Array . isArray ( startColor ) ) { //Average arrays, make colors rgb()
startColor = averageRgbPrefixedColorArray ( startColor ) ;
} else {
2022-11-12 22:08:04 -05:00
startColor = rgbHexCatcher ( startColor ) ;
2022-11-12 13:11:22 -05:00
} ;
var newColorObject = rgbStringToObject ( startColor ) ;
//End color gen
//The spout
//console.log(elementOfSpout);
var firstInfo , firstTemp ;
if ( Array . isArray ( elementOfSpout ) ) {
firstInfo = elements [ elementOfSpout [ 0 ] ] ;
firstTemp = airTemp ;
if ( typeof ( firstInfo . temp ) !== "undefined" ) {
firstTemp = firstInfo . temp ;
} ;
} else {
firstInfo = elements [ elementOfSpout ] ;
firstTemp = airTemp ;
if ( typeof ( firstInfo . temp ) !== "undefined" ) {
firstTemp = firstInfo . temp ;
} ;
} ;
elementOfSpout = tryJoin ( elementOfSpout , "," ) ;
//console.log(elementOfSpout);
elements [ spoutName ] = {
color : startColor ,
insulate : true ,
colorObject : newColorObject ,
behavior : [
[ "XX" , ` CR: ${ elementOfSpout } ` , "XX" ] ,
[ ` CR: ${ elementOfSpout } ` , "XX" , ` CR: ${ elementOfSpout } ` ] ,
[ "XX" , ` CR: ${ elementOfSpout } ` , "XX" ]
] ,
category : "spouts" ,
temp : firstTemp ,
hardness : 1 ,
} ;
if ( ! randomExcl ) {
if ( typeof ( spoutChoices ) === "undefined" ) {
spoutChoices = [ ]
} ;
if ( ! spoutChoices . includes ( spoutName ) ) {
spoutChoices . push ( spoutName ) ;
} ;
}
if ( spoutIncludeRandom ) {
randomExcl ? elements [ spoutName ] . excludeRandom = true : elements [ spoutName ] . excludeRandom = false ;
} else {
elements [ spoutName ] . excludeRandom = true ;
} ;
2022-12-19 10:35:14 -05:00
if ( isNocheer ) {
elements [ spoutName ] . nocheer = true ;
}
2022-11-12 22:08:04 -05:00
if ( isAfterScriptLoading ) {
elementCount ++ ; //increment for new spout element
2022-12-19 10:35:14 -05:00
if ( settings . cheerful && elements [ spoutName ] . nocheer ) {
elements [ spoutName ] . hidden = true ;
hiddenCount ++ ;
} else {
createElementButton ( spoutName ) ;
} ;
2022-11-12 22:08:04 -05:00
elements [ spoutName ] . 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-11-14 17:06:51 -05:00
eLists . SPOUT . push ( spoutName ) ;
2022-11-02 16:59:53 -04:00
} ;
} ;
2022-11-12 13:11:22 -05:00
runAfterAutogen ( function ( ) {
2022-12-19 10:35:14 -05:00
if ( generateSpouts ) {
liquidArray = Object . keys ( elements ) . filter ( function ( e ) {
return ( defaultSpoutCondition ( e ) ) ;
} ) ;
liquidArray . push ( [ "rock" , "sand" ] ) ;
generateSpout ( liquidArray , false ) ;
2022-09-01 13:25:46 -04:00
} ;
2022-09-01 14:50:10 -04:00
} ) ;
2022-10-08 22:11:59 -04:00
elements . random _spout = {
color : [ "#3e5f8a" , "#a334ec" , "#ea96f9" , "#a6ecf6" , "#70ebc8" , "#d9286b" , "#7eed91" , "#a18b30" ] ,
behavior : behaviors . WALL ,
category : "special" ,
excludeRandom : true ,
tick : function ( pixel ) {
changePixel ( pixel , spoutChoices [ Math . floor ( Math . random ( ) * spoutChoices . length ) ] )
} ,
} ;
} else {
2022-11-12 22:08:04 -05:00
if ( ! enabledMods . includes ( runAfterAutogenMod ) ) { enabledMods . splice ( enabledMods . indexOf ( modName ) , 0 , runAfterAutogenMod ) } ;
if ( ! enabledMods . includes ( libraryMod ) ) { enabledMods . splice ( enabledMods . indexOf ( modName ) , 0 , libraryMod ) } ;
alert ( ` The " ${ runAfterAutogenMod } " and " ${ libraryMod } " mods are required; any missing mods in this list have been automatically inserted (reload for this to take effect). ` )
2022-10-08 22:11:59 -04:00
localStorage . setItem ( "enabledMods" , JSON . stringify ( enabledMods ) ) ;
2022-09-01 14:50:10 -04:00
} ;