|
楼主 |
发表于 2021-10-24 03:50:47
|
显示全部楼层
然后是针对mud的基础类
- (function (app) {
- let state = Include("include/state.js")
- let BasicState=function(){
- state.call(this)
- }
- BasicState.prototype = Object.create(state.prototype)
- BasicState.prototype.OnEvent=function(context,event,data){
- }
- return BasicState
- })(App)
复制代码
https://github.com/hellclient-sc ... state/basicstate.js
这个负责默认的事件处理,用于被所有实际的状态触发
- (function (app) {
- let statecontext = Include("include/statecontext.js")
- let GlobalStateContext=function(){
- statecontext.call(this)
- }
- GlobalStateContext.prototype = Object.create(statecontext.prototype)
- GlobalStateContext.prototype.ChangeState=function(newstatue){
- app.Data.State=newstatue.ID
- statecontext.prototype.ChangeState.call(this,newstatue)
- app.UpdateState()
- }
- return GlobalStateContext
- })(App)
复制代码
https://github.com/hellclient-sc ... obalstatecontext.js
这是一个全局(用户控制的惧色)状态,并和实际的App.Data做交互
然后是全局的管理和注册状态的代码
- (function(app){
- let globalstatecontext=Include("core/state/globalstatecontext.js")
- app.Data.State=""
- app.States={}
- app.StateContext=new globalstatecontext()
- app.RegisterState=function(state){
- if (state.ID==""){
- throw "State id不可为空"
- }
- app.States[state.ID]=state
- }
- app.GetState=function(id){
- let state=app.States[id]
- if (!state){
- throw "未知的state id"+id
- }
- return state
- }
- app.ChangeState=function(id){
- let state=app.GetState(id)
- app.StateContext.ChangeState(state)
- }
- app.OnStateEnvent=function(event,data){
- app.StateContext.OnEvent(event,data)
- }
- app.UpdateState=function(){
- let statuetext=app.Data.State
- world.SetStatus(statuetext);
- }
- app.RegisterState(new (Include("core/state/stateinit.js"))())
- app.RegisterState(new (Include("core/state/stateready.js"))())
- app.RegisterState(new (Include("core/state/statemanual.js"))())
- app.ChangeState("init")
- })(App)
复制代码
https://github.com/hellclient-sc ... cript/core/state.js
我添加了全局的全局的注册获取状态的方法,全局的切换状态和相应状态方法的快捷方式
同时,引入了 init,ready,manual三个状态,并在加载程序后进入了init状态
|
|