Skip to content

Commit f8f3548

Browse files
committed
feat: update devtools
1 parent b7cb7d8 commit f8f3548

File tree

15 files changed

+74
-10
lines changed

15 files changed

+74
-10
lines changed

packages/devtools/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "minigame-canvas-engine-devtools",
3-
"version": "1.1.0",
3+
"version": "1.1.1",
44
"description": "一些工具函数和方法,在调试阶段用于提高效率",
55
"main": "dist/index.js",
66
"scripts": {

packages/devtools/src/app.vue

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,13 +66,28 @@ export default defineComponent({
6666
doTCompile() {
6767
let xml = document.getElementById("template")?.innerHTML;
6868
69+
if (process.env.NODE_ENV !== 'production') {
70+
xml = (window as any).layoutTpl;
71+
}
72+
6973
// 没有监听到模板的情况
7074
if (!xml) {
7175
this.showNoXMLDialog = true;
7276
return;
7377
}
7478
75-
let comment = `/**\n * xml经过doT.js编译出的模板函数\n * 因为小游戏不支持new Function,模板函数只能外部编译\n * 可直接拷贝本函数到小游戏中使用\n */\n`;
79+
let comment =
80+
`
81+
/**
82+
* 模板引擎使用教程可见:https://wechat-miniprogram.github.io/minigame-canvas-engine/tutorial/templateengine.html
83+
* xml经过doT.js编译出的模板函数
84+
* 因为小游戏不支持new Function,模板函数只能外部编译
85+
* 可直接拷贝本函数到小游戏中使用
86+
* 原始的模板如下:
87+
* ${xml}
88+
*
89+
*/
90+
`;
7691
7792
const tplFunc = String(template(xml));
7893

packages/devtools/src/demos/bitmaptext.vue

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,11 @@ export default defineComponent({
3535
3636
methods: {
3737
init() {
38+
// for devtools debug
39+
if (process.env.NODE_ENV !== 'production') {
40+
(window as any).layoutTpl = tpl;
41+
}
42+
3843
const Layout = (window as any).Layout;
3944
Layout.registBitMapFont(
4045
"fnt_number-export",

packages/devtools/src/demos/button.vue

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import { defineComponent } from "vue";
44
55
// <image src="https://res.wx.qq.com/wechatgame/product/webpack/userupload/20191119/wegoing.jpeg" id="wegoing"></image>
66
7-
let template = `
7+
let tpl = `
88
<view id="container">
99
<button id="testButton" value="邀请"></button>
1010
</view>
@@ -31,8 +31,13 @@ export default defineComponent({
3131
mounted() {},
3232
methods: {
3333
init() {
34+
// for devtools debug
35+
if (process.env.NODE_ENV !== 'production') {
36+
(window as any).layoutTpl = tpl;
37+
}
38+
3439
const Layout = (window as any).Layout;
35-
Layout.init(template, style);
40+
Layout.init(tpl, style);
3641
3742
let canvas = document.getElementById("button") as HTMLCanvasElement;
3843
let context = canvas.getContext("2d");

packages/devtools/src/demos/canvas.vue

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,11 @@ export default defineComponent({
4242
mounted() {},
4343
methods: {
4444
init() {
45+
// for devtools debug
46+
if (process.env.NODE_ENV !== 'production') {
47+
(window as any).layoutTpl = tpl;
48+
}
49+
4550
const Layout = (window as any).Layout;
4651
Layout.init(template(tpl)({}), style);
4752

packages/devtools/src/demos/helloworld.vue

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<script lang="ts">
22
import { defineComponent } from "vue";
33
4-
let template = `
4+
let tpl = `
55
<view id="container">
66
<text id="testText" class="redText" value="Hello World"></text>
77
</view>
@@ -38,9 +38,13 @@ export default defineComponent({
3838
mounted() {},
3939
methods: {
4040
init() {
41+
// for devtools debug
42+
if (process.env.NODE_ENV !== 'production') {
43+
(window as any).layoutTpl = tpl;
44+
}
4145
const Layout = (window as any).Layout;
4246
43-
Layout.init(template, style);
47+
Layout.init(tpl, style);
4448
let canvas = document.getElementById("helloworld") as HTMLCanvasElement;
4549
let context = canvas.getContext("2d");
4650
document.body.append(canvas);

packages/devtools/src/demos/insertElement.vue

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ const renderRect = {
55
width: 400,
66
height: 600,
77
};
8-
const template = `
8+
const tpl = `
99
<view class="container">
1010
<text class="loading" value="加载中..."></text>
1111
<scrollview class="scrollView" scrollY="true"></scrollview>
@@ -45,6 +45,10 @@ export default defineComponent({
4545
mounted() {},
4646
methods: {
4747
init() {
48+
// for devtools debug
49+
if (process.env.NODE_ENV !== 'production') {
50+
(window as any).layoutTpl = tpl;
51+
}
4852
let canvas = document.getElementById("insertElement") as HTMLCanvasElement;
4953
let context = canvas.getContext("2d");
5054
canvas.style.width = 400 / 2 + 'px';
@@ -54,7 +58,7 @@ export default defineComponent({
5458
5559
const Layout = (window as any).Layout;
5660
Layout.updateViewPort(canvas.getBoundingClientRect());
57-
Layout.init(template, style);
61+
Layout.init(tpl, style);
5862
5963
Layout.layout(context);
6064
// 模拟数据加载

packages/devtools/src/demos/invite.vue

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,10 @@ export default defineComponent({
9595
mounted() {},
9696
methods: {
9797
init() {
98+
// for devtools debug
99+
if (process.env.NODE_ENV !== 'production') {
100+
(window as any).layoutTpl = tpl;
101+
}
98102
const Layout = (window as any).Layout;
99103
let canvas = document.getElementById("invite") as HTMLCanvasElement;
100104
let context = canvas.getContext("2d");

packages/devtools/src/demos/loading.vue

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,10 @@ export default defineComponent({
3131
mounted() {},
3232
methods: {
3333
init() {
34+
// for devtools debug
35+
if (process.env.NODE_ENV !== 'production') {
36+
(window as any).layoutTpl = tpl;
37+
}
3438
const Layout = (window as any).Layout;
3539
Layout.init(tpl, style);
3640

packages/devtools/src/demos/ranklist.vue

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,10 @@ export default defineComponent({
151151
mounted() {},
152152
methods: {
153153
init() {
154+
// for devtools debug
155+
if (process.env.NODE_ENV !== 'production') {
156+
(window as any).layoutTpl = tpl;
157+
}
154158
const Layout = (window as any).Layout;
155159
// 创建mock数据
156160
let item = {

0 commit comments

Comments
 (0)