refactor(09-13): remove legacy fallback layer and de-wire index.ts

- delete fallback/{index,audio,ui,weather,load}.ts (A-7/A-1/A-4)

- index.ts: drop patchAll import/call and export * from './fallback'

- create() keeps createRender(); no new naming
This commit is contained in:
unanmed 2026-10-12 16:12:25 +08:00
parent 8819faa93b
commit 12bb67b5db
6 changed files with 0 additions and 254 deletions

View File

@ -1,71 +0,0 @@
import { Patch, PatchClass } from '@motajs/legacy-common';
import { mainSetting } from '@motajs/legacy-ui';
import { sleep } from '@motajs/common';
import { isNil } from 'lodash-es';
import { client } from '../core';
// todo: 添加弃用警告 logger.warn(56)
export function patchAudio() {
const patch = new Patch(PatchClass.Control);
const { bgmPlayer, soundPlayer, audioContext } = client;
const play = (bgm: BgmIds, when?: number) => {
bgmPlayer.play(bgm, when);
};
const pause = () => {
bgmPlayer.pause();
};
patch.add('playBgm', function (bgm, startTime) {
play(bgm, startTime);
});
patch.add('pauseBgm', function () {
pause();
});
patch.add('resumeBgm', function () {
bgmPlayer.resume();
});
patch.add('checkBgm', function () {
if (bgmPlayer.playing) return;
if (mainSetting.getValue('audio.bgmEnabled')) {
if (bgmPlayer.playingBGM) {
bgmPlayer.play(bgmPlayer.playingBGM);
} else {
play(main.startBgm, 0);
}
} else {
pause();
}
});
patch.add('triggerBgm', function () {
if (bgmPlayer.playing) bgmPlayer.pause();
else bgmPlayer.resume();
});
patch.add(
'playSound',
function (sound, _pitch, callback, position, orientation) {
const name = core.getMappedName(sound) as SoundIds;
const num = soundPlayer.play(name, position, orientation);
const route = audioContext.getRoute(`sounds.${num}`);
if (!route) {
callback?.();
return -1;
} else {
sleep(route.duration).then(() => callback?.());
return num;
}
}
);
patch.add('stopSound', function (id) {
if (isNil(id)) {
soundPlayer.stopAllSounds();
} else {
soundPlayer.stop(id);
}
});
patch.add('getPlayingSounds', function () {
return [...soundPlayer.playing];
});
}

View File

@ -1,9 +0,0 @@
import { patchAudio } from './audio';
import { patchWeather } from './weather';
import { patchUI } from './ui';
export function patchAll() {
patchAudio();
patchWeather();
patchUI();
}

View File

