Files
lifeRestart/public/condition_test.html
Vick Scarlet 150c991648 Squashed commit of the following:
commit b421082374
Author: Vick Scarlet <scarlet_vick@outlook.com>
Date:   Fri Dec 31 20:26:20 2021 +0800

    update specialthanks

commit 765a69294b
Author: Vick Scarlet <scarlet_vick@outlook.com>
Date:   Tue Dec 14 19:10:03 2021 +0800

    fix ios goto

commit 8eb8c3ca72
Author: Vick Scarlet <scarlet_vick@outlook.com>
Date:   Tue Dec 14 19:03:37 2021 +0800

    add event grade

commit ab705dd46c
Author: Vick Scarlet <scarlet_vick@outlook.com>
Date:   Tue Dec 14 18:48:42 2021 +0800

    build version

commit a1e4232369
Author: Vick Scarlet <scarlet_vick@outlook.com>
Date:   Tue Dec 14 18:47:05 2021 +0800

    change talent replace before property allocate

commit f4d7b3ae3c
Author: Vick Scarlet <scarlet_vick@outlook.com>
Date:   Tue Dec 14 18:06:18 2021 +0800

    add event grade

commit 0567e40ddc
Author: Vick Scarlet <scarlet_vick@outlook.com>
Date:   Thu Dec 2 21:28:10 2021 +0800

    add particle

commit f17003925e
Author: Vick Scarlet <scarlet_vick@outlook.com>
Date:   Thu Dec 2 20:14:26 2021 +0800

    change ui

commit f8beda1d8f
Author: Vick Scarlet <scarlet_vick@outlook.com>
Date:   Thu Dec 2 19:08:30 2021 +0800

    change popup message ui

commit 915a2aa17d
Author: Vick Scarlet <scarlet_vick@outlook.com>
Date:   Thu Dec 2 18:34:29 2021 +0800

    new build

commit b5edabc104
Author: Vick Scarlet <scarlet_vick@outlook.com>
Date:   Thu Dec 2 18:18:46 2021 +0800

    add hint message

commit a143feadaf
Author: Vick Scarlet <scarlet_vick@outlook.com>
Date:   Thu Dec 2 17:57:31 2021 +0800

    fix copy bug

commit eab1975791
Author: Vick Scarlet <scarlet_vick@outlook.com>
Date:   Thu Dec 2 17:56:28 2021 +0800

    add save/load

commit acf9b92134
Author: Vick Scarlet <scarlet_vick@outlook.com>
Date:   Thu Dec 2 14:35:33 2021 +0800

    add theme switch

commit 488a6054ab
Author: Vick Scarlet <scarlet_vick@outlook.com>
Date:   Wed Dec 1 18:30:36 2021 +0800

    fix uiManager bug

commit f0317eaf14
Author: Vick Scarlet <scarlet_vick@outlook.com>
Date:   Wed Dec 1 16:07:03 2021 +0800

    add message popup

commit eb02d1ee6f
Author: Vick Scarlet <scarlet_vick@outlook.com>
Date:   Sun Nov 28 21:22:54 2021 +0800

    change relocation

commit 60503eae47
Author: Vick Scarlet <scarlet_vick@outlook.com>
Date:   Sun Nov 28 19:27:16 2021 +0800

    change ScaleButton -> Laya.runtime.ScaleButton

commit 52ef5909c1
Author: Vick Scarlet <scarlet_vick@outlook.com>
Date:   Sun Nov 28 19:26:31 2021 +0800

    change ScaleButton -> Laya.runtime.ScaleButton

commit 0284f6aa71
Author: Vick Scarlet <scarlet_vick@outlook.com>
Date:   Sun Nov 28 19:05:24 2021 +0800

    config webpack

commit 0e272ffd99
Author: Vick Scarlet <scarlet_vick@outlook.com>
Date:   Sun Nov 28 13:17:41 2021 +0800

    add thanks

commit e1e2ab4701
Author: Vick Scarlet <scarlet_vick@outlook.com>
Date:   Sun Nov 28 11:40:21 2021 +0800

    add light theme

