mirror of
https://github.com/motajs/template.git
synced 2026-10-11 23:20:21 +08:00
refactor(09-04): clean up main.tsx after status ownership migration
- remove replayStatus/leftStatus/rightStatus defs, updateStatus, updateDataFallback
- remove dead write-only locked ref and attributeHook + its onUnmounted
- drop status={...} props on LeftStatusBar/RightStatusBar
- hideStatus now reads flag default once at setup + // TODO: (flags has no listen system)
- preserve hideStatus consumers, map render, interaction handlers, mainUIController, MainSceneUI
- drop now-unused imports (onUnmounted/reactive/ILeftHeroStatus/IRightHeroStatus/ReplayingStatus)
This commit is contained in:
parent
61b618e533
commit
458135037c
@ -5,7 +5,7 @@ import {
|
|||||||
CustomRenderItem
|
CustomRenderItem
|
||||||
} from '@motajs/render';
|
} from '@motajs/render';
|
||||||
// import { WeatherController } from '../weather';
|
// import { WeatherController } from '../weather';
|
||||||
import { defineComponent, onUnmounted, reactive, ref } from 'vue';
|
import { defineComponent, ref } from 'vue';
|
||||||
import { Textbox, TextboxProps, Tip } from '@user/client-base';
|
import { Textbox, TextboxProps, Tip } from '@user/client-base';
|
||||||
import { GameUI, SetupComponentOptions } from '@motajs/system';
|
import { GameUI, SetupComponentOptions } from '@motajs/system';
|
||||||
import {
|
import {
|
||||||
@ -18,13 +18,7 @@ import {
|
|||||||
STATUS_BAR_HEIGHT,
|
STATUS_BAR_HEIGHT,
|
||||||
STATUS_BAR_WIDTH
|
STATUS_BAR_WIDTH
|
||||||
} from '../shared';
|
} from '../shared';
|
||||||
import {
|
import { LeftStatusBar, RightStatusBar } from './statusBar';
|
||||||
ILeftHeroStatus,
|
|
||||||
IRightHeroStatus,
|
|
||||||
LeftStatusBar,
|
|
||||||
RightStatusBar
|
|
||||||
} from './statusBar';
|
|
||||||
import { ReplayingStatus } from './toolbar';
|
|
||||||
import { state } from '@user/data-state';
|
import { state } from '@user/data-state';
|
||||||
import { mainUIController } from './controller';
|
import { mainUIController } from './controller';
|
||||||
import { isNil } from 'lodash-es';
|
import { isNil } from 'lodash-es';
|
||||||
@ -58,110 +52,13 @@ const MainScene = defineComponent<MainSceneProps>(props => {
|
|||||||
width: MAP_WIDTH
|
width: MAP_WIDTH
|
||||||
};
|
};
|
||||||
|
|
||||||
const hideStatus = ref(false);
|
const hideStatus = ref(
|
||||||
const locked = ref(false);
|
p.state.flags.getFieldValueDefaults('hideStatusBar', false)
|
||||||
|
);
|
||||||
|
// TODO: flags 更新未接(当前无监听系统)
|
||||||
// const weather = new WeatherController();
|
// const weather = new WeatherController();
|
||||||
// weather.extern('main');
|
// weather.extern('main');
|
||||||
|
|
||||||
const replayStatus: ReplayingStatus = reactive({
|
|
||||||
replaying: false,
|
|
||||||
playing: false,
|
|
||||||
speed: 1,
|
|
||||||
played: 0,
|
|
||||||
total: 0
|
|
||||||
});
|
|
||||||
const leftStatus: ILeftHeroStatus = reactive({
|
|
||||||
hp: 0,
|
|
||||||
hpmax: 0,
|
|
||||||
mana: 0,
|
|
||||||
manamax: 0,
|
|
||||||
atk: 0,
|
|
||||||
def: 0,
|
|
||||||
mdef: 0,
|
|
||||||
money: 0,
|
|
||||||
exp: 0,
|
|
||||||
up: 0,
|
|
||||||
yellowKey: 0,
|
|
||||||
blueKey: 0,
|
|
||||||
redKey: 0,
|
|
||||||
greenKey: 0,
|
|
||||||
pickaxe: 0,
|
|
||||||
bomb: 0,
|
|
||||||
centerFly: 0,
|
|
||||||
poison: false,
|
|
||||||
weak: false,
|
|
||||||
curse: false,
|
|
||||||
floor: 'MT0',
|
|
||||||
lv: '',
|
|
||||||
replay: replayStatus
|
|
||||||
});
|
|
||||||
const rightStatus: IRightHeroStatus = reactive({
|
|
||||||
exampleHard: 0
|
|
||||||
});
|
|
||||||
|
|
||||||
//#region 状态更新
|
|
||||||
const updateStatus = () => {
|
|
||||||
if (!core.status || !core.status.hero || !core.status.floorId) return;
|
|
||||||
// TODO: flags 更新未接(当前无监听系统)
|
|
||||||
const flags = props.state.flags;
|
|
||||||
hideStatus.value = flags.getFieldValueDefaults('hideStatusBar', false);
|
|
||||||
|
|
||||||
const hero = core.status.hero;
|
|
||||||
leftStatus.atk = props.state.hero.attribute.getFinalAttribute('atk');
|
|
||||||
leftStatus.hp = props.state.hero.attribute.getFinalAttribute('hp');
|
|
||||||
leftStatus.hpmax =
|
|
||||||
props.state.hero.attribute.getFinalAttribute('hpmax');
|
|
||||||
leftStatus.mana = props.state.hero.attribute.getFinalAttribute('mana');
|
|
||||||
leftStatus.manamax =
|
|
||||||
props.state.hero.attribute.getFinalAttribute('manamax');
|
|
||||||
leftStatus.def = props.state.hero.attribute.getFinalAttribute('def');
|
|
||||||
leftStatus.mdef = props.state.hero.attribute.getFinalAttribute('mdef');
|
|
||||||
leftStatus.money =
|
|
||||||
props.state.hero.attribute.getFinalAttribute('money');
|
|
||||||
leftStatus.exp = props.state.hero.attribute.getFinalAttribute('exp');
|
|
||||||
leftStatus.up = core.getNextLvUpNeed() ?? 0;
|
|
||||||
leftStatus.yellowKey = core.itemCount('yellowKey');
|
|
||||||
leftStatus.blueKey = core.itemCount('blueKey');
|
|
||||||
leftStatus.redKey = core.itemCount('redKey');
|
|
||||||
leftStatus.greenKey = core.itemCount('greenKey');
|
|
||||||
leftStatus.pickaxe = core.itemCount('pickaxe');
|
|
||||||
leftStatus.bomb = core.itemCount('bomb');
|
|
||||||
leftStatus.centerFly = core.itemCount('centerFly');
|
|
||||||
// TODO: flags 更新未接(当前无监听系统)
|
|
||||||
leftStatus.poison = flags.getFieldValueDefaults('poison', true);
|
|
||||||
leftStatus.weak = flags.getFieldValueDefaults('weak', true);
|
|
||||||
leftStatus.curse = flags.getFieldValueDefaults('curse', true);
|
|
||||||
leftStatus.floor = core.status.floorId;
|
|
||||||
leftStatus.lv = core.getLvName(hero.lv);
|
|
||||||
|
|
||||||
const { pausing, speed, toReplay, totalList } = core.status.replay;
|
|
||||||
replayStatus.replaying = core.isReplaying();
|
|
||||||
replayStatus.playing = !pausing;
|
|
||||||
replayStatus.speed = speed;
|
|
||||||
replayStatus.played = totalList.length - toReplay.length;
|
|
||||||
replayStatus.total = totalList.length;
|
|
||||||
|
|
||||||
// TODO: flags 更新未接(当前无监听系统)
|
|
||||||
rightStatus.exampleHard = flags.getFieldValueDefaults('hard', 0);
|
|
||||||
};
|
|
||||||
|
|
||||||
const updateDataFallback = () => {
|
|
||||||
// 更新 locked 状态
|
|
||||||
locked.value = core.status.lockControl;
|
|
||||||
};
|
|
||||||
|
|
||||||
// 监听状态栏更新事件
|
|
||||||
const attributeHook = props.state.hero.attribute.addHook({
|
|
||||||
onUpdateAttribute: () => {
|
|
||||||
updateStatus();
|
|
||||||
updateDataFallback();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
onUnmounted(() => {
|
|
||||||
attributeHook.unload();
|
|
||||||
});
|
|
||||||
|
|
||||||
//#region sprite 渲染
|
//#region sprite 渲染
|
||||||
|
|
||||||
let lastLength = 0;
|
let lastLength = 0;
|
||||||
@ -240,7 +137,6 @@ const MainScene = defineComponent<MainSceneProps>(props => {
|
|||||||
>
|
>
|
||||||
<LeftStatusBar
|
<LeftStatusBar
|
||||||
loc={[0, 0, STATUS_BAR_WIDTH, STATUS_BAR_HEIGHT]}
|
loc={[0, 0, STATUS_BAR_WIDTH, STATUS_BAR_HEIGHT]}
|
||||||
status={leftStatus}
|
|
||||||
hidden={hideStatus.value}
|
hidden={hideStatus.value}
|
||||||
state={props.state}
|
state={props.state}
|
||||||
></LeftStatusBar>
|
></LeftStatusBar>
|
||||||
@ -287,7 +183,6 @@ const MainScene = defineComponent<MainSceneProps>(props => {
|
|||||||
/>
|
/>
|
||||||
<RightStatusBar
|
<RightStatusBar
|
||||||
loc={[RIGHT_STATUS_POS, 0, STATUS_BAR_WIDTH, STATUS_BAR_HEIGHT]}
|
loc={[RIGHT_STATUS_POS, 0, STATUS_BAR_WIDTH, STATUS_BAR_HEIGHT]}
|
||||||
status={rightStatus}
|
|
||||||
hidden={hideStatus.value && ENABLE_RIGHT_STATUS_BAR}
|
hidden={hideStatus.value && ENABLE_RIGHT_STATUS_BAR}
|
||||||
state={props.state}
|
state={props.state}
|
||||||
></RightStatusBar>
|
></RightStatusBar>
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user