Complete Cocos Creator port with level bundles, themes, and tooling.
Adds level prefabs, theme assets, audio, extensions, and deployment scripts for the Unity WebGL migration. Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
173
extensions/game-controller-inspector/dist/footer.js
vendored
Normal file
173
extensions/game-controller-inspector/dist/footer.js
vendored
Normal file
@@ -0,0 +1,173 @@
|
||||
'use strict';
|
||||
|
||||
/** AppRoot Inspector:SwitchLevel + 游戏调试(对齐 Unity TestPlayer) */
|
||||
|
||||
function compUuid(dump) {
|
||||
if (!dump || !dump.value) return '';
|
||||
const u = dump.value.uuid;
|
||||
return (u && u.value) ? u.value : (typeof u === 'string' ? u : '');
|
||||
}
|
||||
|
||||
function nodeUuid(dump) {
|
||||
if (!dump || !dump.value) return '';
|
||||
const n = dump.value.node;
|
||||
return (n && n.value && n.value.uuid) ? n.value.uuid : '';
|
||||
}
|
||||
|
||||
function getMessageProtocolScene(el) {
|
||||
let element = el;
|
||||
while (element) {
|
||||
const root = element.getRootNode && element.getRootNode();
|
||||
element = element.parentElement || (root && root.host) || null;
|
||||
if (element && element.messageProtocol && element.messageProtocol.scene) {
|
||||
return element.messageProtocol.scene;
|
||||
}
|
||||
}
|
||||
return 'scene';
|
||||
}
|
||||
|
||||
async function callMethod(contextEl, uuid, name, args) {
|
||||
if (!uuid || typeof Editor === 'undefined') return;
|
||||
const protocols = [];
|
||||
const primary = getMessageProtocolScene(contextEl);
|
||||
if (primary) protocols.push(primary);
|
||||
if (protocols.indexOf('scene') < 0) protocols.push('scene');
|
||||
let lastErr;
|
||||
for (let i = 0; i < protocols.length; i++) {
|
||||
try {
|
||||
await Editor.Message.request(protocols[i], 'execute-component-method', {
|
||||
uuid,
|
||||
name,
|
||||
args: args || [],
|
||||
});
|
||||
return;
|
||||
} catch (e) {
|
||||
lastErr = e;
|
||||
}
|
||||
}
|
||||
console.warn('[game-controller-inspector]', name, lastErr);
|
||||
}
|
||||
|
||||
async function findGameControllerUuid(nu) {
|
||||
if (!nu) return null;
|
||||
try {
|
||||
const node = await Editor.Message.request('scene', 'query-node', nu);
|
||||
for (const c of node?.__comps__ || []) {
|
||||
if (c.type === 'GameController' || c.type === '8940aPSKJhGKKIBE/qKnFm7') {
|
||||
return c.value.uuid.value;
|
||||
}
|
||||
}
|
||||
} catch (e) {
|
||||
console.warn('[game-controller-inspector] query-node failed', e);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
async function callGame(contextEl, dump, method, args) {
|
||||
const gc = await findGameControllerUuid(nodeUuid(dump));
|
||||
if (!gc) {
|
||||
console.warn('[game-controller-inspector] 请先点预览 ▶,等关卡加载后再调试');
|
||||
return;
|
||||
}
|
||||
await callMethod(contextEl, gc, method, args);
|
||||
}
|
||||
|
||||
function parseStep(raw) {
|
||||
const n = parseInt(String(raw || '1'), 10);
|
||||
return Number.isNaN(n) || n === 0 ? 1 : n;
|
||||
}
|
||||
|
||||
let lastDebugAt = 0;
|
||||
function guardDebug(fn) {
|
||||
return () => {
|
||||
const now = Date.now();
|
||||
if (now - lastDebugAt < 350) return;
|
||||
lastDebugAt = now;
|
||||
fn();
|
||||
};
|
||||
}
|
||||
|
||||
module.exports = Editor.Panel.define({
|
||||
template: `
|
||||
<div class="gc-footer">
|
||||
<ui-label class="hint">① 预览 ▶ ② GameController 填 inputLevel ③ 点 SwitchLevel</ui-label>
|
||||
<div class="row level-nav">
|
||||
<ui-button class="btn-prev">上一关</ui-button>
|
||||
<ui-button class="btn-next">下一关</ui-button>
|
||||
</div>
|
||||
<ui-button class="btn-switch blue">SwitchLevel</ui-button>
|
||||
<ui-label class="sep">— 游戏调试(须预览运行中)—</ui-label>
|
||||
<div class="row">
|
||||
<ui-label class="lbl">步数</ui-label>
|
||||
<ui-input class="step" value="1"></ui-input>
|
||||
</div>
|
||||
<div class="row">
|
||||
<ui-button class="fwd">前进</ui-button>
|
||||
<ui-button class="back">后退</ui-button>
|
||||
<ui-button class="jump">跳</ui-button>
|
||||
</div>
|
||||
<div class="row">
|
||||
<ui-button class="rot-l">左转</ui-button>
|
||||
<ui-button class="rot-r">右转</ui-button>
|
||||
<ui-button class="info">坐标</ui-button>
|
||||
</div>
|
||||
<div class="row">
|
||||
<ui-button class="end">结束输入</ui-button>
|
||||
<ui-button class="veh">载具+1</ui-button>
|
||||
<ui-button class="reset">重置关卡</ui-button>
|
||||
</div>
|
||||
</div>
|
||||
`,
|
||||
style: `
|
||||
.gc-footer { margin-top: 6px; }
|
||||
.gc-footer .hint, .gc-footer .sep {
|
||||
opacity: 0.8;
|
||||
font-size: 11px;
|
||||
margin: 6px 0;
|
||||
display: block;
|
||||
}
|
||||
.gc-footer .row { display: flex; gap: 4px; margin-bottom: 6px; }
|
||||
.gc-footer .lbl { font-size: 11px; align-self: center; min-width: 28px; }
|
||||
.gc-footer .step { flex: 1; }
|
||||
.gc-footer ui-button { flex: 1; }
|
||||
.gc-footer .level-nav { margin-bottom: 4px; }
|
||||
.gc-footer .btn-switch { width: 100%; margin-bottom: 4px; }
|
||||
`,
|
||||
$: {
|
||||
hint: '.hint',
|
||||
step: '.step',
|
||||
btnSwitch: '.btn-switch',
|
||||
btnPrev: '.btn-prev',
|
||||
btnNext: '.btn-next',
|
||||
fwd: '.fwd',
|
||||
back: '.back',
|
||||
jump: '.jump',
|
||||
rotL: '.rot-l',
|
||||
rotR: '.rot-r',
|
||||
info: '.info',
|
||||
end: '.end',
|
||||
veh: '.veh',
|
||||
reset: '.reset',
|
||||
},
|
||||
ready() {
|
||||
const ctx = () => this.$this || this.$.btnSwitch;
|
||||
const step = () => parseStep(this.$.step.value);
|
||||
this.$.btnPrev.addEventListener('confirm', guardDebug(() => void callGame(ctx(), this.dump, 'prevLevel', [])));
|
||||
this.$.btnNext.addEventListener('confirm', guardDebug(() => void callGame(ctx(), this.dump, 'nextLevel', [])));
|
||||
this.$.btnSwitch.addEventListener('confirm', () => {
|
||||
void callMethod(ctx(), compUuid(this.dump), 'switchLevelFromBootstrap', []);
|
||||
});
|
||||
this.$.fwd.addEventListener('confirm', guardDebug(() => void callGame(ctx(), this.dump, 'debugMove', [step()])));
|
||||
this.$.back.addEventListener('confirm', guardDebug(() => void callGame(ctx(), this.dump, 'debugMove', [-step()])));
|
||||
this.$.jump.addEventListener('confirm', guardDebug(() => void callGame(ctx(), this.dump, 'debugJump', [])));
|
||||
this.$.rotL.addEventListener('confirm', guardDebug(() => void callGame(ctx(), this.dump, 'debugRotateLeft', [1])));
|
||||
this.$.rotR.addEventListener('confirm', guardDebug(() => void callGame(ctx(), this.dump, 'debugRotateRight', [1])));
|
||||
this.$.info.addEventListener('confirm', guardDebug(() => void callGame(ctx(), this.dump, 'debugPlayerInfo', [])));
|
||||
this.$.end.addEventListener('confirm', guardDebug(() => void callGame(ctx(), this.dump, 'debugInputEnd', [])));
|
||||
this.$.veh.addEventListener('confirm', guardDebug(() => void callGame(ctx(), this.dump, 'debugVehicleMove', [1])));
|
||||
this.$.reset.addEventListener('confirm', guardDebug(() => void callGame(ctx(), this.dump, 'debugResetLevel', [])));
|
||||
},
|
||||
update(dump) {
|
||||
if (dump) this.dump = dump;
|
||||
},
|
||||
});
|
||||
124
extensions/game-controller-inspector/dist/game-controller-footer.js
vendored
Normal file
124
extensions/game-controller-inspector/dist/game-controller-footer.js
vendored
Normal file
@@ -0,0 +1,124 @@
|
||||
'use strict';
|
||||
|
||||
function compUuid(dump) {
|
||||
if (!dump || !dump.value) return '';
|
||||
const u = dump.value.uuid;
|
||||
return (u && u.value) ? u.value : (typeof u === 'string' ? u : '');
|
||||
}
|
||||
|
||||
function getMessageProtocolScene(el) {
|
||||
let element = el;
|
||||
while (element) {
|
||||
const root = element.getRootNode && element.getRootNode();
|
||||
element = element.parentElement || (root && root.host) || null;
|
||||
if (element && element.messageProtocol && element.messageProtocol.scene) {
|
||||
return element.messageProtocol.scene;
|
||||
}
|
||||
}
|
||||
return 'scene';
|
||||
}
|
||||
|
||||
async function callMethod(contextEl, uuid, name, args) {
|
||||
if (!uuid || typeof Editor === 'undefined') return;
|
||||
const protocols = [];
|
||||
const primary = getMessageProtocolScene(contextEl);
|
||||
if (primary) protocols.push(primary);
|
||||
if (protocols.indexOf('scene') < 0) protocols.push('scene');
|
||||
let lastErr;
|
||||
for (let i = 0; i < protocols.length; i++) {
|
||||
try {
|
||||
await Editor.Message.request(protocols[i], 'execute-component-method', {
|
||||
uuid,
|
||||
name,
|
||||
args: args || [],
|
||||
});
|
||||
return;
|
||||
} catch (e) {
|
||||
lastErr = e;
|
||||
}
|
||||
}
|
||||
console.warn('[game-controller-inspector]', name, lastErr);
|
||||
}
|
||||
|
||||
function parseStep(raw) {
|
||||
const n = parseInt(String(raw || '1'), 10);
|
||||
return Number.isNaN(n) || n === 0 ? 1 : n;
|
||||
}
|
||||
|
||||
module.exports = Editor.Panel.define({
|
||||
template: `
|
||||
<div class="gc-debug">
|
||||
<ui-label class="hint">预览 ▶ 运行后可用(对齐 Unity TestPlayer)</ui-label>
|
||||
<div class="row">
|
||||
<ui-label class="lbl">步数</ui-label>
|
||||
<ui-input class="step" value="1"></ui-input>
|
||||
</div>
|
||||
<div class="row">
|
||||
<ui-button class="fwd">前进</ui-button>
|
||||
<ui-button class="back">后退</ui-button>
|
||||
<ui-button class="jump">跳</ui-button>
|
||||
</div>
|
||||
<div class="row">
|
||||
<ui-button class="rot-l">左转</ui-button>
|
||||
<ui-button class="rot-r">右转</ui-button>
|
||||
<ui-button class="info">坐标</ui-button>
|
||||
</div>
|
||||
<div class="row">
|
||||
<ui-button class="end">结束输入</ui-button>
|
||||
<ui-button class="veh">载具+1</ui-button>
|
||||
<ui-button class="reset">重置关卡</ui-button>
|
||||
</div>
|
||||
<div class="row level-nav">
|
||||
<ui-button class="btn-prev">上一关</ui-button>
|
||||
<ui-button class="btn-next">下一关</ui-button>
|
||||
</div>
|
||||
<ui-button class="btn-switch blue">SwitchLevel</ui-button>
|
||||
</div>
|
||||
`,
|
||||
style: `
|
||||
.gc-debug { margin-top: 6px; }
|
||||
.gc-debug .hint { opacity: 0.75; font-size: 11px; margin-bottom: 8px; display: block; }
|
||||
.gc-debug .row { display: flex; gap: 4px; margin-bottom: 6px; }
|
||||
.gc-debug .lbl { font-size: 11px; align-self: center; }
|
||||
.gc-debug .step { flex: 1; }
|
||||
.gc-debug ui-button { flex: 1; }
|
||||
.gc-debug .level-nav { margin-top: 2px; }
|
||||
.gc-debug .btn-switch { width: 100%; margin-top: 4px; }
|
||||
`,
|
||||
$: {
|
||||
hint: '.hint',
|
||||
step: '.step',
|
||||
fwd: '.fwd',
|
||||
back: '.back',
|
||||
jump: '.jump',
|
||||
rotL: '.rot-l',
|
||||
rotR: '.rot-r',
|
||||
info: '.info',
|
||||
end: '.end',
|
||||
veh: '.veh',
|
||||
reset: '.reset',
|
||||
btnSwitch: '.btn-switch',
|
||||
btnPrev: '.btn-prev',
|
||||
btnNext: '.btn-next',
|
||||
},
|
||||
ready() {
|
||||
const uuid = () => compUuid(this.dump);
|
||||
const step = () => parseStep(this.$.step.value);
|
||||
const ctx = () => this.$this || this.$.btnSwitch;
|
||||
this.$.fwd.addEventListener('confirm', () => void callMethod(ctx(), uuid(), 'debugMove', [step()]));
|
||||
this.$.back.addEventListener('confirm', () => void callMethod(ctx(), uuid(), 'debugMove', [-step()]));
|
||||
this.$.jump.addEventListener('confirm', () => void callMethod(ctx(), uuid(), 'debugJump', []));
|
||||
this.$.rotL.addEventListener('confirm', () => void callMethod(ctx(), uuid(), 'debugRotateLeft', [1]));
|
||||
this.$.rotR.addEventListener('confirm', () => void callMethod(ctx(), uuid(), 'debugRotateRight', [1]));
|
||||
this.$.info.addEventListener('confirm', () => void callMethod(ctx(), uuid(), 'debugPlayerInfo', []));
|
||||
this.$.end.addEventListener('confirm', () => void callMethod(ctx(), uuid(), 'debugInputEnd', []));
|
||||
this.$.veh.addEventListener('confirm', () => void callMethod(ctx(), uuid(), 'debugVehicleMove', [1]));
|
||||
this.$.reset.addEventListener('confirm', () => void callMethod(ctx(), uuid(), 'debugResetLevel', []));
|
||||
this.$.btnPrev.addEventListener('confirm', () => void callMethod(ctx(), uuid(), 'prevLevel', []));
|
||||
this.$.btnNext.addEventListener('confirm', () => void callMethod(ctx(), uuid(), 'nextLevel', []));
|
||||
this.$.btnSwitch.addEventListener('confirm', () => void callMethod(ctx(), uuid(), 'clickSwitchLevel', []));
|
||||
},
|
||||
update(dump) {
|
||||
if (dump) this.dump = dump;
|
||||
},
|
||||
});
|
||||
105
extensions/game-controller-inspector/dist/main.js
vendored
Normal file
105
extensions/game-controller-inspector/dist/main.js
vendored
Normal file
@@ -0,0 +1,105 @@
|
||||
'use strict';
|
||||
|
||||
const fs = require('fs');
|
||||
const path = require('path');
|
||||
|
||||
async function findComp(nodeUuid, typeNames) {
|
||||
if (!nodeUuid || typeof Editor === 'undefined') return null;
|
||||
const node = await Editor.Message.request('scene', 'query-node', nodeUuid);
|
||||
const comps = node?.__comps__ || [];
|
||||
for (const c of comps) {
|
||||
if (typeNames.indexOf(c.type) >= 0) {
|
||||
return c.value.uuid.value;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
async function callOnNode(nodeUuid, typeNames, method, args) {
|
||||
try {
|
||||
const uuid = await findComp(nodeUuid, typeNames);
|
||||
if (!uuid) {
|
||||
console.warn('[game-controller-inspector] 选中节点上未找到', typeNames.join('/'));
|
||||
return;
|
||||
}
|
||||
await Editor.Message.request('scene', 'execute-component-method', {
|
||||
uuid,
|
||||
name: method,
|
||||
args: args || [],
|
||||
});
|
||||
} catch (e) {
|
||||
console.warn('[game-controller-inspector]', method, e);
|
||||
}
|
||||
}
|
||||
|
||||
const BOOTSTRAP_TYPES = ['AppBootstrap', 'c0468XFPX1InLN14gtZ5PLf'];
|
||||
const GAME_TYPES = ['GameController'];
|
||||
|
||||
function readLevelDatabaseJson() {
|
||||
if (typeof Editor === 'undefined' || !Editor.Project?.path) return null;
|
||||
const dbPath = path.join(Editor.Project.path, 'assets', 'level-data', 'levels-database.json');
|
||||
if (!fs.existsSync(dbPath)) {
|
||||
console.warn('[game-controller-inspector] 未找到 assets/level-data/levels-database.json');
|
||||
return null;
|
||||
}
|
||||
try {
|
||||
return JSON.parse(fs.readFileSync(dbPath, 'utf8'));
|
||||
} catch (e) {
|
||||
console.warn('[game-controller-inspector] 解析关卡库失败', e);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
/** 编辑器 ▶ 预览:注入关卡库(不再打包进 resources bundle) */
|
||||
function installPreviewLevelDbHook() {
|
||||
if (typeof Editor === 'undefined' || !Editor.Message?.addBroadcastListener) return;
|
||||
Editor.Message.addBroadcastListener('scene:ready-for-preview', () => {
|
||||
const json = readLevelDatabaseJson();
|
||||
if (!json) return;
|
||||
Editor.Message.request('scene', 'execute-scene-script', {
|
||||
name: 'game-controller-inspector',
|
||||
method: 'apply',
|
||||
args: [json],
|
||||
}).catch((e) => {
|
||||
console.warn('[game-controller-inspector] 预览注入关卡库失败,请通过 scratch-gui 嵌入测试', e);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
exports.load = function load() {
|
||||
console.log('[game-controller-inspector] v3.4 — AppBootstrap 面板含游戏调试');
|
||||
installPreviewLevelDbHook();
|
||||
};
|
||||
|
||||
exports.unload = function unload() {
|
||||
console.log('[game-controller-inspector] 已卸载');
|
||||
};
|
||||
|
||||
async function callGameOnSelection(method, args) {
|
||||
const uuids = Editor.Selection.getSelected('node');
|
||||
if (!uuids || !uuids.length) {
|
||||
console.warn('[game-controller-inspector] 请先在层级管理器选中含 GameController 的节点');
|
||||
return;
|
||||
}
|
||||
await callOnNode(uuids[0], GAME_TYPES, method, args);
|
||||
}
|
||||
|
||||
exports.methods = {
|
||||
async switchLevelOnSelection() {
|
||||
const uuids = Editor.Selection.getSelected('node');
|
||||
if (!uuids || !uuids.length) {
|
||||
console.warn('[game-controller-inspector] 请先在层级管理器选中 AppRoot');
|
||||
return;
|
||||
}
|
||||
await callOnNode(uuids[0], BOOTSTRAP_TYPES, 'switchLevelFromBootstrap', []);
|
||||
},
|
||||
async debugMoveOnSelection() {
|
||||
await callGameOnSelection('debugMove', [1]);
|
||||
},
|
||||
async debugJumpOnSelection() {
|
||||
await callGameOnSelection('debugJump', []);
|
||||
},
|
||||
async debugPlayerInfoOnSelection() {
|
||||
await callGameOnSelection('debugPlayerInfo', []);
|
||||
},
|
||||
};
|
||||
10
extensions/game-controller-inspector/dist/scene-script.js
vendored
Normal file
10
extensions/game-controller-inspector/dist/scene-script.js
vendored
Normal file
@@ -0,0 +1,10 @@
|
||||
'use strict';
|
||||
|
||||
/** 编辑器 ▶ 预览:注入 data/levels-database.json(不打包进 resources) */
|
||||
exports.methods = {
|
||||
apply(json) {
|
||||
if (typeof window !== 'undefined' && json && typeof json === 'object') {
|
||||
window.__tfrhLevelsDatabaseJson = json;
|
||||
}
|
||||
},
|
||||
};
|
||||
@@ -1,16 +1,58 @@
|
||||
{
|
||||
"package_version": 2,
|
||||
"name": "game-controller-inspector",
|
||||
"version": "1.0.0",
|
||||
"description": "GameController Inspector 调试按钮(对齐 Unity TestGame2)",
|
||||
"version": "3.3.0",
|
||||
"description": "GameController 调试按钮 + AppBootstrap SwitchLevel",
|
||||
"author": "tfrh",
|
||||
"editor": ">=3.8.0",
|
||||
"main": "./dist/main.js",
|
||||
"scene-script": "./dist/scene-script.js",
|
||||
"contributions": {
|
||||
"inspector": {
|
||||
"section": {
|
||||
"footer": {
|
||||
"node": {
|
||||
"GameController": "./dist/inspector.js"
|
||||
"AppBootstrap": "./dist/footer.js",
|
||||
"c0468XFPX1InLN14gtZ5PLf": "./dist/footer.js",
|
||||
"GameController": "./dist/game-controller-footer.js",
|
||||
"8940aPSKJhGKKIBE/qKnFm7": "./dist/game-controller-footer.js"
|
||||
}
|
||||
}
|
||||
},
|
||||
"menu": [
|
||||
{
|
||||
"path": "扩展",
|
||||
"label": "SwitchLevel(当前选中 AppRoot)",
|
||||
"message": "switch-level"
|
||||
},
|
||||
{
|
||||
"path": "扩展/游戏调试",
|
||||
"label": "Player 前进 1 格",
|
||||
"message": "debug-move-fwd"
|
||||
},
|
||||
{
|
||||
"path": "扩展/游戏调试",
|
||||
"label": "Player 跳跃",
|
||||
"message": "debug-jump"
|
||||
},
|
||||
{
|
||||
"path": "扩展/游戏调试",
|
||||
"label": "Player 获取坐标",
|
||||
"message": "debug-player-info"
|
||||
}
|
||||
],
|
||||
"messages": {
|
||||
"switch-level": {
|
||||
"methods": ["switchLevelOnSelection"]
|
||||
},
|
||||
"debug-move-fwd": {
|
||||
"methods": ["debugMoveOnSelection"]
|
||||
},
|
||||
"debug-jump": {
|
||||
"methods": ["debugJumpOnSelection"]
|
||||
},
|
||||
"debug-player-info": {
|
||||
"methods": ["debugPlayerInfoOnSelection"]
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,83 +1,35 @@
|
||||
/**
|
||||
* GameController 自定义 Inspector(需启用扩展 game-controller-inspector)
|
||||
* 构建: 在扩展目录执行 npm run build,或在 Creator 扩展管理器中启用
|
||||
* GameController Inspector Footer — 关卡切换 + SwitchLevel
|
||||
*/
|
||||
|
||||
export const template = `
|
||||
<div class="game-controller-inspector">
|
||||
<ui-prop type="dump" prop="dump"></ui-prop>
|
||||
<ui-section header="关卡调试">
|
||||
<ui-input id="input-level" placeholder="inputLevel"></ui-input>
|
||||
<ui-button id="btn-switch">SwitchLevel</ui-button>
|
||||
<ui-button id="btn-end">EndInput</ui-button>
|
||||
</ui-section>
|
||||
<ui-section header="主题">
|
||||
<ui-input id="input-style" placeholder="inputStyle"></ui-input>
|
||||
<ui-button id="btn-style">ChangeStyle</ui-button>
|
||||
</ui-section>
|
||||
<ui-section header="多人">
|
||||
<ui-input id="input-coins" placeholder='coinStr JSON'></ui-input>
|
||||
<ui-button id="btn-mult">StartMultPlay</ui-button>
|
||||
</ui-section>
|
||||
<ui-section header="音频">
|
||||
<ui-button id="btn-mute">Mute</ui-button>
|
||||
<ui-button id="btn-unmute">Unmute</ui-button>
|
||||
</ui-section>
|
||||
<div class="gc-footer">
|
||||
<ui-label class="hint">预览 ▶ 后可用;inputLevel 填 ID 或点上一关/下一关</ui-label>
|
||||
<div class="row level-nav">
|
||||
<ui-button class="btn-prev">上一关</ui-button>
|
||||
<ui-button class="btn-next">下一关</ui-button>
|
||||
</div>
|
||||
<ui-button class="btn-switch">SwitchLevel</ui-button>
|
||||
</div>
|
||||
`;
|
||||
|
||||
export const style = `
|
||||
.gc-footer { margin-top: 6px; }
|
||||
.gc-footer .hint { opacity: 0.75; font-size: 11px; margin-bottom: 6px; display: block; }
|
||||
.gc-footer .row { display: flex; gap: 4px; margin-bottom: 6px; }
|
||||
.gc-footer .row ui-button { flex: 1; }
|
||||
.gc-footer .btn-switch { width: 100%; }
|
||||
`;
|
||||
|
||||
export const $ = {
|
||||
inputLevel: '#input-level',
|
||||
inputStyle: '#input-style',
|
||||
inputCoins: '#input-coins',
|
||||
btnSwitch: '#btn-switch',
|
||||
btnEnd: '#btn-end',
|
||||
btnStyle: '#btn-style',
|
||||
btnMult: '#btn-mult',
|
||||
btnMute: '#btn-mute',
|
||||
btnUnmute: '#btn-unmute',
|
||||
} as Record<string, string>;
|
||||
hint: '.hint',
|
||||
btnPrev: '.btn-prev',
|
||||
btnNext: '.btn-next',
|
||||
btnSwitch: '.btn-switch',
|
||||
};
|
||||
|
||||
type Dump = { value: Record<string, { value: unknown }> };
|
||||
|
||||
export function update(this: { dump: Dump; $: Record<string, HTMLElement> }, dump: Dump) {
|
||||
this.dump = dump;
|
||||
const v = dump.value;
|
||||
if (this.$.inputLevel && v.inputLevel) {
|
||||
(this.$.inputLevel as unknown as { value: string }).value = String(v.inputLevel.value ?? '1');
|
||||
}
|
||||
if (this.$.inputStyle && v.inputStyle) {
|
||||
(this.$.inputStyle as unknown as { value: string }).value = String(v.inputStyle.value ?? 'default');
|
||||
}
|
||||
if (this.$.inputCoins && v.coinStr) {
|
||||
(this.$.inputCoins as unknown as { value: string }).value = String(v.coinStr.value ?? '[]');
|
||||
}
|
||||
export function update(dump: unknown) {
|
||||
void dump;
|
||||
}
|
||||
|
||||
function callMethod(uuid: string, name: string, args: unknown[] = []) {
|
||||
// @ts-expect-error Editor global
|
||||
if (typeof Editor !== 'undefined' && Editor.Message) {
|
||||
// @ts-expect-error Editor API
|
||||
Editor.Message.request('scene', 'execute-component-method', { uuid, name, args });
|
||||
}
|
||||
}
|
||||
|
||||
export function ready(this: { dump: Dump; $: Record<string, HTMLElement> }) {
|
||||
const uuid = () => this.dump.value.uuid?.value as string;
|
||||
|
||||
this.$.btnSwitch?.addEventListener('confirm', () => {
|
||||
const id = parseInt((this.$.inputLevel as unknown as { value: string }).value || '1', 10);
|
||||
callMethod(uuid(), 'switchLevel', [id]);
|
||||
});
|
||||
this.$.btnEnd?.addEventListener('confirm', () => callMethod(uuid(), 'callSetIsInputEnd', [1]));
|
||||
this.$.btnStyle?.addEventListener('confirm', () => {
|
||||
const s = (this.$.inputStyle as unknown as { value: string }).value || 'default';
|
||||
callMethod(uuid(), 'changeUIStyle', [s]);
|
||||
});
|
||||
this.$.btnMult?.addEventListener('confirm', () => {
|
||||
const coins = (this.$.inputCoins as unknown as { value: string }).value || '[]';
|
||||
callMethod(uuid(), 'startMultPlay', ['PlayerA1', coins]);
|
||||
});
|
||||
this.$.btnMute?.addEventListener('confirm', () => callMethod(uuid(), 'callMute', []));
|
||||
this.$.btnUnmute?.addEventListener('confirm', () => callMethod(uuid(), 'callUnmute', []));
|
||||
}
|
||||
export function ready() {}
|
||||
|
||||
Reference in New Issue
Block a user