Improve AiScript

This commit is contained in:
syuilo 2019-05-01 14:54:34 +09:00
parent d0af2c2a98
commit 52ebf2055e
No known key found for this signature in database
GPG key ID: BDC4C49D06AB9D69
6 changed files with 80 additions and 75 deletions

View file

@ -1,5 +1,5 @@
<template>
<div v-show="script.vars.find(x => x.name === value.var).value">
<div v-show="script.vars[value.var]">
<x-block v-for="child in value.children" :value="child" :page="page" :script="script" :key="child.id" :h="h"/>
</div>
</template>

View file

@ -27,7 +27,7 @@ import { url } from '../../../../config';
class Script {
public aiScript: AiScript;
public vars: any;
public vars: Record<string, any>;
constructor(aiScript) {
this.aiScript = aiScript;
@ -41,7 +41,7 @@ class Script {
public interpolate(str: string) {
if (str == null) return null;
return str.replace(/\{(.+?)\}/g, match => {
const v = this.vars.find(x => x.name === match.slice(1, -1).trim()).value;
const v = this.vars[match.slice(1, -1).trim()];
return v == null ? 'NULL' : v.toString();
});
}