From 646f9e3ab087198ae2ebe950bd0e4d9d3e1d6d47 Mon Sep 17 00:00:00 2001 From: unanmed <1319491857@qq.com> Date: Sun, 4 Feb 2024 19:28:09 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E5=BC=80=E5=A7=8B=E7=95=8C=E9=9D=A2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- public/libs/control.js | 11 +- public/libs/core.js | 1 + public/libs/loader.js | 46 ++--- public/main.js | 2 +- public/project/data.js | 2 +- src/core/index.ts | 19 -- src/core/main/init/ui.ts | 16 +- src/game/system.ts | 19 +- src/plugin/game/utils.ts | 5 +- src/ui/start.vue | 408 ++++++++++++--------------------------- 10 files changed, 169 insertions(+), 360 deletions(-) diff --git a/public/libs/control.js b/public/libs/control.js index d0a7cd6..2cb62f5 100644 --- a/public/libs/control.js +++ b/public/libs/control.js @@ -3400,13 +3400,10 @@ control.prototype.checkBgm = function () { }; ///// 设置屏幕放缩 ////// -control.prototype.setDisplayScale = function (delta) { - var index = core.domStyle.availableScale.indexOf(core.domStyle.scale); - if (index < 0) return; - index = - (index + delta + core.domStyle.availableScale.length) % - core.domStyle.availableScale.length; - core.domStyle.scale = core.domStyle.availableScale[index]; +control.prototype.setDisplayScale = function (i) { + const scale = core.domStyle.availableScale[i]; + if (!scale) return; + core.domStyle.scale = scale; core.setLocalStorage('scale', core.domStyle.scale); core.resize(); }; diff --git a/public/libs/core.js b/public/libs/core.js index ad429a1..9119ca6 100644 --- a/public/libs/core.js +++ b/public/libs/core.js @@ -602,6 +602,7 @@ core.prototype._afterLoadResources = function (callback) { // if (core.plugin._afterLoadResources) core.plugin._afterLoadResources(); core.showStartAnimate(); + Mota.require('var', 'hook').emit('load'); if (callback) callback(); }; diff --git a/public/libs/loader.js b/public/libs/loader.js index fab081d..2975832 100644 --- a/public/libs/loader.js +++ b/public/libs/loader.js @@ -1,9 +1,4 @@ /// - -/* -loader.js:负责对资源的加载 - - */ 'use strict'; function loader() { @@ -32,7 +27,6 @@ loader.prototype._load = function (callback) { loader.prototype._load_sync = function (callback) { this._loadAnimates_sync(); - if (main.mode === 'play') return callback(); this._loadMusic_sync(); core.loader._loadMaterials_sync(function () { core.loader._loadExtraImages_sync(function () { @@ -116,7 +110,6 @@ loader.prototype._load_async = function (callback) { // ----- 加载资源文件 ------ // loader.prototype._loadMaterials_sync = function (callback) { - if (main.mode === 'play') return callback(); this._setStartLoadTipText('正在加载资源文件...'); this.loadImages( 'materials', @@ -156,7 +149,6 @@ loader.prototype._loadMaterials_afterLoad = function () { // ------ 加载使用的图片 ------ // loader.prototype._loadExtraImages_sync = function (callback) { - if (main.mode === 'play') return callback(); core.material.images.images = {}; this._setStartLoadTipText('正在加载图片文件...'); core.loadImages( @@ -199,7 +191,6 @@ loader.prototype._loadExtraImages_async = function (onprogress, onfinished) { // ------ 加载自动元件 ------ // loader.prototype._loadAutotiles_sync = function (callback) { - if (main.mode === 'play') return callback(); core.material.images.autotile = {}; var keys = Object.keys(core.material.icons.autotile); var autotiles = {}; @@ -229,7 +220,6 @@ loader.prototype._loadAutotiles_async = function (onprogress, onfinished) { }; loader.prototype._loadAutotiles_afterLoad = function (keys, autotiles) { - if (main.mode === 'play') return; // autotile需要保证顺序 keys.forEach(function (v) { core.material.images.autotile[v] = autotiles[v]; @@ -243,7 +233,6 @@ loader.prototype._loadAutotiles_afterLoad = function (keys, autotiles) { // ------ 加载额外素材 ------ // loader.prototype._loadTilesets_sync = function (callback) { - if (main.mode === 'play') return callback(); core.material.images.tilesets = {}; this._setStartLoadTipText('正在加载额外素材...'); this.loadImages( @@ -251,6 +240,7 @@ loader.prototype._loadTilesets_sync = function (callback) { core.tilesets, core.material.images.tilesets, function () { + core.loader._loadTilesets_afterLoad(); callback(); } ); @@ -264,15 +254,28 @@ loader.prototype._loadTilesets_async = function (onprogress, onfinished) { core.material.images.tilesets, onprogress, function () { + core.loader._loadTilesets_afterLoad(); onfinished(); } ); }; +loader.prototype._loadTilesets_afterLoad = function () { + // 检查宽高是32倍数,如果出错在控制台报错 + for (var imgName in core.material.images.tilesets) { + var img = core.material.images.tilesets[imgName]; + if (img.width % 32 != 0 || img.height % 32 != 0) { + console.warn('警告!' + imgName + '的宽或高不是32的倍数!'); + } + if (img.width * img.height > 32 * 32 * 3000) { + console.warn('警告!' + imgName + '上的图块素材个数大于3000!'); + } + } +}; + // ------ 实际加载一系列图片 ------ // loader.prototype.loadImages = function (dir, names, toSave, callback) { - if (main.mode === 'play') return callback(); if (!names || names.length == 0) { if (callback) callback(); return; @@ -310,9 +313,7 @@ loader.prototype.loadImage = function (dir, imgName, callback) { }; image.src = 'project/' + dir + '/' + name + '?v=' + main.version; if (name.endsWith('.gif')) callback(imgName, null); - } catch (e) { - console.error(e); - } + } catch (e) {} }; // ------ 从zip中加载一系列图片 ------ // @@ -363,14 +364,13 @@ loader.prototype.loadImagesFromZip = function ( // ------ 加载动画文件 ------ // loader.prototype._loadAnimates_sync = function () { - if (main.mode === 'play') return; this._setStartLoadTipText('正在加载动画文件...'); if (main.supportBunch) { if (core.animates.length > 0) { core.http( 'GET', - '/all/__all_animates__?v=' + + '__all_animates__?v=' + main.version + '&id=' + core.animates.join(','), @@ -403,7 +403,6 @@ loader.prototype._loadAnimates_sync = function () { core.material.animates[t] = core.loader._loadAnimate(content); }, function (e) { - console.error(e); core.material.animates[t] = null; }, 'text/plain; charset=x-user-defined' @@ -449,7 +448,6 @@ loader.prototype._loadAnimate = function (content) { image.src = t2; data.images.push(image); } catch (e) { - console.error(e); data.images.push(null); } } @@ -473,7 +471,6 @@ loader.prototype._loadAnimate = function (content) { }); return data; } catch (e) { - console.error(e); return null; } }; @@ -524,20 +521,19 @@ loader.prototype.loadOneMusic = function (name) { if (main.bgmRemote) music.src = main.bgmRemoteRoot + core.firstData.name + '/' + name; else music.src = 'project/bgms/' + name; - music.loop = 'loop'; - core.material.bgms[name] = music; + Mota.require('var', 'bgm').add(`bgms.${name}`, music); }; loader.prototype.loadOneSound = function (name) { + const sound = Mota.require('var', 'sound'); core.http( 'GET', 'project/sounds/' + name + '?v=' + main.version, null, function (data) { - core.loader._loadOneSound_decodeData(name, data); + sound.add(`sounds.${name}`, data); }, function (e) { - console.error(e); core.material.sounds[name] = null; }, null, @@ -562,12 +558,10 @@ loader.prototype._loadOneSound_decodeData = function (name, data) { core.material.sounds[name] = buffer; }, function (e) { - console.error(e); core.material.sounds[name] = null; } ); } catch (e) { - console.error(e); core.material.sounds[name] = null; } }; diff --git a/public/main.js b/public/main.js index 0758cc0..7a91181 100644 --- a/public/main.js +++ b/public/main.js @@ -411,7 +411,7 @@ main.prototype.loadAsync = async function (mode, callback) { main.core = core; // 自动放缩最大化 - let auto = Mota.require('var', 'mainSetting').getValue('autoSclae'); + let auto = Mota.require('var', 'mainSetting').getValue('autoScale', true); if (auto && !core.domStyle.isVertical) { try { diff --git a/public/project/data.js b/public/project/data.js index 2c05ea6..c228ab5 100644 --- a/public/project/data.js +++ b/public/project/data.js @@ -313,7 +313,7 @@ var data_a1e2fb4a_e986_4524_b0da_9b7ba7c0874d = "splitImages": [] }, "firstData": { - "title": "人类:开天辟地", + "title": "魔塔样板", "name": "HumanBreak", "version": "Ver 2.7.3.1", "floorId": "MT0", diff --git a/src/core/index.ts b/src/core/index.ts index bc376e7..a4a9ed2 100644 --- a/src/core/index.ts +++ b/src/core/index.ts @@ -1,13 +1,5 @@ import { BgmController, bgm } from './audio/bgm'; import { SoundController, SoundEffect, sound } from './audio/sound'; -import { readyAllResource } from './loader/load'; -import { - Resource, - ResourceStore, - ZippedResource, - resource, - zipResource -} from './loader/resource'; import { Focus, GameUi, UiController } from './main/custom/ui'; import { GameStorage } from './main/storage'; import './main/init/'; @@ -30,10 +22,6 @@ import { Hotkey } from './main/custom/hotkey'; import { Keyboard } from './main/custom/keyboard'; import './main/layout'; -function ready() { - readyAllResource(); -} - // ----- 类注册 Mota.register('class', 'AudioPlayer', AudioPlayer); Mota.register('class', 'BgmController', BgmController); @@ -44,13 +32,10 @@ Mota.register('class', 'GameUi', GameUi); Mota.register('class', 'Hotkey', Hotkey); Mota.register('class', 'Keyboard', Keyboard); Mota.register('class', 'MotaSetting', MotaSetting); -Mota.register('class', 'Resource', Resource); -Mota.register('class', 'ResourceStore', ResourceStore); Mota.register('class', 'SettingDisplayer', SettingDisplayer); Mota.register('class', 'SoundController', SoundController); Mota.register('class', 'SoundEffect', SoundEffect); Mota.register('class', 'UiController', UiController); -Mota.register('class', 'ZippedResource', ZippedResource); // ----- 函数注册 // ----- 变量注册 @@ -61,11 +46,7 @@ Mota.register('var', 'sound', sound); Mota.register('var', 'gameKey', gameKey); Mota.register('var', 'mainSetting', mainSetting); Mota.register('var', 'KeyCode', KeyCode); -Mota.register('var', 'resource', resource); -Mota.register('var', 'zipResource', zipResource); Mota.register('var', 'settingStorage', settingStorage); Mota.register('var', 'status', status); // ----- 模块注册 - -ready(); diff --git a/src/core/main/init/ui.ts b/src/core/main/init/ui.ts index 170a287..21a8987 100644 --- a/src/core/main/init/ui.ts +++ b/src/core/main/init/ui.ts @@ -35,6 +35,9 @@ fixedUi.register( ); fixedUi.showAll(); +let loaded = false; +let mounted = false; + const hook = Mota.require('var', 'hook'); hook.once('mounted', () => { const ui = document.getElementById('ui-main')!; @@ -57,6 +60,15 @@ hook.once('mounted', () => { fixed.style.display = 'none'; }); - // todo: 暂时先这么搞,之后重写加载界面,需要改成先显示加载界面,加载完毕后再打开这个界面 - fixedUi.open('start'); + if (loaded && !mounted) { + fixedUi.open('start'); + } + mounted = true; +}); +hook.once('load', () => { + if (mounted) { + // todo: 暂时先这么搞,之后重写加载界面,需要改成先显示加载界面,加载完毕后再打开这个界面 + fixedUi.open('start'); + } + loaded = true; }); diff --git a/src/game/system.ts b/src/game/system.ts index 81e5526..b6a1acd 100644 --- a/src/game/system.ts +++ b/src/game/system.ts @@ -7,22 +7,12 @@ import type { IndexedEventEmitter } from '@/core/common/eventEmitter'; import type { loading } from './game'; -import type { - Resource, - ResourceStore, - ResourceType, - ZippedResource -} from '@/core/loader/resource'; import type { Hotkey } from '@/core/main/custom/hotkey'; import type { Keyboard } from '@/core/main/custom/keyboard'; import type { CustomToolbar } from '@/core/main/custom/toolbar'; import type { Focus, GameUi, UiController } from '@/core/main/custom/ui'; import type { gameListener, hook } from './game'; -import type { - MotaSetting, - SettingDisplayer, - SettingStorage -} from '@/core/main/setting'; +import type { MotaSetting, SettingDisplayer } from '@/core/main/setting'; import type { GameStorage } from '@/core/main/storage'; import type { DamageEnemy, EnemyCollection } from './enemy/damage'; import type { specials } from './enemy/special'; @@ -41,9 +31,6 @@ interface ClassInterface { GameStorage: typeof GameStorage; MotaSetting: typeof MotaSetting; SettingDisplayer: typeof SettingDisplayer; - Resource: typeof Resource; - ZippedResource: typeof ZippedResource; - ResourceStore: typeof ResourceStore; Focus: typeof Focus; GameUi: typeof GameUi; UiController: typeof UiController; @@ -85,9 +72,7 @@ interface VariableInterface { // isMobile: boolean; bgm: BgmController; sound: SoundController; - resource: ResourceStore>; - zipResource: ResourceStore<'zip'>; - settingStorage: GameStorage; + settingStorage: GameStorage; status: Ref; // 定义于游戏进程,渲染进程依然可用 haloSpecials: number[]; diff --git a/src/plugin/game/utils.ts b/src/plugin/game/utils.ts index e279f00..6a0d4bd 100644 --- a/src/plugin/game/utils.ts +++ b/src/plugin/game/utils.ts @@ -31,10 +31,7 @@ export function has(v: T): v is NonNullable { } export function maxGameScale(n: number = 0) { - const index = core.domStyle.availableScale.indexOf(core.domStyle.scale); - core.control.setDisplayScale( - core.domStyle.availableScale.length - 1 - index - n - ); + core.control.setDisplayScale(core.domStyle.availableScale.length - 1 - n); if (!core.isPlaying() && core.flags.enableHDCanvas) { // @ts-ignore core.domStyle.ratio = Math.max( diff --git a/src/ui/start.vue b/src/ui/start.vue index 5b5f40f..e5c0570 100644 --- a/src/ui/start.vue +++ b/src/ui/start.vue @@ -3,7 +3,7 @@
-
人类:开天辟地
+
{{ name }}
-
+ +
+
+ + +
@@ -56,21 +92,18 @@