2019-04-29 09:11:57 +09:00
|
|
|
<template>
|
2020-01-30 06:19:18 +09:00
|
|
|
<div class="iroscrza" :class="{ center: page.alignCenter, serif: page.font === 'serif' }" v-if="script">
|
|
|
|
<x-block v-for="child in page.content" :value="child" @input="v => updateBlock(v)" :page="page" :script="script" :key="child.id" :h="2"/>
|
2019-04-29 09:11:57 +09:00
|
|
|
</div>
|
|
|
|
</template>
|
|
|
|
|
|
|
|
<script lang="ts">
|
|
|
|
import Vue from 'vue';
|
2020-04-13 03:23:23 +09:00
|
|
|
import { AiScript, parse, values } from '@syuilo/aiscript';
|
2019-05-17 19:56:47 +09:00
|
|
|
import { faHeart as faHeartS } from '@fortawesome/free-solid-svg-icons';
|
2019-07-07 06:56:13 +09:00
|
|
|
import { faHeart } from '@fortawesome/free-regular-svg-icons';
|
2020-04-13 03:23:23 +09:00
|
|
|
import i18n from '../../i18n';
|
2019-04-29 09:11:57 +09:00
|
|
|
import XBlock from './page.block.vue';
|
2020-04-12 19:38:19 +09:00
|
|
|
import { ASEvaluator } from '../../scripts/aoiscript/evaluator';
|
2020-01-30 04:37:25 +09:00
|
|
|
import { collectPageVars } from '../../scripts/collect-page-vars';
|
|
|
|
import { url } from '../../config';
|
2019-04-29 09:11:57 +09:00
|
|
|
|
|
|
|
class Script {
|
2020-04-13 03:23:23 +09:00
|
|
|
public aoiScript: ASEvaluator;
|
2019-05-01 15:17:24 +09:00
|
|
|
private onError: any;
|
2019-05-01 14:54:34 +09:00
|
|
|
public vars: Record<string, any>;
|
2019-07-06 18:14:50 +09:00
|
|
|
public page: Record<string, any>;
|
2019-04-29 09:11:57 +09:00
|
|
|
|
2020-04-13 03:23:23 +09:00
|
|
|
constructor(page, aoiScript, onError, cb) {
|
2019-07-06 18:14:50 +09:00
|
|
|
this.page = page;
|
2020-04-13 03:23:23 +09:00
|
|
|
this.aoiScript = aoiScript;
|
2019-05-01 15:17:24 +09:00
|
|
|
this.onError = onError;
|
2020-04-13 03:23:23 +09:00
|
|
|
|
|
|
|
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();
|
|
|
|
}
|
2019-04-29 09:11:57 +09:00
|
|
|
}
|
|
|
|
|
2019-05-01 15:17:24 +09:00
|
|
|
public eval() {
|
|
|
|
try {
|
2020-04-13 03:23:23 +09:00
|
|
|
this.vars = this.aoiScript.evaluateVars();
|
2019-05-01 15:17:24 +09:00
|
|
|
} catch (e) {
|
|
|
|
this.onError(e);
|
|
|
|
}
|
2019-04-29 09:11:57 +09:00
|
|
|
}
|
|
|
|
|
|
|
|
public interpolate(str: string) {
|
2019-04-30 06:40:02 +09:00
|
|
|
if (str == null) return null;
|
2019-05-05 09:27:55 +09:00
|
|
|
return str.replace(/{(.+?)}/g, match => {
|
2019-05-01 14:54:34 +09:00
|
|
|
const v = this.vars[match.slice(1, -1).trim()];
|
2019-04-29 11:08:35 +09:00
|
|
|
return v == null ? 'NULL' : v.toString();
|
|
|
|
});
|
2019-04-29 09:11:57 +09:00
|
|
|
}
|
2020-04-13 03:23:23 +09:00
|
|
|
|
|
|
|
public callAiScript(fn: string) {
|
|
|
|
this.aoiScript.aiscript.execFn(this.aoiScript.aiscript.scope.get(fn), []);
|
|
|
|
}
|
2019-04-29 09:11:57 +09:00
|
|
|
}
|
|
|
|
|
|
|
|
export default Vue.extend({
|
2020-01-30 04:37:25 +09:00
|
|
|
i18n,
|
2019-04-29 09:11:57 +09:00
|
|
|
|
|
|
|
components: {
|
|
|
|
XBlock
|
|
|
|
},
|
|
|
|
|
|
|
|
props: {
|
2019-07-07 06:56:13 +09:00
|
|
|
page: {
|
|
|
|
type: Object,
|
2019-04-29 09:11:57 +09:00
|
|
|
required: true
|
|
|
|
},
|
|
|
|
},
|
|
|
|
|
|
|
|
data() {
|
|
|
|
return {
|
|
|
|
script: null,
|
2019-05-17 19:56:47 +09:00
|
|
|
faHeartS, faHeart
|
2019-04-29 09:11:57 +09:00
|
|
|
};
|
|
|
|
},
|
|
|
|
|
|
|
|
created() {
|
2019-07-07 06:56:13 +09:00
|
|
|
const pageVars = this.getPageVars();
|
2020-04-13 03:23:23 +09:00
|
|
|
|
|
|
|
const s = new Script(this.page, new ASEvaluator(this, this.page.variables, pageVars, {
|
2019-07-07 06:56:13 +09:00
|
|
|
randomSeed: Math.random(),
|
|
|
|
visitor: this.$store.state.i,
|
|
|
|
page: this.page,
|
|
|
|
url: url
|
|
|
|
}), e => {
|
|
|
|
console.dir(e);
|
2020-04-13 03:23:23 +09:00
|
|
|
}, () => {
|
|
|
|
this.script = s;
|
2019-07-07 06:56:13 +09:00
|
|
|
});
|
2020-04-13 03:23:23 +09:00
|
|
|
|
|
|
|
s.aoiScript.aiscript.scope.opts.onUpdated = (name, value) => {
|
|
|
|
s.eval();
|
|
|
|
};
|
2019-04-29 09:11:57 +09:00
|
|
|
},
|
|
|
|
|
|
|
|
methods: {
|
|
|
|
getPageVars() {
|
|
|
|
return collectPageVars(this.page.content);
|
|
|
|
},
|
|
|
|
}
|
|
|
|
});
|
|
|
|
</script>
|
|
|
|
|
2020-01-30 04:37:25 +09:00
|
|
|
<style lang="scss" scoped>
|
|
|
|
.iroscrza {
|
|
|
|
&.serif {
|
|
|
|
> div {
|
|
|
|
font-family: serif;
|
|
|
|
}
|
|
|
|
}
|
2019-04-29 09:11:57 +09:00
|
|
|
|
2020-01-30 04:37:25 +09:00
|
|
|
&.center {
|
|
|
|
text-align: center;
|
|
|
|
}
|
|
|
|
}
|
2019-04-29 09:11:57 +09:00
|
|
|
</style>
|