Lua 리 디자인 줄거리 체인
--[[
file name . GameList.lua
author . Clark/
created . 8.13.2011
purpose .
--]]
module("GameList", package.seeall)
--
function list_newList()
local first = 1
local last = 0
local list = {}
local listManager = {}
function listManager.pushFront(_tempObj)
first = first - 1
list[first] = _tempObj
end
function listManager.pushBack(_tempObj)
last = last + 1
list[last] = _tempObj
end
function listManager.temp_getFront()
if listManager.bool_isEmpty() then
return nil
else
local val = list[first]
return val
end
end
function listManager.temp_getBack()
if listManager.bool_isEmpty() then
return nil
else
local val = list[last]
return val
end
end
function listManager.popFront()
list[first] = nil
first = first + 1
end
function listManager.popBack()
list[last] = nil
last = last - 1
end
function listManager.clear()
while false == listManager.bool_isEmpty() do
listManager.popFront()
end
end
function listManager.bool_isEmpty()
if first > last then
first = 1
last = 0
return true
else
return false
end
end
function listManager.d_getSize()
if listManager.bool_isEmpty() then
return 0
else
return last - first + 1
end
end
return listManager
end
-------------------------------------------------------------------------------------
--[[
file name : GameEvents.lua
author : Clark/
created : 8:13:2011
purpose :
--]]
module("GameEvents", package.seeall)
pakList = require "GameList"
function manager_newEventManager()
--
function events_newEvents(_ID)
local ID = _ID or os.time()
local cmdpars = pakList.list_newList() --
local events = {} --
function events.id_getID()
return ID
end
--
function events.push(_trigger, _tTgrPar, _fun, _tFunPar)
local t = { trigger = _trigger, tTgrPar = _tTgrPar or {}, fun = _fun, tFunPar = _tFunPar or {}}
cmdpars.pushBack(t)
end
--
function events.clear()
cmdpars.clear()
end
--
function events.setEvent()
local tVal = cmdpars.temp_getFront()
if nil ~= tVal then
if nil ~= tVal.trigger then
tVal.trigger(events.id_getID(), tVal.tTgrPar)
end
end
end
--
function events.onEvent(tEventPar)
local tEventPar = tEventPar or {}
local tVal = cmdpars.temp_getFront()
if nil ~= tVal then
cmdpars.popFront()
if nil ~= tVal.fun then
tVal.fun(events.id_getID(), tVal.tFunPar, tEventPar)
end
end
end
--
function events.bool_isEmpty()
local val = cmdpars.bool_isEmpty()
return val
end
return events --
end
--
local et = {}
local manager = {}
function manager.events_newEvents(_ID)
local event = events_newEvents(_ID)
if nil ~= event then
et[event.id_getID()] = event
end
return event
end
function manager.events_getEvents(_ID)
return et[_ID]
end
function manager.deleteEvents(_ID)
et[_ID] = nil
end
return manager
end
-------------------------------------------------------------------------------------
--[[
file name : GameCallBack.lua
author : Clark/
created : 8:13:2011
purpose :
--]]
module("GameCallBack", package.seeall)
pakEvents = require "GameEvents"
EVENT_MANAGER = pakEvents.manager_newEventManager()
--
function onGotoCallBack(_tEventPar)
local et = EVENT_MANAGER.events_getEvents(_tEventPar)
if nil ~= et then
et.onEvent()
et.setEvent()
end
end
--
function onDieCallBack(_tEventPar)
local et = EVENT_MANAGER.events_getEvents(_tEventPar)
if nil ~= et then
et.onEvent()
et.setEvent()
end
end
-------------------------------------------------------------------------------------
--[[
file name : GameMain.lua
author : Clark/
created : 8:13:2011
purpose :
--]]
module("GameMain", package.seeall)
pakCallBack = require "GameCallBack"
------------------------ -----------------------------
function map_newMap(_ID)
local ID = _ID
local map = {}
-- ID
function map.id_getID()
return ID
end
--
function map.event_KillMonster()
local tgr = false
local et = {}
function et.setEvent(eventID, tTgrPar)
print("on EVENTS:", eventID, "| Map: ", map.id_getID(), " on ", tTgrPar[1])
tgr = true
pakCallBack.onDieCallBack(eventID)
end
function et.onEvent(eventID, tFunPar, tEventPar)
print("do EVENTS:", eventID, "| Map: ", map.id_getID(), " -> ", tFunPar[1])
tgr = false
end
return et
end
--
function map.event_Exit()
local tgr = false
local et = {}
function et.setEvent(eventID, tTgrPar)
print("on EVENTS:", eventID, "| Map: ", map.id_getID(), " on ", tTgrPar[1])
tgr = true
pakCallBack.onGotoCallBack(eventID)
end
function et.onEvent(eventID, tFunPar, tEventPar)
print("do EVENTS:", eventID, "| Map: ", map.id_getID(), " -> ", tFunPar[1])
tgr = false
map.uninitScene()
end
return et
end
local EVENTS_1_ID = os.time() -- os.time() ,
local EVENTS_2_ID = EVENTS_1_ID + 1
--
function map.initScene()
print("---------- initScene ----------")
local et = nil
-- 1
local ets1 = pakCallBack.EVENT_MANAGER.events_newEvents(EVENTS_1_ID)
et = map.event_KillMonster()
ets1.push(et.setEvent, {"Wolf die"}, et.onEvent, {"give A"})
-- 2
local ets2 = pakCallBack.EVENT_MANAGER.events_newEvents(EVENTS_2_ID)
ets2.push(et.setEvent, {"tiger die"}, et.onEvent, {"give B"})
et = map.event_Exit()
ets2.push(et.setEvent, {"exiting"}, et.onEvent, {"exited"})
--
ets1.setEvent()
ets2.setEvent()
end
--
function map.uninitScene()
print("---------- uninitScene ----------")
pakCallBack.EVENT_MANAGER.deleteEvents(EVENTS_1_ID)
end
return map
end
function main()
map = map_newMap(007)
map.initScene()
end
main()
-------------------------------------------------------------
result:
>lua -e "io.stdout:setvbuf 'no'""Main.lua" ---------- initScene ---------- on EVENTS: 1313262659 | Map: 7 on Wolf die do EVENTS: 1313262659 | Map: 7 -> give A on EVENTS: 1313262660 | Map: 7 on tiger die do EVENTS: 1313262660 | Map: 7 -> give B on EVENTS: 1313262660 | Map: 7 on exiting do EVENTS: 1313262660 | Map: 7 -> exited ---------- uninitScene ---------->Exit code: 0
이 내용에 흥미가 있습니까?
현재 기사가 여러분의 문제를 해결하지 못하는 경우 AI 엔진은 머신러닝 분석(스마트 모델이 방금 만들어져 부정확한 경우가 있을 수 있음)을 통해 가장 유사한 기사를 추천합니다:
[SwiftUI]List화한 CoreData를 가로 스와이프로 행 삭제하는 방법상당히 조사했지만 일본어 자료가 없었기 때문에 비망록으로 남겨 둔다. 아래와 같이 CoreData를 참조한 리스트를 가로 스와이프로 삭제하고 싶었다. UI 요소뿐만 아니라 원본 데이터 당 삭제합니다. 잘 다른 페이지...
텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
CC BY-SA 2.5, CC BY-SA 3.0 및 CC BY-SA 4.0에 따라 라이센스가 부여됩니다.