@ -1,137 +0,0 @@
import { ITexture } from '@motajs/render';
import {
IBlockIdentifier,
ITextureManager,
IIndexedIdentifier
} from '@user/client-base';
import { isNil } from 'lodash-es';
function extractClsBlocks<C extends Exclude<Cls, 'tileset'>>(
cls: C,
map: Record<string, number>,
icons: Record<string, number>
): IBlockIdentifier[] {
const max = Math.max(...Object.values(icons));
const arr = Array(max).fill(void 0);
for (const [key, value] of Object.entries(icons)) {
// 样板编辑器 bug 可能会导致多个 id 使用一个偏移,因此要判断下
if (!(key in map) || !isNil(arr[value])) continue;
const id = key as AllIdsOf<C>;
const num = map[id] as keyof NumberToId;
const identifier: IBlockIdentifier = {
id: id as string,
cls,
num
};
arr[value] = identifier;
}
return arr;
}
function addTileset(set: Set<number>, map?: readonly (readonly number[])[]) {
if (!map) return;
map.forEach(line => {
line.forEach(v => {
if (v >= 10000) set.add(v);
});
});
}
function addAutotile(set: Set<number>, map?: readonly (readonly number[])[]) {
if (!map) return;
map.forEach(line => {
line.forEach(v => {
const id = core.maps.blocksInfo[v as keyof NumberToId];
if (id?.cls === 'autotile') set.add(v);
});
});
}
/**
* 兼容旧版加载
*/
export function fallbackLoad(materials: ITextureManager) {
// 基本素材
const icons = core.icons.icons;
const images = core.material.images;
const idNumMap: Record<string, number> = {};
for (const [key, value] of Object.entries(core.maps.blocksInfo)) {
const num = Number(key);
idNumMap[value.id] = Number(num);
if (!isNil(value.animate)) {
materials.setDefaultFrame(num, value.animate - 1);
}
}
const terrains = extractClsBlocks('terrains', idNumMap, icons.terrains);
const animates = extractClsBlocks('animates', idNumMap, icons.animates);
const items = extractClsBlocks('items', idNumMap, icons.items);
const enemys = extractClsBlocks('enemys', idNumMap, icons.enemys);
const npcs = extractClsBlocks('npcs', idNumMap, icons.npcs);
const enemy48 = extractClsBlocks('enemy48', idNumMap, icons.enemy48);
const npc48 = extractClsBlocks('npc48', idNumMap, icons.npc48);
// Grid
materials.addGrid(images.terrains, terrains);
materials.addGrid(images.items, items);
// Row Animates
materials.addRowAnimate(images.animates, animates, 32);
materials.addRowAnimate(images.enemys, enemys, 32);
materials.addRowAnimate(images.npcs, npcs, 32);
materials.addRowAnimate(images.enemy48, enemy48, 48);
materials.addRowAnimate(images.npc48, npc48, 48);
// Autotile
for (const key of Object.keys(icons.autotile)) {
const id = key as AllIdsOf<'autotile'>;
const img = images.autotile[id];
const identifier: IBlockIdentifier = {
id,
num: idNumMap[id],
cls: 'autotile'
};
materials.addAutotile(img, identifier);
}
// Tilesets
core.tilesets.forEach((v, i) => {
const img = images.tilesets[v];
const identifier: IIndexedIdentifier = {
index: i,
alias: v
};
materials.addTileset(img, identifier);
});
// 地图上出现过的 tileset
const tilesetSet = new Set<number>();
const autotileSet = new Set<number>();
core.floorIds.forEach(v => {
const floor = core.floors[v];
addTileset(tilesetSet, floor.bgmap);
addTileset(tilesetSet, floor.bg2map);
addTileset(tilesetSet, floor.map);
addTileset(tilesetSet, floor.fgmap);
addTileset(tilesetSet, floor.fg2map);
addAutotile(autotileSet, floor.bgmap);
addAutotile(autotileSet, floor.bg2map);
addAutotile(autotileSet, floor.map);
addAutotile(autotileSet, floor.fgmap);
addAutotile(autotileSet, floor.fg2map);
});
const heroTextures: ITexture[] = [];
data_a1e2fb4a_e986_4524_b0da_9b7ba7c0874d.main.heroImages.forEach(v => {
const tex = materials.getImageByAlias(v);
if (tex) heroTextures.push(tex);
});
materials.buildAssets();
materials.cacheAutotileList(autotileSet);
materials.cacheTilesetList(tilesetSet);
materials.buildListToAsset(heroTextures);
}

View File

@ -1,11 +0,0 @@
import { Patch, PatchClass } from '@motajs/legacy-common';
import { TipStore } from '@user/client-base';
export function patchUI() {
const patch = new Patch(PatchClass.UI);
patch.add('drawTip', function (text, id) {
const tip = TipStore.get('main-tip');
tip?.drawTip(text, id);
});
}

View File

@ -1,23 +0,0 @@
import { Patch, PatchClass } from '@motajs/legacy-common';
import { WeatherController } from '../render/weather';
import { isNil } from 'lodash-es';
// todo: 添加弃用警告 logger.warn(56)
export function patchWeather() {
const patch = new Patch(PatchClass.Control);
let nowWeather: string = '';
let nowLevel: number = 0;
patch.add('setWeather', (type, level) => {
const weather = WeatherController.get('main');
if (!weather) return;
if (type === nowWeather && level === nowLevel) return;
weather.clearWeather();
if (!isNil(type)) {
weather.activate(type, level);
nowWeather = type;
nowLevel = level ?? 5;
}
});
}

View File

@ -1,13 +1,10 @@
import { patchAll } from './fallback';
import { createRender } from './render';
export function create() {
patchAll();
createRender();
}
export * from './action';
export * from './fallback';
export * from './render';
export * from './ui';