2022-11-11 16:03:50 -05:00
var modName = "mods/prop.js" ;
var variablesMod = "mods/prop and prompt variables.js" ;
2022-09-14 14:37:03 -04:00
2022-11-11 16:03:50 -05:00
if ( enabledMods . includes ( variablesMod ) ) {
propProperty = "element" ;
propValue = "sand" ;
propType = "string" ;
numberAdjusterProperty = "temp" ;
numberAdjusterValue = 1 ;
numberAdjusterMode = "add" ;
numberAdjusterVerb = "adding" ;
2022-12-24 15:24:29 -05:00
numberAdjusterPreposition = "to" ;
numberAdjusterReverseOrder = false ;
2022-09-14 14:37:03 -04:00
2022-11-11 16:03:50 -05:00
function rgbStringToUnvalidatedObject ( string ) {
string = string . split ( "," ) ;
var red = parseFloat ( string [ 0 ] . substring ( 4 ) ) ;
var green = parseFloat ( string [ 1 ] ) ;
var blue = parseFloat ( string [ 2 ] . slice ( 0 , - 1 ) ) ;
return { r : red , g : green , b : blue } ;
} ;
function hslStringToUnvalidatedObject ( string ) {
string = string . split ( "," ) ;
var hue = parseFloat ( string [ 0 ] . substring ( 4 ) ) ;
var saturation = parseFloat ( string [ 1 ] . slice ( 0 , - 1 ) ) ;
var lightness = parseFloat ( string [ 2 ] . slice ( 0 , - 2 ) ) ;
return { h : hue , s : saturation , l : lightness } ;
} ;
2022-09-14 14:37:03 -04:00
2022-11-11 16:03:50 -05:00
document . addEventListener ( "keydown" , function ( e ) { //prop prompt listener
// , = propPrompt()
if ( e . keyCode == 188 ) {
e . preventDefault ( ) ;
shiftDown ? numberAdjusterPrompt ( ) : propPrompt ( ) ;
} ;
} ) ;
2022-09-14 14:37:03 -04:00
2022-11-11 16:03:50 -05:00
function propPrompt ( ) {
propProperty = prompt ( "Enter the property you want to set" ) ;
propValue = prompt ( "Enter the value you want to set to" ) ;
2022-09-14 14:37:03 -04:00
2022-11-11 16:03:50 -05:00
//special check: element
if ( propProperty === "element" ) {
//empty string
if ( propValue === "" ) {
alert ( "No element was specified!" ) ;
return false ;
} ;
// replace spaces with underscores
propValue = propValue . replace ( / /g , "_" ) ;
var propValueS = mostSimilarElement ( propValue ) ;
if ( propValueS === null || propValueS === undefined ) {
alert ( "Element \"" + value + "\" not found! Defaulting to sand." ) ;
propValue = "sand" ;
} else {
propValue = propValueS ;
} ;
2022-09-14 14:37:03 -04:00
} ;
2022-11-11 16:03:50 -05:00
//special check: color
if ( propProperty === "color" ) {
//empty string
if ( propValue === "" ) {
alert ( "No color was specified!" ) ;
return false ;
} ;
var splitValue = propValue . split ( "," ) ;
if ( ! propValue . startsWith ( "rgb(" ) ) { //if not RGB
if ( propValue . startsWith ( "hsl(" ) ) { //if HSL
if ( ! ( splitValue [ 1 ] . endsWith ( '%' ) ) || ! ( splitValue [ 2 ] . endsWith ( '%)' ) ) ) { //if missing percent symbols
alert ( colorInvalidError ) ;
return false ;
} ;
} else { //if not RGB and not HSL
2022-09-14 14:37:03 -04:00
alert ( colorInvalidError ) ;
return false ;
} ;
} ;
2022-11-11 16:03:50 -05:00
if ( propValue . split ( "," ) . length !== 3 ) { //if too short or long
alert ( colorInvalidError ) ;
2022-09-14 14:37:03 -04:00
return false ;
2022-11-11 16:03:50 -05:00
}
if ( propValue . startsWith ( "rgb(" ) ) { //if RGB
var checkedColorObject = rgbStringToUnvalidatedObject ( propValue ) ; //RGB NaN checking
if ( isNaN ( checkedColorObject . r ) || isNaN ( checkedColorObject . g ) || isNaN ( checkedColorObject . b ) ) {
//console.log(checkedColorObject);
alert ( "One or more color values are invalid!" ) ;
return false ;
} ;
} else if ( propValue . startsWith ( "hsl(" ) ) { //if HSL
var checkedColorObject = hslStringToUnvalidatedObject ( propValue ) ; //HSL NaN checking
if ( isNaN ( checkedColorObject . h ) || isNaN ( checkedColorObject . s ) || isNaN ( checkedColorObject . l ) ) {
//console.log(checkedColorObject);
alert ( "One or more color values are invalid!" ) ;
return false ;
} ;
} else { //if neither
alert ( colorInvalidError ) ;
2022-09-14 14:37:03 -04:00
return false ;
} ;
} ;
2022-11-11 16:03:50 -05:00
//special check: x
if ( propProperty === "x" ) {
//empty string
if ( ! propValue . isInteger ) {
alert ( "X values must be integers!" ) ;
} ;
2022-09-14 14:37:03 -04:00
} ;
2022-11-11 16:03:50 -05:00
if ( defaultNumberTypeValues . includes ( propProperty . toLowerCase ( ) ) ) {
propType = "number" ;
} else if ( defaultBooleanTypeValues . includes ( propProperty . toLowerCase ( ) ) ) {
propType = "boolean" ;
} else if ( defaultStringTypeValues . includes ( propProperty . toLowerCase ( ) ) ) {
propType = "string" ;
} else if ( defaultArrayTypeValues . includes ( propProperty . toLowerCase ( ) ) ) {
propType = "array" ;
2022-09-14 14:37:03 -04:00
} else {
2022-11-11 16:03:50 -05:00
propType = prompt ( "Enter the type of the value" ) ;
if ( stringSynonyms . includes ( propType ) ) {
propType = "string" ;
} else if ( numberSynonyms . includes ( propType ) ) {
propType = "number" ; //Infinity (case-sensitively) is a *number*.
} else if ( booleanSynonyms . includes ( propType ) ) {
propType = "boolean" ;
} else if ( objectSynonyms . includes ( propType ) ) {
propType = "object" ; //null (case-sensitively) is an *object*.
} else if ( arraySynonyms . includes ( propType ) ) {
propType = "array" ; //offset coords use arrays a lot
} ;
2022-09-14 14:37:03 -04:00
} ;
2022-11-11 16:03:50 -05:00
//Conversion
if ( propType === "number" ) {
propValue = parseFloat ( propValue ) ;
if ( isNaN ( propValue ) ) {
alert ( "Value is not a number!" ) ;
return false ;
} ;
} else if ( propType === "boolean" ) {
if ( synonymsOfTrue . includes ( propValue . toLowerCase ( ) ) ) {
propValue = true ;
} else if ( synonymsOfFalse . includes ( propValue . toLowerCase ( ) ) ) {
propValue = false ;
} else {
alert ( "Unrecognized boolean value: " + propValue + "." ) ;
return false ;
} ;
} else if ( propType === "object" ) {
try {
propValue = JSON . parse ( propValue ) ;
} catch ( error ) {
alert ( "JSON is invalid! Note that it requires quotes around keys as well as those curly {} parentheses." ) ;
return false ;
} ;
} else if ( propType === "array" ) {
2022-11-11 16:08:42 -05:00
array = propValue . split ( "," ) ;
2022-11-11 16:03:50 -05:00
for ( i = 0 ; i < array . length ; i ++ ) {
if ( array [ i ] . startsWith ( "s" ) ) { //String
array [ i ] = array [ i ] . substring ( 1 ) ;
} else if ( array [ i ] . startsWith ( "n" ) ) { //Number
array [ i ] = array [ i ] . substring ( 1 ) ;
if ( isNaN ( parseFloat ( array [ i ] ) ) ) {
alert ( array [ i ] + " is not a number!" ) ;
return false ;
} ;
array [ i ] = parseFloat ( array [ i ] ) ;
} else if ( array [ i ] . startsWith ( "o" ) ) { //Object
array [ i ] = array [ i ] . substring ( 1 ) ;
try {
array [ i ] = JSON . parse ( array [ i ] ) ;
} catch ( error ) {
alert ( array [ i ] + " is not valid JSON!" ) ;
return false ;
} ;
} else if ( array [ i ] . startsWith ( "b" ) ) { //Boolean
array [ i ] = array [ i ] . substring ( 1 ) ;
if ( synonymsOfTrue . includes ( array [ i ] . toLowerCase ( ) ) ) {
array [ i ] = true ;
} else if ( synonymsOfFalse . includes ( array [ i ] . toLowerCase ( ) ) ) {
array [ i ] = false ;
} else {
alert ( "Unrecognized boolean value: " + array [ i ] + "." ) ;
return false ;
} ;
} else {
alert ( array [ i ] + ' must start with "s" for a string, "n" for a number, "o" for an object, or "b" for a boolean.' ) ;
return false ;
} ;
} ;
2022-11-11 16:08:42 -05:00
propValue = array ;
2022-11-11 16:03:50 -05:00
} else if ( propType !== "string" ) {
alert ( "Unrecognized or unsupported type!" ) ;
2022-09-14 14:37:03 -04:00
return false ;
} ;
2022-11-11 16:03:50 -05:00
updatePropDescription ( ) ;
currentElement = "prop" ;
2022-09-14 14:37:03 -04:00
} ;
2022-11-11 16:03:50 -05:00
elements . prop = {
color : "#ff7f00" ,
tool : function ( pixel ) {
if ( propProperty === "element" ) {
pixel [ propProperty ] = propValue ;
pixel . temp = ( elements [ propValue ] . temp || pixel . temp ) ;
} else {
pixel [ propProperty ] = propValue ;
} ;
pixelTempCheck ( pixel ) ;
} ,
category : "tools" ,
desc : ` Sets properties of pixels.<br/>Currently setting ${ propProperty } to ${ propValue } ( ${ propType } ).<br/><span onclick=propPrompt() style= \" color: #ff00ff; \" ;>Press [,] or click here</span> to open the property tool prompt. ` ,
} ;
2022-09-14 14:37:03 -04:00
2022-11-11 16:03:50 -05:00
function updatePropDescription ( ) {
elements . prop . desc = ` Sets properties of pixels.<br/>Currently setting ${ propProperty } to ${ propValue } ( ${ propType } ).<br/><span onclick=propPrompt() style= \" color: #ff00ff; \" ;>Press [,] or click here</span> to open the property tool prompt. ` ;
} ;
2022-09-30 12:29:16 -04:00
2022-11-11 16:03:50 -05:00
function numberAdjusterPrompt ( ) {
2022-12-24 15:24:29 -05:00
var oldProperty = numberAdjusterProperty ;
if ( oldProperty === null ) {
oldProperty = "temp" ;
} ;
2022-11-11 16:03:50 -05:00
numberAdjusterProperty = prompt ( "Enter the property you want to change" ) ;
2022-12-24 15:24:29 -05:00
if ( numberAdjusterProperty === null ) {
numberAdjusterProperty = oldProperty ;
return false ;
} ;
2022-11-11 16:03:50 -05:00
numberAdjusterValue = prompt ( "Enter the value you want to use" ) ;
2022-12-24 15:24:29 -05:00
numberAdjusterMode = prompt ( "Enter the operation you want to use" ) ;
2022-09-30 12:29:16 -04:00
2022-11-11 16:03:50 -05:00
//property check
2022-12-24 15:24:29 -05:00
if ( numberAdjusterProperty === "" ) {
2022-11-11 16:03:50 -05:00
alert ( "No property was specified! Defaulting to temp." ) ;
numberAdjusterProperty = "temp" ;
} ;
2022-09-30 12:29:16 -04:00
2022-11-11 16:03:50 -05:00
//value check
if ( isNaN ( parseFloat ( numberAdjusterValue ) ) ) {
if ( numberAdjusterValue === "" || numberAdjusterValue === null ) {
//console.log("Null value path");
alert ( "No value was specified! Defaulting to 1" ) ;
numberAdjusterValue = 1 ;
//console.log(numberAdjusterValue);
} else {
//console.log("NaN value path");
alert ( "Invalid value! The value must be a number (defaulting to 1)" ) ;
numberAdjusterValue = 1 ;
//console.log(numberAdjusterValue);
} ;
2022-09-30 12:29:16 -04:00
} ;
2022-11-11 16:03:50 -05:00
numberAdjusterValue = parseFloat ( numberAdjusterValue ) ;
//console.log("Value: " + numberAdjusterValue);
2022-09-30 12:29:16 -04:00
2022-11-11 16:03:50 -05:00
//mode check
2022-12-24 15:24:29 -05:00
if ( numberAdjusterMode === null ) {
alert ( "No operation was specified! Defaulting to add." ) ;
numberAdjusterMode = "add" ;
2022-09-30 12:29:16 -04:00
} ;
2022-12-24 15:24:29 -05:00
2022-11-11 16:03:50 -05:00
numberAdjusterMode = numberAdjusterMode . toLowerCase ( ) ;
2022-09-30 12:29:16 -04:00
2022-12-24 15:24:29 -05:00
var opNames = [ "+" , "add" , "addition" , "plus" , "increase" , "increment" , "-" , "subtract" , "subtraction" , "minus" , "take away" , "takeaway" , "decrease" , "decrement" , "*" , "x" , "× " , "multiply" , "multiplication" , "times" , "by" , "/" , "÷" , "divide" , "division" , "divided by" , "%" , "mod" , "modulo" , "modulus" , "modulo by" , "=" , "set" , "equals" , "assign" , "assignment" , ">" , ">=" , "min" , "minimum" , "<" , "<=" , "max" , "maximum" , "^" , "**" , "exp" , "exponent" , "exponentiate" , "raise" , "raise to" , "raised to" ] ;
switch ( numberAdjusterMode ) {
case "+" :
case "add" :
case "addition" :
case "plus" :
case "increase" :
case "increment" :
numberAdjusterVerb = "adding" ;
numberAdjusterPreposition = "to" ;
numberAdjusterReverseOrder = false ;
break ;
case "-" :
case "subtract" :
case "subtraction" :
case "minus" :
case "take away" :
case "takeaway" :
case "decrease" :
case "decrement" :
numberAdjusterVerb = "subtracting" ;
numberAdjusterPreposition = "from" ;
numberAdjusterReverseOrder = false ;
break ;
case "*" :
case "x" :
case "× " :
case "multiply" :
case "multiplication" :
case "times" :
case "by" :
numberAdjusterVerb = "multiplying" ;
numberAdjusterPreposition = "by" ;
numberAdjusterReverseOrder = true ;
break ;
case "/" :
case "÷" :
case "divide" :
case "division" :
case "divided by" :
numberAdjusterVerb = "dividing" ;
numberAdjusterPreposition = "by" ;
numberAdjusterReverseOrder = true ;
break ;
case "%" :
case "mod" :
case "modulo" :
case "modulus" :
case "modulo by" :
numberAdjusterVerb = "reducing" ;
numberAdjusterPreposition = "modulo" ;
numberAdjusterReverseOrder = true ;
break ;
case "=" :
case "set" :
case "equals" :
case "assign" :
case "assignment" :
numberAdjusterVerb = "setting" ;
numberAdjusterPreposition = "to" ;
numberAdjusterReverseOrder = true ;
break ;
case ">" : //lower-bounds the color
case ">=" :
case "min" :
case "minimum" :
numberAdjusterVerb = "lower-bounding" ;
numberAdjusterPreposition = "to" ;
numberAdjusterReverseOrder = true ;
break ;
case "<" :
case "<=" :
case "max" : //upper-bounds the color
case "maximum" :
numberAdjusterVerb = "limiting" ;
numberAdjusterPreposition = "to" ;
numberAdjusterReverseOrder = true ;
break ;
case "^" :
case "**" :
case "exp" :
case "exponent" :
case "exponentiate" :
case "raise" :
case "raise to" :
case "raised to" :
numberAdjusterVerb = "raising" ;
numberAdjusterPreposition = "to" ;
numberAdjusterReverseOrder = true ;
break ;
default :
alert ( ` Invalid operation (defaulting to "add")! ` ) ;
numberAdjusterMode = "add" ;
numberAdjusterVerb = "adding" ;
numberAdjusterPreposition = "to" ;
numberAdjusterReverseOrder = false ;
break ;
} ;
2022-11-11 16:03:50 -05:00
updateNumberAdjusterDescription ( ) ;
currentElement = "number_adjuster" ;
} ;
2022-09-30 12:29:16 -04:00
2022-11-11 16:03:50 -05:00
elements . number _adjuster = {
color : "#7fff00" ,
tool : function ( pixel ) {
2022-12-24 15:24:29 -05:00
if ( typeof ( pixel [ numberAdjusterProperty ] ) === "undefined" ) {
pixel [ numberAdjusterProperty ] = 0 ;
} ;
if ( typeof ( pixel [ numberAdjusterProperty ] ) === "number" ) {
switch ( numberAdjusterMode . toLowerCase ( ) ) {
case "+" :
case "add" :
case "addition" :
case "plus" :
case "increase" :
case "increment" :
pixel [ numberAdjusterProperty ] += numberAdjusterValue ;
break ;
case "-" :
case "subtract" :
case "subtraction" :
case "minus" :
case "take away" :
case "takeaway" :
case "decrease" :
case "decrement" :
pixel [ numberAdjusterProperty ] -= numberAdjusterValue ;
break ;
case "*" :
case "x" :
case "× " :
case "multiply" :
case "multiplication" :
case "times" :
case "by" :
pixel [ numberAdjusterProperty ] *= numberAdjusterValue ;
break ;
case "/" :
case "÷" :
case "divide" :
case "division" :
case "divided by" :
pixel [ numberAdjusterProperty ] /= numberAdjusterValue ;
break ;
case "%" :
case "mod" :
case "modulo" :
case "modulus" :
case "modulo by" :
pixel [ numberAdjusterProperty ] %= numberAdjusterValue ;
break ;
case "=" :
case "set" :
case "equals" :
case "assign" :
case "assignment" :
pixel [ numberAdjusterProperty ] = numberAdjusterValue ;
break ;
case ">" : //lower-bounds the color
case ">=" :
case "min" :
case "minimum" :
pixel [ numberAdjusterProperty ] = Math . max ( numberAdjusterValue , pixel [ numberAdjusterProperty ] ) ;
break ;
case "<" :
case "<=" :
case "max" : //upper-bounds the color
case "maximum" :
pixel [ numberAdjusterProperty ] = Math . min ( numberAdjusterValue , pixel [ numberAdjusterProperty ] ) ;
break ;
case "^" :
case "**" :
case "exp" :
case "exponent" :
case "exponentiate" :
case "raise" :
case "raise to" :
case "raised to" :
pixel [ numberAdjusterProperty ] = pixel [ numberAdjusterProperty ] * * numberAdjusterValue ;
break ;
default :
pixel [ numberAdjusterProperty ] += numberAdjusterValue ;
2022-09-30 12:29:16 -04:00
} ;
2022-11-11 16:03:50 -05:00
pixelTempCheck ( pixel ) ;
2022-09-30 12:29:16 -04:00
} ;
2022-11-11 16:03:50 -05:00
} ,
category : "tools" ,
2022-12-24 15:24:29 -05:00
desc : ` Changes properties of pixels.<br/>Currently ${ numberAdjusterVerb } ${ numberAdjusterValue } ${ numberAdjusterPreposition } ${ numberAdjusterProperty } .<br/><span onclick=numberAdjusterPrompt() style= \" color: #ff00ff; \" ;>Press [Shift+,] or click here</span> to open the adjuster tool prompt. ` ,
2022-11-11 16:03:50 -05:00
} ;
2022-09-30 12:29:16 -04:00
2022-11-11 16:03:50 -05:00
function updateNumberAdjusterDescription ( ) {
2022-12-24 15:24:29 -05:00
elements . number _adjuster . desc = numberAdjusterReverseOrder ? ` Changes numeric properties of pixels.<br/>Currently ${ numberAdjusterVerb } ${ numberAdjusterProperty } ${ numberAdjusterPreposition } ${ numberAdjusterValue } .<br/><span onclick=numberAdjusterPrompt() style= \" color: #ff00ff; \" ;>Press [Shift+,] or click here</span> to open the adjuster tool prompt. ` : ` Changes numeric properties of pixels.<br/>Currently ${ numberAdjusterVerb } ${ numberAdjusterValue } ${ numberAdjusterPreposition } ${ numberAdjusterProperty } .<br/><span onclick=numberAdjusterPrompt() style= \" color: #ff00ff; \" ;>Press [Shift+,] or click here</span> to open the adjuster tool prompt. ` ;
2022-11-11 16:03:50 -05:00
} ;
} else {
alert ( ` The ${ variablesMod } mod is required and has been automatically inserted (reload for this to take effect). ` )
enabledMods . splice ( enabledMods . indexOf ( modName ) , 0 , variablesMod )
localStorage . setItem ( "enabledMods" , JSON . stringify ( enabledMods ) ) ;
2022-09-14 14:37:03 -04:00
} ;