diff --git a/packages-user/client-modules/src/fallback/audio.ts b/packages-user/client-modules/src/fallback/audio.ts deleted file mode 100644 index 7ba0fd9..0000000 --- a/packages-user/client-modules/src/fallback/audio.ts +++ /dev/null @@ -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]; - }); -} diff --git a/packages-user/client-modules/src/fallback/index.ts b/packages-user/client-modules/src/fallback/index.ts deleted file mode 100644 index 36ce4bf..0000000 --- a/packages-user/client-modules/src/fallback/index.ts +++ /dev/null @@ -1,9 +0,0 @@ -import { patchAudio } from './audio'; -import { patchWeather } from './weather'; -import { patchUI } from './ui'; - -export function patchAll() { - patchAudio(); - patchWeather(); - patchUI(); -} diff --git a/packages-user/client-modules/src/fallback/load.ts b/packages-user/client-modules/src/fallback/load.ts deleted file mode 100644 index 37a74bb..0000000 --- a/packages-user/client-modules/src/fallback/load.ts +++ /dev/null @@ -1,137 +0,0 @@ -import { ITexture } from '@motajs/render'; -import { - IBlockIdentifier, - ITextureManager, - IIndexedIdentifier -} from '@user/client-base'; -import { isNil } from 'lodash-es'; - -function extractClsBlocks>( - cls: C, - map: Record, - icons: Record -): 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; - 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, map?: readonly (readonly number[])[]) { - if (!map) return; - map.forEach(line => { - line.forEach(v => { - if (v >= 10000) set.add(v); - }); - }); -} - -function addAutotile(set: Set, 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 = {}; - - 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(); - const autotileSet = new Set(); - 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); -} diff --git a/packages-user/client-modules/src/fallback/ui.ts b/packages-user/client-modules/src/fallback/ui.ts deleted file mode 100644 index ab0ee29..0000000 --- a/packages-user/client-modules/src/fallback/ui.ts +++ /dev/null @@ -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); - }); -} diff --git a/packages-user/client-modules/src/fallback/weather.ts b/packages-user/client-modules/src/fallback/weather.ts deleted file mode 100644 index 0003f5b..0000000 --- a/packages-user/client-modules/src/fallback/weather.ts +++ /dev/null @@ -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; - } - }); -} diff --git a/packages-user/client-modules/src/index.ts b/packages-user/client-modules/src/index.ts index 0e0ce00..745bed0 100644 --- a/packages-user/client-modules/src/index.ts +++ b/packages-user/client-modules/src/index.ts @@ -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';