make same changes to prompt
This commit is contained in:
parent
cae5928023
commit
e2555a9554
|
|
@ -1,17 +1,7 @@
|
|||
colorInvalidError = "Color must be in the form \"rgb(red,green,blue)\" or \"hsl(hue,saturation%,lightness%)\" (without quotes)!";
|
||||
stringSynonyms = [ "string", "str", "st", "s" ];
|
||||
numberSynonyms = [ "number", "num", "nm", "nu", "nb", "integer", "int", "i", "it", "float",
|
||||
"flt", "ft", "fl", "f", "wholenumber", "decimalnumber", "wn", "dn", "w",
|
||||
"d", "deeznuts" ]; /*The purpose of these blatant lies is, through a
|
||||
reference to the Alice series of software, have an excuse to include deez
|
||||
nuts.*/
|
||||
//Passing "Infinity" through parseFloat returns Infinity.
|
||||
booleanSynonyms = [ "boolean", "bool", "boole", "boo", "bo", "bl", "b" ];
|
||||
synonymsOfTrue = ["true", "t", "1", "yes"];
|
||||
synonymsOfFalse = ["false", "f", "0", "no"];
|
||||
defaultStringTypeValues = ["element","color","clone","changeTo","void","type","spawn"];
|
||||
defaultNumberTypeValues = ["x","y","temp","start","vx","vy","chargeCD","start","burnStart","dir","panic","r","frequency","length","delay","volume","debounce","debounceLength","speed","fall","penetrateCounter","chargeCounter","spawnCounter","spawnTime","squadiusX","squadiusY","spawnTries","counter"];
|
||||
defaultBooleanTypeValues = ["burning","charge","dead","hissing","following","dirLocked","del","didChargeBlueTinted","shooting","del"];
|
||||
var modName = "mods/prompt.js";
|
||||
var variablesMod = "mods/prop and prompt variables.js";
|
||||
|
||||
if(enabledMods.includes(variablesMod)) {
|
||||
commandHelpObject = {
|
||||
"set": "Sets properties for every pixel of a given type.\nUsage: set [property] [element] [value] <type>\nDon't include framing characters []<>.\nThe element can be \"all\" to set the property for every pixel.\nNote: Strings can't have spaces because spaces are the separator used in the parsing split().\nArguments in [brackets] are required and ones in <angle brackets> are optional.",
|
||||
"test": "Test.",
|
||||
|
|
@ -88,11 +78,14 @@ function funniPrompt(argument=null,alertOutput=true,alertError=true) {
|
|||
type = "boolean";
|
||||
} else if(stringSynonyms.includes(type.toLowerCase())) {
|
||||
type = "string";
|
||||
} /*else if(arraySynonyms.includes(type.toLowerCase())) { //I have no plans to implement these.
|
||||
} else if(arraySynonyms.includes(type.toLowerCase())) {
|
||||
type = "array";
|
||||
} else if(objectSynonyms.includes(type.toLowerCase())) {
|
||||
type = "object";
|
||||
}*/ else {
|
||||
};
|
||||
|
||||
var typeWhitelist = [null,"string","number","boolean","array","object"];
|
||||
if(!typeWhitelist.includes(type)) {
|
||||
alertIfError(alertError,"Unrecognized type: \"" + type + "\".");
|
||||
return false;
|
||||
};
|
||||
|
|
@ -102,6 +95,10 @@ function funniPrompt(argument=null,alertOutput=true,alertError=true) {
|
|||
type = "string";
|
||||
} else if(defaultNumberTypeValues.includes(property)) {
|
||||
type = "number";
|
||||
} else if(defaultBooleanTypeValues.includes(property)) {
|
||||
type = "boolean";
|
||||
} else if(defaultArrayTypeValues.includes(property)) {
|
||||
type = "array";
|
||||
} else {
|
||||
alertIfError(alertError,"Type could not be assumed from property. Please specify the type as a fourth argument.");
|
||||
return false;
|
||||
|
|
@ -123,6 +120,49 @@ function funniPrompt(argument=null,alertOutput=true,alertError=true) {
|
|||
alertIfError(alertError,"Unrecognized boolean value: " + value + ".");
|
||||
return false;
|
||||
}
|
||||
} else if(type === "object") {
|
||||
try {
|
||||
value = JSON.parse(value);
|
||||
} catch (error) {
|
||||
alertIfError(alertError,"JSON is invalid! Note that it requires quotes around keys as well as those curly {} parentheses.");
|
||||
return false;
|
||||
};
|
||||
} else if(type === "array") {
|
||||
array = value.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;
|
||||
};
|
||||
};
|
||||
value = array;
|
||||
}
|
||||
//The values start out as strings when split from the array, so string is kind of the default form.
|
||||
|
||||
|
|
@ -372,3 +412,8 @@ function funniPrompt(argument=null,alertOutput=true,alertError=true) {
|
|||
return false;
|
||||
};
|
||||
};
|
||||
} 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