Compare commits

..

5 Commits

22 changed files with 127 additions and 92 deletions

View File

@ -2,12 +2,12 @@
`@motajs/client` 包含多个模块:
- [ClientBase](../motajs-client-base/)
- [`@motajs/client-base`](../motajs-client-base/)
示例:
```ts
import { ClientBase } from '@motajs/client';
import { KeyCode } from '@motajs/client';
const { ClientBase } = Mota.require('@motajs/client');
const { KeyCOde } = Mota.require('@motajs/client');
```

View File

@ -2,16 +2,16 @@
包含两个模块:
- [Action](../motajs-system-action/index.md)
- [UI](../motajs-system-ui/index.md)
- [`@motajs/system-action`](../motajs-system-action/index.md)
- [`@motajs/system-ui`](../motajs-system-ui/index.md)
## 引入示例
```ts
import { Action, UI } from '@motajs/system';
import { gameKey, UIController } from '@motajs/system';
Action.gameKey.register(...);
const myController = new UI.UIController('my-controller');
gameKey.register(...);
const myController = new UIController('my-controller');
```
等效于:

View File

@ -698,11 +698,11 @@ export class TextContentParser {
if (!param) {
// 参数为空或没有参数,视为标签结束
const color = this.fillStyleStack.pop();
if (this.resolved.length > 0) this.addTextRenderable();
if (!color) {
logger.warn(54, '\\r', pointer.toString());
return end;
}
if (this.resolved.length > 0) this.addTextRenderable();
this.status.fillStyle = color;
return end;
} else {
@ -719,11 +719,11 @@ export class TextContentParser {
if (!param) {
// 参数为空或没有参数,视为标签结束
const size = this.fontSizeStack.pop();
if (this.resolved.length > 0) this.addTextRenderable();
if (!size) {
logger.warn(54, '\\c', pointer.toString());
return end;
}
if (this.resolved.length > 0) this.addTextRenderable();
this.status.fontSize = size;
this.font = this.buildFont();
return end;
@ -742,11 +742,11 @@ export class TextContentParser {
if (!param) {
// 参数为空或没有参数,视为标签结束
const font = this.fontFamilyStack.pop();
if (this.resolved.length > 0) this.addTextRenderable();
if (!font) {
logger.warn(54, '\\g', pointer.toString());
return end;
}
if (this.resolved.length > 0) this.addTextRenderable();
this.status.fontFamily = font;
this.font = this.buildFont();
return end;
@ -990,7 +990,6 @@ export class TextContentParser {
data.splitLines.push(this.wordBreak[index]);
this.lineHeights.push(this.lineHeight);
this.lineWidths.push(this.lineWidth);
this.bsStart = index;
const text = data.text.slice(
this.wordBreak[index] + 1,
pointer + 1
@ -1002,10 +1001,11 @@ export class TextContentParser {
}
maxWidth = width;
const metrics = ctx.measureText(text);
if (metrics.width < maxWidth) {
if (metrics.width < maxWidth || index === this.bsStart) {
this.lastBreakIndex = index;
break;
}
this.bsStart = index;
}
this.lineWidth = 0;
this.lineStart = pointer;
@ -1092,7 +1092,6 @@ export class TextContentParser {
data.splitLines.push(this.wordBreak[index]);
this.lineHeights.push(this.lineHeight);
this.lineWidths.push(this.lineWidth);
this.bsStart = index;
const text = data.text.slice(this.wordBreak[index] + 1);
if (!isLast && text.length < guess / 4) {
// 如果剩余文字很少,几乎不可能会单独成一行时,直接结束循环
@ -1101,10 +1100,11 @@ export class TextContentParser {
}
const metrics = ctx.measureText(text);
maxWidth = width;
if (metrics.width < maxWidth) {
if (metrics.width < maxWidth || index === this.bsStart) {
this.lastBreakIndex = index;
break;
}
this.bsStart = index;
}
this.lineWidth = 0;
return true;

View File

@ -628,13 +628,13 @@ export class Layer extends Container<ELayerEvent> {
this.size(core._PX_, core._PY_);
this.staticMap.setHD(false);
// this.staticMap.setAntiAliasing(false);
this.staticMap.setAntiAliasing(false);
this.staticMap.size(core._PX_, core._PY_);
this.movingMap.setHD(false);
// this.movingMap.setAntiAliasing(false);
this.movingMap.setAntiAliasing(false);
this.movingMap.size(core._PX_, core._PY_);
this.backMap.setHD(false);
// this.backMap.setAntiAliasing(false);
this.backMap.setAntiAliasing(false);
this.backMap.size(core._PX_, core._PY_);
this.main.setAntiAliasing(false);
this.main.setHD(false);
@ -778,11 +778,11 @@ export class Layer extends Container<ELayerEvent> {
if (!data) return;
const frame = data.frame;
const temp = this.requireCanvas();
const temp = this.requireCanvas(true, false);
temp.setHD(false);
temp.setAntiAliasing(false);
for (let i = 0; i < frame; i++) {
const canvas = this.requireCanvas();
const canvas = this.requireCanvas(true, false);
const ctx = canvas.ctx;
const tempCtx = temp.ctx;
const [sx, sy, w, h] = data.render[i];
@ -1198,7 +1198,7 @@ export class Layer extends Container<ELayerEvent> {
const ex = Math.min(sx + blockSize, this.mapWidth);
const ey = Math.min(sy + blockSize, this.mapHeight);
const temp = this.requireCanvas();
const temp = this.requireCanvas(true, false);
temp.setAntiAliasing(false);
temp.setHD(false);
temp.size(core._PX_, core._PY_);

View File

@ -179,7 +179,7 @@ export class Winskin extends RenderItem<EWinskinEvent> {
}
private generatePattern() {
const pattern = this.requireCanvas();
const pattern = this.requireCanvas(true, false);
pattern.setScale(1);
const img = this.image;
pattern.size(32, 16);

View File

@ -1,6 +1,6 @@
import { backDir, has } from '@user/data-utils';
import { loading } from '@user/data-base';
import { LayerDoorAnimate } from '@user/client-modules';
import type { LayerDoorAnimate } from '@user/client-modules';
/**
*

View File

@ -1,5 +1,7 @@
import { createData } from '@user/entry-data';
import { create } from './create';
export function createGame() {
createData();
create();
}

View File

@ -4,12 +4,14 @@ import { patchAll } from '@user/data-fallback';
import { loading } from '@user/data-base';
import { Patch } from '@motajs/legacy-common';
createMota();
patchAll();
create();
export function createData() {
createMota();
patchAll();
create();
loading.once('coreInit', () => {
loading.once('coreInit', () => {
Patch.patchAll();
});
});
}
export * from './mota';

View File

@ -1,3 +1,7 @@
if (import.meta.env.DEV) {
import('./dev/hotReload');
}
export * from './boss';
export * from './chase';
export * from './fx';

View File

@ -5,10 +5,6 @@ import { createHook } from './hook';
import { initReplay } from './replay';
import { initUI } from './ui';
if (import.meta.env.DEV) {
import('./dev/hotReload');
}
export function create() {
initFallback();
loading.once('coreInit', () => {

View File

@ -1 +1 @@
export * as Base from '@motajs/client-base';
export * from '@motajs/client-base';

View File

@ -127,7 +127,7 @@ export class Logger {
const n = Math.floor(code / 50) + 1;
const n2 = code % 50;
const url = `${location.origin}/_docs/logger/error/error${n}.html#error-code-${n2}`;
console.error(`[ERROR Code ${code}] ${text}. See ${url}`);
console.error(`[ERROR Code ${code}] ${text} See ${url}`);
}
}

View File

@ -1,11 +1,12 @@
import { createDanmaku } from './danmaku';
import { createFixed } from './fixed';
import { createUI } from './ui';
import { createSetting, createUI } from './ui';
export function createPreset() {
createDanmaku();
createFixed();
createUI();
createSetting();
}
export * from './ui';

View File

@ -224,46 +224,6 @@ mainSetting
.register('tips', '小贴士', true, COM.Boolean)
);
const { loading } = Mota.require('@user/data-base');
loading.once('coreInit', () => {
mainSetting.reset({
'screen.fullscreen': !!document.fullscreenElement,
'screen.halo': !!storage.getValue('screen.showHalo', true),
'screen.itemDetail': !!storage.getValue('screen.itemDetail', true),
'screen.heroDetail': !!storage.getValue('screen.heroDetail', false),
'screen.transition': !!storage.getValue('screen.transition', false),
'screen.fontSize': storage.getValue(
'screen.fontSize',
isMobile ? 9 : 16
),
'screen.smoothView': !!storage.getValue('screen.smoothView', true),
'screen.criticalGem': !!storage.getValue('screen.criticalGem', false),
'screen.fontSizeStatus': storage.getValue('screen.fontSizeStatus', 100),
'action.fixed': !!storage.getValue('action.fixed', true),
'audio.bgmEnabled': !!storage.getValue('audio.bgmEnabled', true),
'audio.bgmVolume': storage.getValue('audio.bgmVolume', 80),
'audio.soundEnabled': !!storage.getValue('audio.soundEnabled', true),
'audio.soundVolume': storage.getValue('audio.soundVolume', 80),
'utils.betterLoad': !!storage.getValue('utils.betterLoad', true),
'utils.autoScale': !!storage.getValue('utils.autoScale', true),
'fx.paraLight': !!storage.getValue('fx.paraLight', true),
'fx.frag': !!storage.getValue('fx.frag', true),
'fx.portalParticle': !!storage.getValue('fx.portalParticle', true),
'ui.mapScale': storage.getValue(
'ui.mapScale',
isMobile ? 300 : Math.floor(window.innerWidth / 600) * 50
),
'ui.mapLazy': storage.getValue('ui.mapLazy', false),
'ui.bookScale': storage.getValue('ui.bookScale', isMobile ? 100 : 80),
'ui.danmaku': storage.getValue('ui.danmaku', true),
'ui.danmakuSpeed': storage.getValue(
'ui.danmakuSpeed',
Math.floor(window.innerWidth / 30) * 5
),
'ui.tips': storage.getValue('ui.tips', true)
});
});
interface SettingTextData {
[x: string]: string[] | SettingTextData;
}
@ -320,3 +280,57 @@ getSettingText(settingsText);
window.addEventListener('resize', () => {
setFontSize();
});
export function createSetting() {
const { loading } = Mota.require('@user/data-base');
loading.once('coreInit', () => {
mainSetting.reset({
'screen.fullscreen': !!document.fullscreenElement,
'screen.halo': !!storage.getValue('screen.showHalo', true),
'screen.itemDetail': !!storage.getValue('screen.itemDetail', true),
'screen.heroDetail': !!storage.getValue('screen.heroDetail', false),
'screen.transition': !!storage.getValue('screen.transition', false),
'screen.fontSize': storage.getValue(
'screen.fontSize',
isMobile ? 9 : 16
),
'screen.smoothView': !!storage.getValue('screen.smoothView', true),
'screen.criticalGem': !!storage.getValue(
'screen.criticalGem',
false
),
'screen.fontSizeStatus': storage.getValue(
'screen.fontSizeStatus',
100
),
'action.fixed': !!storage.getValue('action.fixed', true),
'audio.bgmEnabled': !!storage.getValue('audio.bgmEnabled', true),
'audio.bgmVolume': storage.getValue('audio.bgmVolume', 80),
'audio.soundEnabled': !!storage.getValue(
'audio.soundEnabled',
true
),
'audio.soundVolume': storage.getValue('audio.soundVolume', 80),
'utils.betterLoad': !!storage.getValue('utils.betterLoad', true),
'utils.autoScale': !!storage.getValue('utils.autoScale', true),
'fx.paraLight': !!storage.getValue('fx.paraLight', true),
'fx.frag': !!storage.getValue('fx.frag', true),
'fx.portalParticle': !!storage.getValue('fx.portalParticle', true),
'ui.mapScale': storage.getValue(
'ui.mapScale',
isMobile ? 300 : Math.floor(window.innerWidth / 600) * 50
),
'ui.mapLazy': storage.getValue('ui.mapLazy', false),
'ui.bookScale': storage.getValue(
'ui.bookScale',
isMobile ? 100 : 80
),
'ui.danmaku': storage.getValue('ui.danmaku', true),
'ui.danmakuSpeed': storage.getValue(
'ui.danmakuSpeed',
Math.floor(window.innerWidth / 30) * 5
),
'ui.tips': storage.getValue('ui.tips', true)
});
});
}

View File

@ -461,7 +461,11 @@ export abstract class RenderItem<E extends ERenderItemEvent = ERenderItemEvent>
*/
requireCanvas(alpha: boolean = true, autoScale: boolean = true) {
const canvas = new MotaOffscreenCanvas2D(alpha);
if (autoScale) {
canvas.setScale(this.scale);
} else {
canvas.setScale(1);
}
this.canvases.add(canvas);
this.canvasMap.set(canvas, { autoScale });
return canvas;

View File

@ -1,2 +1,2 @@
export * as Action from '@motajs/system-action';
export * as UI from '@motajs/system-ui';
export * from '@motajs/system-action';
export * from '@motajs/system-ui';

View File

@ -3250,7 +3250,7 @@ colour : this.dataColor
try {
var tempobj = JSON.parse(JsonEvalString_0);
} catch (e) {throw new Error("不合法的JSON格式");}
if (!tempobj.type) throw new Error("自定义事件需要一个type:xxx");
// if (!tempobj.type) throw new Error("自定义事件需要一个type:xxx");
var code = JSON.stringify(tempobj) +',\n';
return code;
*/;
@ -3517,7 +3517,7 @@ isShopVisited_e
/* isShopVisited_e
default : ['shop1']
allShops : ['IdString_0']
var code = 'Mota.require('@user/legacy-plugin-data').isShopVisited(\'' + IdString_0 + '\')';
var code = 'Mota.require("@user/legacy-plugin-data").isShopVisited(\'' + IdString_0 + '\')';
return [code, Blockly.JavaScript.ORDER_ATOMIC];
*/;

View File

@ -360,7 +360,7 @@ core.prototype._loadGameProcess = async function () {
if (main.pluginUseCompress) {
await main.loadScript(`project/processG.min.js`);
} else {
await main.loadScript(`src/game/index.esm.ts`, true);
await main.loadScript(`src/editor.esm.ts`, true);
}
}
}

View File

@ -47,7 +47,6 @@ main.floors.MT0=
"他从石头的缝隙中看去,看到满山的枫叶在秋风中摇曳,仿佛在提醒他时间的流逝。",
"这些自然的变迁,虽然无情,却也教会了他如何适应和生存。",
"\t[原始人]今天的天气似乎不错,那就上山看看吧。",
"\r[red]注意!!!\r[]该塔新增了很多新的功能同时对样板的ui进行了大幅度的改动操作也有改变由于内容过多这里不再一一描述具体请在道具栏查看百科全书百科全书是在你面前的几个道具中的其中一个",
{
"type": "function",
"function": "function(){\nif (!core.isReplaying()) Mota.require('@motajs/legacy-ui').fixedUi.open('chapter', { chapter: '序章 起源' });\n}"
@ -122,11 +121,7 @@ main.floors.MT0=
"autoEvent": {},
"bgm": "cave.opus",
"beforeBattle": {},
"bg2map": [
],
"fg2map": [
],
"bg2map": [],
"fg2map": [],
"cannotMoveIn": {}
}

View File

@ -17,6 +17,7 @@ import { WebSocket, WebSocketServer } from 'ws';
import chokidar from 'chokidar';
import commonjs from '@rollup/plugin-commonjs';
import json from '@rollup/plugin-json';
import replace from '@rollup/plugin-replace';
const base = './public';
@ -150,10 +151,23 @@ async function getEsmFile(
exclude: '**/node_modules/**'
},
plugins: [
typescript({ sourceMap: true }),
nodeResolve(),
typescript({
sourceMap: true,
noCheck: true,
paths: {
'@motajs/*': ['packages/*/src'],
'@user/*': ['packages-user/*/src']
}
}),
nodeResolve({
browser: true,
preferBuiltins: false
}),
commonjs(),
json()
json(),
replace({
'import.meta.env.DEV': 'false'
})
],
onwarn() {}
});

3
src/editor.ts Normal file
View File

@ -0,0 +1,3 @@
import { createData } from '@user/entry-data';
createData();