Improve AiScript

This commit is contained in:
syuilo 2019-05-01 15:17:24 +09:00
parent b6c50d63a0
commit 4747ae8b61
No known key found for this signature in database
GPG Key ID: BDC4C49D06AB9D69
8 changed files with 32 additions and 18 deletions

View File

@ -139,8 +139,12 @@ const envVarsDef = {
}; };
class AiScriptError extends Error { class AiScriptError extends Error {
constructor(...params) { public info?: any;
super(...params);
constructor(message: string, info?: any) {
super(message);
this.info = info;
// Maintains proper stack trace for where our error was thrown (only available on V8) // Maintains proper stack trace for where our error was thrown (only available on V8)
if (Error.captureStackTrace) { if (Error.captureStackTrace) {
@ -178,7 +182,9 @@ class Scope {
} }
throw new AiScriptError( throw new AiScriptError(
`No such variable '${name}' in scope '${this.name}'`); `No such variable '${name}' in scope '${this.name}'`, {
scope: this.layerdStates
});
} }
} }

View File

@ -6,25 +6,25 @@ export function collectPageVars(content) {
pageVars.push({ pageVars.push({
name: x.name, name: x.name,
type: 'string', type: 'string',
value: x.default value: x.default || ''
}); });
} else if (x.type === 'textareaInput') { } else if (x.type === 'textareaInput') {
pageVars.push({ pageVars.push({
name: x.name, name: x.name,
type: 'string', type: 'string',
value: x.default value: x.default || ''
}); });
} else if (x.type === 'numberInput') { } else if (x.type === 'numberInput') {
pageVars.push({ pageVars.push({
name: x.name, name: x.name,
type: 'number', type: 'number',
value: x.default value: x.default || 0
}); });
} else if (x.type === 'switch') { } else if (x.type === 'switch') {
pageVars.push({ pageVars.push({
name: x.name, name: x.name,
type: 'boolean', type: 'boolean',
value: x.default value: x.default || false
}); });
} else if (x.children) { } else if (x.children) {
collect(x.children); collect(x.children);

View File

@ -20,13 +20,13 @@ export default Vue.extend({
methods: { methods: {
click() { click() {
if (this.value.action === 'dialog') { if (this.value.action === 'dialog') {
this.script.reEval(); this.script.eval();
this.$root.dialog({ this.$root.dialog({
text: this.script.interpolate(this.value.content) text: this.script.interpolate(this.value.content)
}); });
} else if (this.value.action === 'resetRandom') { } else if (this.value.action === 'resetRandom') {
this.script.aiScript.updateRandomSeed(Math.random()); this.script.aiScript.updateRandomSeed(Math.random());
this.script.reEval(); this.script.eval();
} }
} }
} }

View File

@ -26,7 +26,7 @@ export default Vue.extend({
watch: { watch: {
v() { v() {
this.script.aiScript.updatePageVar(this.value.name, this.v); this.script.aiScript.updatePageVar(this.value.name, this.v);
this.script.reEval(); this.script.eval();
} }
} }
}); });

View File

@ -26,7 +26,7 @@ export default Vue.extend({
watch: { watch: {
v() { v() {
this.script.aiScript.updatePageVar(this.value.name, this.v); this.script.aiScript.updatePageVar(this.value.name, this.v);
this.script.reEval(); this.script.eval();
} }
} }
}); });

View File

@ -26,7 +26,7 @@ export default Vue.extend({
watch: { watch: {
v() { v() {
this.script.aiScript.updatePageVar(this.value.name, this.v); this.script.aiScript.updatePageVar(this.value.name, this.v);
this.script.reEval(); this.script.eval();
} }
} }
}); });

View File

@ -26,7 +26,7 @@ export default Vue.extend({
watch: { watch: {
v() { v() {
this.script.aiScript.updatePageVar(this.value.name, this.v); this.script.aiScript.updatePageVar(this.value.name, this.v);
this.script.reEval(); this.script.eval();
} }
} }
}); });

View File

@ -27,15 +27,21 @@ import { url } from '../../../../config';
class Script { class Script {
public aiScript: AiScript; public aiScript: AiScript;
private onError: any;
public vars: Record<string, any>; public vars: Record<string, any>;
constructor(aiScript) { constructor(aiScript, onError) {
this.aiScript = aiScript; this.aiScript = aiScript;
this.vars = this.aiScript.evaluateVars(); this.onError = onError;
this.eval();
} }
public reEval() { public eval() {
this.vars = this.aiScript.evaluateVars(); try {
this.vars = this.aiScript.evaluateVars();
} catch (e) {
this.onError(e);
}
} }
public interpolate(str: string) { public interpolate(str: string) {
@ -86,7 +92,9 @@ export default Vue.extend({
visitor: this.$store.state.i, visitor: this.$store.state.i,
page: page, page: page,
url: url url: url
})); }), e => {
console.dir(e);
});
}); });
}, },