Move variables to dependency
i'm sick of having to update them twice also shallow array support lmao
This commit is contained in:
parent
748e0171e8
commit
69f3beda4f
128
mods/prop.js
128
mods/prop.js
|
|
@ -1,52 +1,40 @@
|
||||||
propProperty = "element";
|
var modName = "mods/prop.js";
|
||||||
propValue = "sand";
|
var variablesMod = "mods/prop and prompt variables.js";
|
||||||
propType = "string";
|
|
||||||
numberAdjusterProperty = "temp";
|
|
||||||
numberAdjusterValue = 1;
|
|
||||||
numberAdjusterMode = "add";
|
|
||||||
numberAdjusterVerb = "adding";
|
|
||||||
|
|
||||||
stringSynonyms = [ "string", "str", "st", "s" ];
|
if(enabledMods.includes(variablesMod)) {
|
||||||
numberSynonyms = [ "number", "num", "nm", "nu", "nb", "integer", "int", "i", "it", "float",
|
propProperty = "element";
|
||||||
"flt", "ft", "fl", "f", "wholenumber", "decimalnumber", "wn", "dn", "w",
|
propValue = "sand";
|
||||||
"d", "deeznuts" ]; /*The purpose of these blatant lies is, through a
|
propType = "string";
|
||||||
reference to the Alice series of software, have an excuse to include deez
|
numberAdjusterProperty = "temp";
|
||||||
nuts.*/
|
numberAdjusterValue = 1;
|
||||||
objectSynonyms = [ "object", "oj", "obj", "ob", "o", "json" ];
|
numberAdjusterMode = "add";
|
||||||
booleanSynonyms = [ "boolean", "bool", "boole", "boo", "bo", "bl", "b" ];
|
numberAdjusterVerb = "adding";
|
||||||
|
|
||||||
defaultStringTypeValues = ["element","color","clone","changeTo","void","type"];
|
function rgbStringToUnvalidatedObject(string) {
|
||||||
defaultNumberTypeValues = ["x","y","temp","start","vx","vy","chargeCD","start","burnStart","dir","panic","r","frequency","length","delay","volume","debounce","debounceLength"];
|
|
||||||
defaultBooleanTypeValues = ["burning","charge","dead","hissing","following","dirLocked","del","didChargeBlueTinted"];
|
|
||||||
|
|
||||||
synonymsOfTrue = ["true", "t", "1", "yes"];
|
|
||||||
synonymsOfFalse = ["false", "f", "0", "no"];
|
|
||||||
colorInvalidError = "Color must be in the form \"rgb(red,green,blue)\" or \"hsl(hue,saturation%,lightness%)\" (without quotes)!";
|
|
||||||
function rgbStringToUnvalidatedObject(string) {
|
|
||||||
string = string.split(",");
|
string = string.split(",");
|
||||||
var red = parseFloat(string[0].substring(4));
|
var red = parseFloat(string[0].substring(4));
|
||||||
var green = parseFloat(string[1]);
|
var green = parseFloat(string[1]);
|
||||||
var blue = parseFloat(string[2].slice(0,-1));
|
var blue = parseFloat(string[2].slice(0,-1));
|
||||||
return {r: red, g: green, b: blue};
|
return {r: red, g: green, b: blue};
|
||||||
};
|
};
|
||||||
function hslStringToUnvalidatedObject(string) {
|
function hslStringToUnvalidatedObject(string) {
|
||||||
string = string.split(",");
|
string = string.split(",");
|
||||||
var hue = parseFloat(string[0].substring(4));
|
var hue = parseFloat(string[0].substring(4));
|
||||||
var saturation = parseFloat(string[1].slice(0,-1));
|
var saturation = parseFloat(string[1].slice(0,-1));
|
||||||
var lightness = parseFloat(string[2].slice(0,-2));
|
var lightness = parseFloat(string[2].slice(0,-2));
|
||||||
return {h: hue, s: saturation, l: lightness};
|
return {h: hue, s: saturation, l: lightness};
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
document.addEventListener("keydown", function(e) { //prop prompt listener
|
document.addEventListener("keydown", function(e) { //prop prompt listener
|
||||||
// , = propPrompt()
|
// , = propPrompt()
|
||||||
if (e.keyCode == 188) {
|
if (e.keyCode == 188) {
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
shiftDown ? numberAdjusterPrompt() : propPrompt();
|
shiftDown ? numberAdjusterPrompt() : propPrompt();
|
||||||
};
|
};
|
||||||
});
|
});
|
||||||
|
|
||||||
function propPrompt() {
|
function propPrompt() {
|
||||||
propProperty = prompt("Enter the property you want to set");
|
propProperty = prompt("Enter the property you want to set");
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -128,20 +116,21 @@ function propPrompt() {
|
||||||
propType = "boolean";
|
propType = "boolean";
|
||||||
} else if(defaultStringTypeValues.includes(propProperty.toLowerCase())) {
|
} else if(defaultStringTypeValues.includes(propProperty.toLowerCase())) {
|
||||||
propType = "string";
|
propType = "string";
|
||||||
|
} else if(defaultArrayTypeValues.includes(propProperty.toLowerCase())) {
|
||||||
|
propType = "array";
|
||||||
} else {
|
} else {
|
||||||
propType = prompt("Enter the type of the value");
|
propType = prompt("Enter the type of the value");
|
||||||
if(stringSynonyms.includes(propType)) {
|
if(stringSynonyms.includes(propType)) {
|
||||||
propType = "string"
|
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
|
||||||
};
|
};
|
||||||
if(numberSynonyms.includes(propType)) {
|
|
||||||
propType = "number" //Infinity (case-sensitively) is a *number*.
|
|
||||||
};
|
|
||||||
if(booleanSynonyms.includes(propType)) {
|
|
||||||
propType = "boolean"
|
|
||||||
};
|
|
||||||
if(objectSynonyms.includes(propType)) {
|
|
||||||
propType = "object" //null (case-sensitively) is an *object*.
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
//Conversion
|
//Conversion
|
||||||
|
|
@ -167,15 +156,51 @@ function propPrompt() {
|
||||||
alert("JSON is invalid! Note that it requires quotes around keys as well as those curly {} parentheses.");
|
alert("JSON is invalid! Note that it requires quotes around keys as well as those curly {} parentheses.");
|
||||||
return false;
|
return false;
|
||||||
};
|
};
|
||||||
|
} else if(propType === "array") {
|
||||||
|
array = propType.split(",");
|
||||||
|
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;
|
||||||
|
};
|
||||||
|
};
|
||||||
|
propType = array;
|
||||||
} else if(propType !== "string") {
|
} else if(propType !== "string") {
|
||||||
alert("Unrecognized or unsupported type!");
|
alert("Unrecognized or unsupported type!");
|
||||||
return false;
|
return false;
|
||||||
};
|
};
|
||||||
updatePropDescription();
|
updatePropDescription();
|
||||||
currentElement = "prop";
|
currentElement = "prop";
|
||||||
};
|
};
|
||||||
|
|
||||||
elements.prop = {
|
elements.prop = {
|
||||||
color: "#ff7f00",
|
color: "#ff7f00",
|
||||||
tool: function(pixel) {
|
tool: function(pixel) {
|
||||||
if(propProperty === "element") {
|
if(propProperty === "element") {
|
||||||
|
|
@ -188,13 +213,13 @@ elements.prop = {
|
||||||
},
|
},
|
||||||
category: "tools",
|
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.`,
|
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.`,
|
||||||
};
|
};
|
||||||
|
|
||||||
function updatePropDescription() {
|
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.`;
|
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.`;
|
||||||
};
|
};
|
||||||
|
|
||||||
function numberAdjusterPrompt() {
|
function numberAdjusterPrompt() {
|
||||||
numberAdjusterProperty = prompt("Enter the property you want to change");
|
numberAdjusterProperty = prompt("Enter the property you want to change");
|
||||||
numberAdjusterValue = prompt("Enter the value you want to use");
|
numberAdjusterValue = prompt("Enter the value you want to use");
|
||||||
numberAdjusterMode = prompt("Enter \"set\" to set the property to the value,\nor \"add\" to add the value to the property.");
|
numberAdjusterMode = prompt("Enter \"set\" to set the property to the value,\nor \"add\" to add the value to the property.");
|
||||||
|
|
@ -257,9 +282,9 @@ function numberAdjusterPrompt() {
|
||||||
}
|
}
|
||||||
updateNumberAdjusterDescription();
|
updateNumberAdjusterDescription();
|
||||||
currentElement = "number_adjuster";
|
currentElement = "number_adjuster";
|
||||||
};
|
};
|
||||||
|
|
||||||
elements.number_adjuster = {
|
elements.number_adjuster = {
|
||||||
color: "#7fff00",
|
color: "#7fff00",
|
||||||
tool: function(pixel) {
|
tool: function(pixel) {
|
||||||
if(numberAdjusterProperty !== "element") {
|
if(numberAdjusterProperty !== "element") {
|
||||||
|
|
@ -277,8 +302,13 @@ elements.number_adjuster = {
|
||||||
},
|
},
|
||||||
category: "tools",
|
category: "tools",
|
||||||
desc: `Sets or adds to numeric properties of pixels.<br/>Currently ${numberAdjusterVerb} ${numberAdjusterValue} to ${numberAdjusterProperty}.<br/><span onclick=numberAdjusterPrompt() style=\"color: #ff00ff;\";>Press [Shift+,] or click here</span> to open the adjuster tool prompt.`,
|
desc: `Sets or adds to numeric properties of pixels.<br/>Currently ${numberAdjusterVerb} ${numberAdjusterValue} to ${numberAdjusterProperty}.<br/><span onclick=numberAdjusterPrompt() style=\"color: #ff00ff;\";>Press [Shift+,] or click here</span> to open the adjuster tool prompt.`,
|
||||||
};
|
};
|
||||||
|
|
||||||
function updateNumberAdjusterDescription() {
|
function updateNumberAdjusterDescription() {
|
||||||
elements.number_adjuster.desc = `Sets or adds to numeric properties of pixels.<br/>Currently ${numberAdjusterVerb} ${numberAdjusterValue} to ${numberAdjusterProperty}.<br/><span onclick=numberAdjusterPrompt() style=\"color: #ff00ff;\";>Press [Shift+,] or click here</span> to open the adjuster tool prompt.`;
|
elements.number_adjuster.desc = `Sets or adds to numeric properties of pixels.<br/>Currently ${numberAdjusterVerb} ${numberAdjusterValue} to ${numberAdjusterProperty}.<br/><span onclick=numberAdjusterPrompt() style=\"color: #ff00ff;\";>Press [Shift+,] or click here</span> to open the adjuster tool prompt.`;
|
||||||
|
};
|
||||||
|
} 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));
|
||||||
};
|
};
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue