make same changes to prompt
This commit is contained in:
parent
cae5928023
commit
e2555a9554
|
|
@ -1,18 +1,8 @@
|
||||||
colorInvalidError = "Color must be in the form \"rgb(red,green,blue)\" or \"hsl(hue,saturation%,lightness%)\" (without quotes)!";
|
var modName = "mods/prompt.js";
|
||||||
stringSynonyms = [ "string", "str", "st", "s" ];
|
var variablesMod = "mods/prop and prompt variables.js";
|
||||||
numberSynonyms = [ "number", "num", "nm", "nu", "nb", "integer", "int", "i", "it", "float",
|
|
||||||
"flt", "ft", "fl", "f", "wholenumber", "decimalnumber", "wn", "dn", "w",
|
if(enabledMods.includes(variablesMod)) {
|
||||||
"d", "deeznuts" ]; /*The purpose of these blatant lies is, through a
|
commandHelpObject = {
|
||||||
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"];
|
|
||||||
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.",
|
"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.",
|
"test": "Test.",
|
||||||
"fill": "Fills the screen with the given pixel(s). Usage: fill [Overwrite pixels? (should be a bool)] [element] <additional elements>.\nDon't include framing characters []<>.\nArguments in [brackets] are required and ones in <angle brackets> are optional.\nAdditional elements are separated by spaces.",
|
"fill": "Fills the screen with the given pixel(s). Usage: fill [Overwrite pixels? (should be a bool)] [element] <additional elements>.\nDon't include framing characters []<>.\nArguments in [brackets] are required and ones in <angle brackets> are optional.\nAdditional elements are separated by spaces.",
|
||||||
|
|
@ -20,43 +10,43 @@ commandHelpObject = {
|
||||||
"count": "Tells you the amount of a specified pixel on the screen. Usage: count [element]\nDon't include framing characters []<>.\nArguments in [brackets] are required.",
|
"count": "Tells you the amount of a specified pixel on the screen. Usage: count [element]\nDon't include framing characters []<>.\nArguments in [brackets] are required.",
|
||||||
"countall": "Logs to console a list of all elements on screen and their amounts. Usage: countall.",
|
"countall": "Logs to console a list of all elements on screen and their amounts. Usage: countall.",
|
||||||
"help": "Usage: help <command>\nDon't include framing characters []<>.\nArguments in <angle brackets> are optional."
|
"help": "Usage: help <command>\nDon't include framing characters []<>.\nArguments in <angle brackets> are optional."
|
||||||
}
|
}
|
||||||
|
|
||||||
function rgbStringToUnvalidatedObject(string) {
|
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};
|
||||||
}
|
}
|
||||||
|
|
||||||
function alertIfError(alertError,text) {
|
function alertIfError(alertError,text) {
|
||||||
if(alertError) {
|
if(alertError) {
|
||||||
alert(text);
|
alert(text);
|
||||||
return(true);
|
return(true);
|
||||||
} else {
|
} else {
|
||||||
return(false);
|
return(false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function alertIfOutput(alertOutput,text) {
|
function alertIfOutput(alertOutput,text) {
|
||||||
if(alertOutput) {
|
if(alertOutput) {
|
||||||
alert(text);
|
alert(text);
|
||||||
return(true);
|
return(true);
|
||||||
} else {
|
} else {
|
||||||
return(false);
|
return(false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function funniPrompt(argument=null,alertOutput=true,alertError=true) {
|
function funniPrompt(argument=null,alertOutput=true,alertError=true) {
|
||||||
argument === null ? inputText = prompt("Enter command") : inputText = argument;
|
argument === null ? inputText = prompt("Enter command") : inputText = argument;
|
||||||
// replace spaces with underscores
|
// replace spaces with underscores
|
||||||
inputAsArray = inputText.split(" ");
|
inputAsArray = inputText.split(" ");
|
||||||
|
|
@ -88,11 +78,14 @@ function funniPrompt(argument=null,alertOutput=true,alertError=true) {
|
||||||
type = "boolean";
|
type = "boolean";
|
||||||
} else if(stringSynonyms.includes(type.toLowerCase())) {
|
} else if(stringSynonyms.includes(type.toLowerCase())) {
|
||||||
type = "string";
|
type = "string";
|
||||||
} /*else if(arraySynonyms.includes(type.toLowerCase())) { //I have no plans to implement these.
|
} else if(arraySynonyms.includes(type.toLowerCase())) {
|
||||||
type = "array";
|
type = "array";
|
||||||
} else if(objectSynonyms.includes(type.toLowerCase())) {
|
} else if(objectSynonyms.includes(type.toLowerCase())) {
|
||||||
type = "object";
|
type = "object";
|
||||||
}*/ else {
|
};
|
||||||
|
|
||||||
|
var typeWhitelist = [null,"string","number","boolean","array","object"];
|
||||||
|
if(!typeWhitelist.includes(type)) {
|
||||||
alertIfError(alertError,"Unrecognized type: \"" + type + "\".");
|
alertIfError(alertError,"Unrecognized type: \"" + type + "\".");
|
||||||
return false;
|
return false;
|
||||||
};
|
};
|
||||||
|
|
@ -102,6 +95,10 @@ function funniPrompt(argument=null,alertOutput=true,alertError=true) {
|
||||||
type = "string";
|
type = "string";
|
||||||
} else if(defaultNumberTypeValues.includes(property)) {
|
} else if(defaultNumberTypeValues.includes(property)) {
|
||||||
type = "number";
|
type = "number";
|
||||||
|
} else if(defaultBooleanTypeValues.includes(property)) {
|
||||||
|
type = "boolean";
|
||||||
|
} else if(defaultArrayTypeValues.includes(property)) {
|
||||||
|
type = "array";
|
||||||
} else {
|
} else {
|
||||||
alertIfError(alertError,"Type could not be assumed from property. Please specify the type as a fourth argument.");
|
alertIfError(alertError,"Type could not be assumed from property. Please specify the type as a fourth argument.");
|
||||||
return false;
|
return false;
|
||||||
|
|
@ -123,6 +120,49 @@ function funniPrompt(argument=null,alertOutput=true,alertError=true) {
|
||||||
alertIfError(alertError,"Unrecognized boolean value: " + value + ".");
|
alertIfError(alertError,"Unrecognized boolean value: " + value + ".");
|
||||||
return false;
|
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.
|
//The values start out as strings when split from the array, so string is kind of the default form.
|
||||||
|
|
||||||
|
|
@ -371,4 +411,9 @@ function funniPrompt(argument=null,alertOutput=true,alertError=true) {
|
||||||
alertIfError(alertError,`Command ${firstItem} not found!`);
|
alertIfError(alertError,`Command ${firstItem} not found!`);
|
||||||
return false;
|
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