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