Resolve #5755
This commit is contained in:
@ -28,7 +28,7 @@ export default Vue.extend({
|
||||
text: this.script.interpolate(this.value.content)
|
||||
});
|
||||
} else if (this.value.action === 'resetRandom') {
|
||||
this.script.aiScript.updateRandomSeed(Math.random());
|
||||
this.script.aoiScript.updateRandomSeed(Math.random());
|
||||
this.script.eval();
|
||||
} else if (this.value.action === 'pushEvent') {
|
||||
this.$root.api('page-push', {
|
||||
@ -43,6 +43,8 @@ export default Vue.extend({
|
||||
type: 'success',
|
||||
text: this.script.interpolate(this.value.message)
|
||||
});
|
||||
} else if (this.value.action === 'callAiScript') {
|
||||
this.script.callAiScript(this.value.fn);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -27,7 +27,7 @@ export default Vue.extend({
|
||||
},
|
||||
watch: {
|
||||
v() {
|
||||
this.script.aiScript.updatePageVar(this.value.name, this.v);
|
||||
this.script.aoiScript.updatePageVar(this.value.name, this.v);
|
||||
this.script.eval();
|
||||
}
|
||||
},
|
||||
|
@ -27,7 +27,7 @@ export default Vue.extend({
|
||||
},
|
||||
watch: {
|
||||
v() {
|
||||
this.script.aiScript.updatePageVar(this.value.name, this.v);
|
||||
this.script.aoiScript.updatePageVar(this.value.name, this.v);
|
||||
this.script.eval();
|
||||
}
|
||||
}
|
||||
|
@ -28,7 +28,7 @@ export default Vue.extend({
|
||||
},
|
||||
watch: {
|
||||
v() {
|
||||
this.script.aiScript.updatePageVar(this.value.name, this.v);
|
||||
this.script.aoiScript.updatePageVar(this.value.name, this.v);
|
||||
this.script.eval();
|
||||
}
|
||||
}
|
||||
|
@ -27,7 +27,7 @@ export default Vue.extend({
|
||||
},
|
||||
watch: {
|
||||
v() {
|
||||
this.script.aiScript.updatePageVar(this.value.name, this.v);
|
||||
this.script.aoiScript.updatePageVar(this.value.name, this.v);
|
||||
this.script.eval();
|
||||
}
|
||||
}
|
||||
|
@ -27,7 +27,7 @@ export default Vue.extend({
|
||||
},
|
||||
watch: {
|
||||
v() {
|
||||
this.script.aiScript.updatePageVar(this.value.name, this.v);
|
||||
this.script.aoiScript.updatePageVar(this.value.name, this.v);
|
||||
this.script.eval();
|
||||
}
|
||||
}
|
||||
|
@ -27,7 +27,7 @@ export default Vue.extend({
|
||||
},
|
||||
watch: {
|
||||
v() {
|
||||
this.script.aiScript.updatePageVar(this.value.name, this.v);
|
||||
this.script.aoiScript.updatePageVar(this.value.name, this.v);
|
||||
this.script.eval();
|
||||
}
|
||||
}
|
||||
|
@ -6,30 +6,57 @@
|
||||
|
||||
<script lang="ts">
|
||||
import Vue from 'vue';
|
||||
import i18n from '../../i18n';
|
||||
import { AiScript, parse, values } from '@syuilo/aiscript';
|
||||
import { faHeart as faHeartS } from '@fortawesome/free-solid-svg-icons';
|
||||
import { faHeart } from '@fortawesome/free-regular-svg-icons';
|
||||
import i18n from '../../i18n';
|
||||
import XBlock from './page.block.vue';
|
||||
import { ASEvaluator } from '../../scripts/aoiscript/evaluator';
|
||||
import { collectPageVars } from '../../scripts/collect-page-vars';
|
||||
import { url } from '../../config';
|
||||
|
||||
class Script {
|
||||
public aiScript: ASEvaluator;
|
||||
public aoiScript: ASEvaluator;
|
||||
private onError: any;
|
||||
public vars: Record<string, any>;
|
||||
public page: Record<string, any>;
|
||||
|
||||
constructor(page, aiScript, onError) {
|
||||
constructor(page, aoiScript, onError, cb) {
|
||||
this.page = page;
|
||||
this.aiScript = aiScript;
|
||||
this.aoiScript = aoiScript;
|
||||
this.onError = onError;
|
||||
this.eval();
|
||||
|
||||
if (this.page.script) {
|
||||
let ast;
|
||||
try {
|
||||
ast = parse(this.page.script);
|
||||
} catch (e) {
|
||||
console.error(e);
|
||||
/*this.$root.dialog({
|
||||
type: 'error',
|
||||
text: 'Syntax error :('
|
||||
});*/
|
||||
return;
|
||||
}
|
||||
this.aoiScript.aiscript.exec(ast).then(() => {
|
||||
this.eval();
|
||||
cb();
|
||||
}).catch(e => {
|
||||
console.error(e);
|
||||
/*this.$root.dialog({
|
||||
type: 'error',
|
||||
text: e
|
||||
});*/
|
||||
});
|
||||
} else {
|
||||
this.eval();
|
||||
cb();
|
||||
}
|
||||
}
|
||||
|
||||
public eval() {
|
||||
try {
|
||||
this.vars = this.aiScript.evaluateVars();
|
||||
this.vars = this.aoiScript.evaluateVars();
|
||||
} catch (e) {
|
||||
this.onError(e);
|
||||
}
|
||||
@ -42,6 +69,10 @@ class Script {
|
||||
return v == null ? 'NULL' : v.toString();
|
||||
});
|
||||
}
|
||||
|
||||
public callAiScript(fn: string) {
|
||||
this.aoiScript.aiscript.execFn(this.aoiScript.aiscript.scope.get(fn), []);
|
||||
}
|
||||
}
|
||||
|
||||
export default Vue.extend({
|
||||
@ -67,14 +98,21 @@ export default Vue.extend({
|
||||
|
||||
created() {
|
||||
const pageVars = this.getPageVars();
|
||||
this.script = new Script(this.page, new ASEvaluator(this.page.variables, pageVars, {
|
||||
|
||||
const s = new Script(this.page, new ASEvaluator(this, this.page.variables, pageVars, {
|
||||
randomSeed: Math.random(),
|
||||
visitor: this.$store.state.i,
|
||||
page: this.page,
|
||||
url: url
|
||||
}), e => {
|
||||
console.dir(e);
|
||||
}, () => {
|
||||
this.script = s;
|
||||
});
|
||||
|
||||
s.aoiScript.aiscript.scope.opts.onUpdated = (name, value) => {
|
||||
s.eval();
|
||||
};
|
||||
},
|
||||
|
||||
methods: {
|
||||
|
Reference in New Issue
Block a user