commit 4f55c00f86
Author: Vick Scarlet <scarlet_vick@outlook.com>
Date:   Sat Nov 27 22:27:39 2021 +0800

    fix bug

commit 1d07bdfc46
Author: Vick Scarlet <scarlet_vick@outlook.com>
Date:   Sat Nov 27 21:48:47 2021 +0800

    daily update

commit 52d6a0ca8f
Author: Vick Scarlet <scarlet_vick@outlook.com>
Date:   Wed Nov 24 23:10:04 2021 +0800

    daily update

commit f8dd720d4d
Author: Vick Scarlet <scarlet_vick@outlook.com>
Date:   Wed Nov 24 19:08:13 2021 +0800

    daily update

commit d088c1a862
Author: Vick Scarlet <scarlet_vick@outlook.com>
Date:   Sun Nov 21 21:41:46 2021 +0800

    remove useless

commit a711fcf3ed
Author: Vick Scarlet <scarlet_vick@outlook.com>
Date:   Tue Nov 16 00:53:05 2021 +0800

    add achievement popup
    add page adaptive
    add talent extends

commit 05e02de3db
Author: Vick Scarlet <scarlet_vick@outlook.com>
Date:   Sat Nov 13 01:24:04 2021 +0800

    add github and discord

commit bff0109cc5
Author: Vick Scarlet <scarlet_vick@outlook.com>
Date:   Sat Nov 13 00:30:01 2021 +0800

    add trajectory auto mode

commit 54c04f65c2
Author: Vick Scarlet <scarlet_vick@outlook.com>
Date:   Fri Nov 12 19:54:31 2021 +0800

    fix property judge negative number bug

commit 660739530b
Author: Vick Scarlet <scarlet_vick@outlook.com>
Date:   Fri Nov 12 19:48:58 2021 +0800

    update achievement

commit c94e9e7433
Author: Vick Scarlet <scarlet_vick@outlook.com>
Date:   Thu Nov 11 21:37:45 2021 +0800

    update daily

commit c06cd9ea62
Author: Vick Scarlet <scarlet_vick@outlook.com>
Date:   Tue Nov 9 00:08:05 2021 +0800

    update daily

commit 2666983f89
Author: Vick Scarlet <scarlet_vick@outlook.com>
Date:   Sun Nov 7 23:00:22 2021 +0800

    add uiManager auto scan and load skin resource

commit 22fa5d755a
Author: Vick Scarlet <scarlet_vick@outlook.com>
Date:   Sun Nov 7 22:17:04 2021 +0800

    update framework

commit f40698d63e
Author: Vick Scarlet <scarlet_vick@outlook.com>
Date:   Sun Oct 31 00:13:22 2021 +0800

    add laya
2021-12-31 20:31:26 +08:00

181 lines
6.1 KiB
HTML

