mirror of
https://github.com/kkapsner/CanvasBlocker
synced 2025-07-03 20:16:33 +02:00
parent
fb231a070b
commit
1bd87e6953
4 changed files with 42 additions and 28 deletions
|
@ -145,6 +145,9 @@
|
|||
case "{random renderer}":
|
||||
return webglRandom.getRandomRenderer(window);
|
||||
}
|
||||
if (settingValue.startsWith("<") && settingValue.endsWith(">")){
|
||||
return webglRandom.pickOneFromTree(settingValue, window);
|
||||
}
|
||||
return settingValue;
|
||||
},
|
||||
decimal: function(originalValue, definition, window){
|
||||
|
|
|
@ -51,6 +51,35 @@
|
|||
const vendor = scope.vendors[getRandomVendorIndex(window)];
|
||||
return vendor.renderers[getRandomRendererIndex(window)];
|
||||
};
|
||||
scope.pickOneFromTree = function pickOneFromTree(treeString, window){
|
||||
function pickOne(string){
|
||||
const options = [];
|
||||
let cumulate = "";
|
||||
let index = 0;
|
||||
for (const l = string.length; index < l; index += 1){
|
||||
const char = string.charAt(index);
|
||||
if (char === "|"){
|
||||
options.push(cumulate);
|
||||
cumulate = "";
|
||||
}
|
||||
else if (char === "<"){
|
||||
const subPick = pickOne(string.substring(index + 1));
|
||||
cumulate += subPick.value;
|
||||
index += 1 + subPick.endIndex;
|
||||
}
|
||||
else if (char === ">"){
|
||||
break;
|
||||
}
|
||||
else {
|
||||
cumulate += char;
|
||||
}
|
||||
}
|
||||
options.push(cumulate);
|
||||
const optionRng = randomSupply.getIndexRng(1, options.length, window);
|
||||
return {value: options[optionRng(0)], endIndex: index};
|
||||
}
|
||||
return pickOne(treeString).value;
|
||||
};
|
||||
|
||||
scope.vendors = [
|
||||
{
|
||||
|
@ -93,34 +122,7 @@
|
|||
return words[parseInt(index, 36)];
|
||||
}
|
||||
);
|
||||
|
||||
function pickOne(string){
|
||||
const options = [];
|
||||
let cumulate = "";
|
||||
let index = 0;
|
||||
for (const l = string.length; index < l; index += 1){
|
||||
const char = string.charAt(index);
|
||||
if (char === "|"){
|
||||
options.push(cumulate);
|
||||
cumulate = "";
|
||||
}
|
||||
else if (char === "<"){
|
||||
const subPick = pickOne(string.substring(index + 1));
|
||||
cumulate += subPick.value;
|
||||
index += 1 + subPick.endIndex;
|
||||
}
|
||||
else if (char === ">"){
|
||||
break;
|
||||
}
|
||||
else {
|
||||
cumulate += char;
|
||||
}
|
||||
}
|
||||
options.push(cumulate);
|
||||
const optionRng = randomSupply.getIndexRng(1, options.length, window);
|
||||
return {value: options[optionRng(0)], endIndex: index};
|
||||
}
|
||||
return pickOne(compressed).value;
|
||||
return scope.pickOneFromTree(compressed, window);
|
||||
|
||||
}
|
||||
},
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue