aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--bin/BeatEm/init.lua14
-rw-r--r--bin/BehaviorTree/init.lua3
-rw-r--r--bin/EventMsgCenter/EventMsgCenter.lua55
-rw-r--r--bin/EventMsgCenter/Events.lua21
-rw-r--r--bin/EventMsgCenter/README.md2
-rw-r--r--bin/StateMachine/init.lua3
-rw-r--r--bin/Tilemap/init.lua0
-rw-r--r--bin/UI/Button.lua5
-rw-r--r--bin/anim/README.md0
-rw-r--r--bin/anim/anim.lua11
-rw-r--r--bin/class/class.lua15
-rw-r--r--bin/component/component.lua20
-rw-r--r--bin/enum/enum.lua11
-rw-r--r--bin/jin3d/init.lua0
-rw-r--r--bin/json/README.md0
-rw-r--r--bin/loghelper/init.lua33
-rw-r--r--bin/newton/README.md0
-rw-r--r--bin/newton/init.lua9
-rw-r--r--bin/particle/particle.lua5
-rw-r--r--bin/pool/pool.lua3
-rw-r--r--bin/shader/README.md0
-rw-r--r--bin/timer/timer.lua78
-rw-r--r--bin/xml/README.md0
23 files changed, 288 insertions, 0 deletions
diff --git a/bin/BeatEm/init.lua b/bin/BeatEm/init.lua
new file mode 100644
index 0000000..b9cab27
--- /dev/null
+++ b/bin/BeatEm/init.lua
@@ -0,0 +1,14 @@
+local BeatEm = {
+ _NAME = "BeatEm"
+ _AUTHOR = "Chai",
+ _DESCRIPTION = [[
+A Fighting game utility for Jin game framework.
+ ]],
+ _JIN_REVISION = 101,
+ _REVISION = 100
+ _LISENCE = [[
+
+ ]]
+}
+
+return BeatEm \ No newline at end of file
diff --git a/bin/BehaviorTree/init.lua b/bin/BehaviorTree/init.lua
new file mode 100644
index 0000000..79863bc
--- /dev/null
+++ b/bin/BehaviorTree/init.lua
@@ -0,0 +1,3 @@
+local BehaviorTree = {}
+
+return BehaviorTrees \ No newline at end of file
diff --git a/bin/EventMsgCenter/EventMsgCenter.lua b/bin/EventMsgCenter/EventMsgCenter.lua
new file mode 100644
index 0000000..7b944c2
--- /dev/null
+++ b/bin/EventMsgCenter/EventMsgCenter.lua
@@ -0,0 +1,55 @@
+local EventMsgCenter = {}
+
+-- <event, {callbacks}>
+local _broadcast = {}
+
+EventMsgCenter.registerMsg = function(e, callback, first)
+ if _broadcast[e] == nil then
+ _broadcast[e] = {}
+ end
+ first = first or false
+ EventMsgCenter.unregisterMsg(e, callback)
+ if not first then
+ table.insert(_broadcast[e], callback)
+ else
+ table.insert(_broadcast[e], 1, callback)
+ end
+end
+
+local removeElement = function(t, e)
+ for i, v in ipairs(t) do
+ if v == e then
+ table.remove(t, i)
+ break
+ end
+ end
+end
+
+EventMsgCenter.unregisterMsg = function(e, callback)
+ if _broadcast[e] == nil or callback == nil then
+ return
+ end
+ removeElement(_broadcast[e], callback)
+end
+
+EventMsgCenter.unregisterAllMsgByEvent = function(e)
+ _broadcast[e] = nil
+end
+
+EventMsgCenter.unregisterAllMsg = function()
+ _broadcast = {}
+end
+
+EventMsgCenter.sendMsg = function(e, ...)
+ local callbacks = _broadcast[e]
+ if callbacks == nil then
+ return
+ end
+ for _, f in ipairs(callbacks) do
+ if f ~= nil then
+ f(...)
+ end
+ end
+end
+
+return EventMsgCenter \ No newline at end of file
diff --git a/bin/EventMsgCenter/Events.lua b/bin/EventMsgCenter/Events.lua
new file mode 100644
index 0000000..3803fd4
--- /dev/null
+++ b/bin/EventMsgCenter/Events.lua
@@ -0,0 +1,21 @@
+local events = {
+
+ "Player_Move",
+ "Player_Change",
+ "Player_Spawn",
+ "Player_Kick",
+
+ ""
+
+}
+
+function CreatEnumTable(tbl, index)
+ local enumtbl = {}
+ local enumindex = index or 0
+ for i, v in ipairs(tbl) do
+ enumtbl[v] = enumindex + i
+ end
+ return enumtbl
+end
+
+return CreatEnumTable(events) \ No newline at end of file
diff --git a/bin/EventMsgCenter/README.md b/bin/EventMsgCenter/README.md
new file mode 100644
index 0000000..ef3bd92
--- /dev/null
+++ b/bin/EventMsgCenter/README.md
@@ -0,0 +1,2 @@
+Event Massage Center
+
diff --git a/bin/StateMachine/init.lua b/bin/StateMachine/init.lua
new file mode 100644
index 0000000..83daeb7
--- /dev/null
+++ b/bin/StateMachine/init.lua
@@ -0,0 +1,3 @@
+local StateMachine = {}
+
+return StateMachine \ No newline at end of file
diff --git a/bin/Tilemap/init.lua b/bin/Tilemap/init.lua
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/bin/Tilemap/init.lua
diff --git a/bin/UI/Button.lua b/bin/UI/Button.lua
new file mode 100644
index 0000000..69950b7
--- /dev/null
+++ b/bin/UI/Button.lua
@@ -0,0 +1,5 @@
+local Button = {}
+
+
+
+return Button \ No newline at end of file
diff --git a/bin/anim/README.md b/bin/anim/README.md
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/bin/anim/README.md
diff --git a/bin/anim/anim.lua b/bin/anim/anim.lua
new file mode 100644
index 0000000..a1529c3
--- /dev/null
+++ b/bin/anim/anim.lua
@@ -0,0 +1,11 @@
+local anim = {
+ _DESCRIPTION = [[
+
+ ]],
+ _AUTHOR = "Chai",
+ _JIN_REVISION = 101,
+
+}
+
+
+return anim \ No newline at end of file
diff --git a/bin/class/class.lua b/bin/class/class.lua
new file mode 100644
index 0000000..6cff4d7
--- /dev/null
+++ b/bin/class/class.lua
@@ -0,0 +1,15 @@
+local class = {}
+
+class.new = function(self, ...)
+ local c = {}
+ setmetatable(c, self)
+ self.__index = self
+ if self.init then
+ self.init(...)
+ end
+ return c
+end
+
+class.static = {}
+
+return class \ No newline at end of file
diff --git a/bin/component/component.lua b/bin/component/component.lua
new file mode 100644
index 0000000..2432054
--- /dev/null
+++ b/bin/component/component.lua
@@ -0,0 +1,20 @@
+local Component = {
+ object = nil
+}
+
+Component.new = function(obj)
+ local component = {}
+ setmetatable(component, Component)
+ Component.__index = Component
+ component:_init(obj)
+end
+
+Component._init = function(self, obj)
+ self.object = obj
+end
+
+Component.update = function(dt)
+
+end
+
+return Component \ No newline at end of file
diff --git a/bin/enum/enum.lua b/bin/enum/enum.lua
new file mode 100644
index 0000000..20a653d
--- /dev/null
+++ b/bin/enum/enum.lua
@@ -0,0 +1,11 @@
+local createEnumTable = function(tbl, index)
+ assert(IsTable(tbl))
+ local enumtbl = {}
+ local enumindex = index or 0
+ for i, v in ipairs(tbl) do
+ enumtbl[v] = enumindex + i
+ end
+ return enumtbl
+end
+
+return createEnumTable \ No newline at end of file
diff --git a/bin/jin3d/init.lua b/bin/jin3d/init.lua
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/bin/jin3d/init.lua
diff --git a/bin/json/README.md b/bin/json/README.md
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/bin/json/README.md
diff --git a/bin/loghelper/init.lua b/bin/loghelper/init.lua
new file mode 100644
index 0000000..fc07943
--- /dev/null
+++ b/bin/loghelper/init.lua
@@ -0,0 +1,33 @@
+-- 不能使用 debug 命名模块,会冲突,
+-- 要使用其余名字比如 loghelper
+local loghelper = {}
+io.stdout:setvbuf("no")
+
+loghelper.LEVEL = {
+ INFO = 4,
+ DEBUG = 3,
+ WARN = 2,
+ ERROR = 1,
+ NONE = 0
+}
+
+local logTag = {
+ [loghelper.LEVEL.INFO] = "[Info]",
+ [loghelper.LEVEL.DEBUG] = "[Debug]",
+ [loghelper.LEVEL.WARN] = "[Warn]",
+ [loghelper.LEVEL.ERROR] = "[Error]",
+}
+
+loghelper.level = loghelper.LEVEL.INFO
+
+loghelper.strict = function(level)
+ loghelper.level = level
+end
+
+loghelper.log = function(level, msg)
+ if level <= loghelper.level then
+ print(logTag[level] .. ":" .. msg)
+ end
+end
+
+return loghelper \ No newline at end of file
diff --git a/bin/newton/README.md b/bin/newton/README.md
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/bin/newton/README.md
diff --git a/bin/newton/init.lua b/bin/newton/init.lua
new file mode 100644
index 0000000..41f9f9a
--- /dev/null
+++ b/bin/newton/init.lua
@@ -0,0 +1,9 @@
+local newton = {}
+
+newton.world = {}
+
+newton.update = function(dt)
+
+end
+
+return newton \ No newline at end of file
diff --git a/bin/particle/particle.lua b/bin/particle/particle.lua
new file mode 100644
index 0000000..e430da9
--- /dev/null
+++ b/bin/particle/particle.lua
@@ -0,0 +1,5 @@
+local particle = {}
+
+
+
+return particle \ No newline at end of file
diff --git a/bin/pool/pool.lua b/bin/pool/pool.lua
new file mode 100644
index 0000000..39eb3a6
--- /dev/null
+++ b/bin/pool/pool.lua
@@ -0,0 +1,3 @@
+local pool = {}
+
+return pool \ No newline at end of file
diff --git a/bin/shader/README.md b/bin/shader/README.md
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/bin/shader/README.md
diff --git a/bin/timer/timer.lua b/bin/timer/timer.lua
new file mode 100644
index 0000000..398f47f
--- /dev/null
+++ b/bin/timer/timer.lua
@@ -0,0 +1,78 @@
+local Timer = {}
+local MODE = {
+ NONE = 0,
+ EVERY = 1,
+ REPEATS = 2,
+ AFTER = 3,
+}
+Timer.timers = {}
+local timer = {
+ new = function(self, _mod, _duration, _count, _callback)
+ local t = {}
+ setmetatable(t, self)
+ self.__index = self
+ t:_init(_mod, _duration, _count, _callback)
+ return t
+ end,
+ _init = function(self, _mod, _duration, _count, _callback)
+ self.tick = 0
+ self.duration = _duration
+ self.mode = _mod
+ self.count = _count
+ self.callback = _callback
+ end,
+ update = function(self, dt)
+ self.tick = self.tick + dt
+ if self.tick >= self.duration then
+ if self.mode == MODE.EVERY then
+ self.tick = 0
+ elseif self.mode == MODE.REPEATS then
+ self.tick = 0
+ self.count = self.count - 1
+ if self.count <= 0 then
+ -- remove this
+ for i, v in ipairs(Timer.timers) do
+ if v == self then
+ table.remove(Timer.timers, i)
+ break
+ end
+ end
+ end
+ elseif self.mode == MODE.AFTER then
+ -- remove this
+ for i, v in ipairs(Timer.timers) do
+ if v == self then
+ table.remove(Timer.timers, i)
+ break
+ end
+ end
+ end
+ if self.callback then
+ self.callback()
+ end
+ end
+ end
+}
+
+Timer.update = function(sec)
+ for _, t in ipairs(Timer.timers) do
+ t:update(sec)
+ end
+end
+
+Timer.every = function(sec, callback)
+ local t = timer:new(MODE.EVERY, sec, nil, callback)
+ table.insert(Timer.timers, t)
+end
+
+Timer.repeats = function(sec, rpt, callback)
+ local t = timer:new(MODE.REPEATS, sec, rpt, callback)
+ table.insert(Timer.timers, t)
+end
+
+Timer.after = function(sec, callback)
+ local t = timer:new(MODE.AFTER, sec, nil, callback)
+ table.insert(Timer.timers, t)
+end
+
+return Timer \ No newline at end of file
diff --git a/bin/xml/README.md b/bin/xml/README.md
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/bin/xml/README.md