颜值: <input class="prop" name="CHR" style="width:300px;" value="5" >(CHR)<br/>
智力: <input class="prop" name="INT" style="width:300px;" value="5" >(INT)<br/>
体质: <input class="prop" name="STR" style="width:300px;" value="5" >(STR)<br/>
家境: <input class="prop" name="MNY" style="width:300px;" value="5" >(MNY)<br/>
快乐: <input class="prop" name="SPR" style="width:300px;" value="5" >(SPR)<br/>
生命: <input class="prop" name="LIF" style="width:300px;" value="5" >(LIF)<br/>
天赋: <input class="prop" name="TLT" style="width:300px;" value="[5]" >(TLT)<br/>
事件: <input class="prop" name="EVT" style="width:300px;" value="[5]" >(EVT)<br/>
<br/><br/>
表达式:<input id="conditions" style="width:500px;"><br/><br/>
结果:<span id="result" style="color:red;"></span><br/><br/>
<button id="submit">&nbsp;&nbsp;&nbsp;&nbsp;</button><br/>
<script>
const DEFAULT_PROP = {
CHR: 5, // 颜值 charm CHR
INT: 5, // 智力 intelligence INT
STR: 5, // 体质 strength STR
MNY: 5, // 家境 money MNY
SPR: 5, // 快乐 spirit SPR
LIF: 5, // 生命 life LIF
TLT: [5], // 天赋 talent TLT
EVT: [5], // 事件 event EVT
};
document.querySelector("#submit").onclick = function() {
document.querySelectorAll('.prop').forEach(({name, value})=>DEFAULT_PROP[name] = JSON.parse(value));
conditions = document.querySelector("#conditions").value;
const result = check(conditions);
document.querySelector("#result").textContent = result;
}
function getProp(prop) {
switch(prop) {
case 'CHR':
case 'INT':
case 'STR':
case 'MNY':
case 'SPR':
case 'LIF':
case 'TLT':
case 'EVT': return DEFAULT_PROP[prop];
default: return null;
}
}
function check(condition) {
const conditions = parseCondition(condition);
return checkParsedCondition(conditions);
}
function checkParsedCondition(conditions) {
if(!Array.isArray(conditions)) return checkLogic(conditions);
if(conditions.length == 0) return true;
if(conditions.length == 1) return checkParsedCondition(conditions[0]);
let ret = checkParsedCondition(conditions[0]);
for(let i=1; i<conditions.length; i+=2) {
switch(conditions[i]) {
case '&':
if(ret) ret = checkParsedCondition(conditions[i+1]);
break;
case '|':
if(ret) return true;
ret = checkParsedCondition(conditions[i+1]);
break;
default: return false;
}
}
return ret;
}
function checkLogic(condition) {
const length = condition.length;
let i = condition.search(/[><\!\?=]/);
const prop = condition.substring(0,i);
const symbol = condition.substring(i, i+=(condition[i+1]=='='?2:1));
const d = condition.substring(i, length);
const propData = getProp(prop);
const conditionData = d[0]=='['? JSON.parse(d): Number(d);
switch(symbol) {
case '>': return propData > conditionData;
case '<': return propData < conditionData;
case '>=': return propData >= conditionData;
case '<=': return propData <= conditionData;
case '=':
if(Array.isArray(propData))
return propData.includes(conditionData);
return propData == conditionData;
case '!=':
if(Array.isArray(propData))
return !propData.includes(conditionData);
return propData == conditionData;
case '?':
if(Array.isArray(propData)) {
for(const p of propData)
if(conditionData.includes(p)) return true;
return false;
}
return conditionData.includes(propData);
case '!':
if(Array.isArray(propData)) {
for(const p of propData)
if(conditionData.includes(p)) return false;
return true;
}
return !conditionData.includes(propData);
default: return false;
}
}
function parseCondition(condition) {
const conditions = [];
const length = condition.length;
const stack = [];
stack.unshift(conditions);
let cursor = 0;
const catchString = i => {
const str = condition.substring(cursor, i).trim();
cursor = i;
if(str) stack[0].push(str);
};
for(let i=0; i<length; i++) {
switch(condition[i]) {
case ' ': continue;
case '(':
catchString(i);
cursor ++;
const sub = [];
stack[0].push(sub);
stack.unshift(sub);
break;
case ')':
catchString(i);
cursor ++;
stack.shift();
break;
case '|':
case '&':
catchString(i);
catchString(i+1);
break;
default: continue;
}
}
catchString(length);
return conditions;
}
// function debug(...conditions) {
// for(const condition of conditions)
// console.debug(check(condition), '\t', condition);
// }
//
// debug(
// '(STR<2&MNY>3)|(MNY<2&CHR<2)',
// '(STR<2&MNY>3)',
// '(STR>2&MNY>3)',
// '((((STR>2&MNY>2))))',
// '((((STR>2&MNY>2)|(MNY<2&CHR<2))))',
// '((((STR>2&MNY>2)|(MNY<2&CHR<2)&(STR>2&MNY>3))))',
// '((((STR>2&MNY>2)|(MNY<2&CHR<2))&(STR>2&MNY>3)))',
// 'EVT![1,2,3]',
// 'EVT![1,2]',
// 'EVT?[1,2,3]',
// 'EVT?[1,2]',
// );
</script>