forked from nikki93/scene-creator
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCommon.lua
More file actions
164 lines (125 loc) · 3.47 KB
/
Common.lua
File metadata and controls
164 lines (125 loc) · 3.47 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
ui = castle.ui
UNIT = 1
MAX_BODY_SIZE = UNIT * 40
MIN_BODY_SIZE = UNIT / 4
DEFAULT_VIEW_WIDTH = 10 * UNIT
MIN_VIEW_WIDTH = DEFAULT_VIEW_WIDTH / 10
MAX_VIEW_WIDTH = DEFAULT_VIEW_WIDTH * 4
VIEW_HEIGHT_TO_WIDTH_RATIO = 7 / 5
CHECKERBOARD_IMAGE_URL =
"https://raw.githubusercontent.com/nikki93/edit-world/4c9d0d6f92b3a67879c7a5714e6608530093b45a/assets/checkerboard.png"
serpent = require "vendor.serpent"
bitser = require "vendor.bitser"
inspect = require "vendor.inspect"
jsEvents = require "__ghost__.jsEvents"
jsBridge = require "__ghost__.bridge"
cjson = require "cjson"
copas = require "copas"
-- Modules
if not castle.system.isRemoteServer() then
tove = require "vendor.tove"
end
resource_loader = require "resource_loader"
util = require "util"
helps = require "helps"
require "actor_behavior" -- -- -- Message kind definition -- Start / stop
require "behaviors.body"
require "behaviors.image"
require "behaviors.drawing"
require "behaviors.circle_shape"
require "behaviors.solid"
require "behaviors.bouncy"
require "behaviors.moving"
require "behaviors.falling"
require "behaviors.sliding"
require "behaviors.slowdown"
require "behaviors.friction"
require "behaviors.speed_limit"
require "behaviors.rotating_motion"
require "behaviors.sling"
require "behaviors.drag"
require "behaviors.rules"
require "behaviors.tags"
require "behaviors.counter"
require "behaviors.text"
require "tools.grab"
require "tools.drawUtils"
if NEW_DRAW_TOOL then
require "tools.draw2"
else
require "tools.draw"
end
require "tools.scale_rotate"
require "library"
require "snapshot"
require "command"
require "variables"
function Common:start()
self.onEndOfFrames = {}
self._nextIdSuffix = 1
self:startActorBehavior()
self:startLibrary()
self:startSnapshot()
self:startCommand()
self:startVariables()
self.performing = true
self.paused = false
end
function Common:stop()
self:stopActorBehavior()
end
function Common:send(opts, ...)
if type(opts) == "string" then -- Shorthand
opts = {kind = opts}
end
local kind = opts.kind
assert(type(kind) == "string", "send: `kind` needs to be a string")
--print("send calling " .. kind .. "()")
self.receivers[kind](self, 0, ...)
end
function Common:generateId()
local suffix = tostring(self._nextIdSuffix)
self._nextIdSuffix = self._nextIdSuffix + 1
local prefix = "0"
return prefix .. "-" .. suffix
end
-- Users
function Common.receivers:me(time, clientId, me)
self.mes[clientId] = me
end
--
--function Common.receivers:ping(time, clientId)
-- self.lastPingTimes[clientId] = time
--end
-- Performance
function Common:updatePerformance(dt)
if self.performing and not self.paused then
self:callHandlers("prePerform", dt)
self:callHandlers("perform", dt)
self:callHandlers("postPerform", dt)
end
end
function Common.receivers:setPerforming(time, performing)
if self.performing ~= performing then
self.performing = performing
self:callHandlers("setPerforming", performing)
end
end
function Common.receivers:setPaused(time, paused)
if self.paused ~= paused then
self.paused = paused
self:callHandlers("setPaused", paused)
end
end
function Common.receivers:clearScene(time)
self:callHandlers("clearScene", paused)
end
--
-- Methods
function Common:fireOnEndOfFrame()
local onEndOfFrames = self.onEndOfFrames
for _, func in ipairs(onEndOfFrames) do
func()
end
self.onEndOfFrames = {}
end