Fix page bug

This commit is contained in:
syuilo 2020-10-18 12:55:26 +09:00
parent 244822298a
commit f0c5943e87
4 changed files with 6 additions and 8 deletions

View File

@ -6,7 +6,6 @@
<script lang="ts"> <script lang="ts">
import { defineComponent } from 'vue'; import { defineComponent } from 'vue';
import * as os from '@/os';
export default defineComponent({ export default defineComponent({
props: { props: {

View File

@ -5,7 +5,6 @@
<script lang="ts"> <script lang="ts">
import { defineComponent } from 'vue'; import { defineComponent } from 'vue';
import MkTextarea from '../ui/textarea.vue'; import MkTextarea from '../ui/textarea.vue';
import * as os from '@/os';
export default defineComponent({ export default defineComponent({
components: { components: {

View File

@ -12,7 +12,6 @@ import { faHeart } from '@fortawesome/free-regular-svg-icons';
import XBlock from './page.block.vue'; import XBlock from './page.block.vue';
import { Hpml } from '@/scripts/hpml/evaluator'; import { Hpml } from '@/scripts/hpml/evaluator';
import { url } from '@/config'; import { url } from '@/config';
import * as os from '@/os';
export default defineComponent({ export default defineComponent({
components: { components: {

View File

@ -7,6 +7,7 @@ import { createAiScriptEnv } from '../aiscript/api';
import { collectPageVars } from '../collect-page-vars'; import { collectPageVars } from '../collect-page-vars';
import { initLib } from './lib'; import { initLib } from './lib';
import * as os from '@/os'; import * as os from '@/os';
import { markRaw, ref, Ref } from 'vue';
type Fn = { type Fn = {
slots: string[]; slots: string[];
@ -23,7 +24,7 @@ export class Hpml {
public aiscript?: AiScript; public aiscript?: AiScript;
private pageVarUpdatedCallback; private pageVarUpdatedCallback;
public canvases: Record<string, HTMLCanvasElement> = {}; public canvases: Record<string, HTMLCanvasElement> = {};
public vars: Record<string, any>; public vars: Ref<Record<string, any>> = ref({});
public page: Record<string, any>; public page: Record<string, any>;
private opts: { private opts: {
@ -38,7 +39,7 @@ export class Hpml {
this.opts = opts; this.opts = opts;
if (this.opts.enableAiScript) { if (this.opts.enableAiScript) {
this.aiscript = new AiScript({ ...createAiScriptEnv({ this.aiscript = markRaw(new AiScript({ ...createAiScriptEnv({
storageKey: 'pages:' + this.page.id storageKey: 'pages:' + this.page.id
}), ...initLib(this)}, { }), ...initLib(this)}, {
in: (q) => { in: (q) => {
@ -56,7 +57,7 @@ export class Hpml {
}, },
log: (type, params) => { log: (type, params) => {
}, },
}); }));
this.aiscript.scope.opts.onUpdated = (name, value) => { this.aiscript.scope.opts.onUpdated = (name, value) => {
this.eval(); this.eval();
@ -89,7 +90,7 @@ export class Hpml {
@autobind @autobind
public eval() { public eval() {
try { try {
this.vars = this.evaluateVars(); this.vars.value = this.evaluateVars();
} catch (e) { } catch (e) {
//this.onError(e); //this.onError(e);
} }
@ -99,7 +100,7 @@ export class Hpml {
public interpolate(str: string) { public interpolate(str: string) {
if (str == null) return null; if (str == null) return null;
return str.replace(/{(.+?)}/g, match => { return str.replace(/{(.+?)}/g, match => {
const v = this.vars ? this.vars[match.slice(1, -1).trim()] : null; const v = this.vars[match.slice(1, -1).trim()];
return v == null ? 'NULL' : v.toString(); return v == null ? 'NULL' : v.toString();
}); });
} }