Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathshopHandler.lua
More file actions
Latest commit
276 lines (243 loc) · 9 KB
/
Copy pathshopHandler.lua
File metadata and controls
276 lines (243 loc) · 9 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
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
localIterableMap=require("include/IterableMap")
localutil=require("include/util")
localFont=require("include/font")
localplatformUtilities=require("utilities/platformUtilities")
localportalUtilities=require("utilities/portalUtilities")
localbuttonUtilities=require("utilities/buttonUtilities")
localself= {}
localapi= {}
localfunctionSaveLevel()
LevelHandler.SaveLevel(self.levelFile.Get())
end
localfunctionLoadLevel()
LevelHandler.LoadLevel(self.levelFile.Get())
end
functionapi.SnapToGrid(pos, xGridMax, yGridMax)
return {math.floor(
0.5+pos[1] /math.min(xGridMax, self.placeGridSize.Get())) *math.min(xGridMax, self.placeGridSize.Get()),
math.floor(0.5+pos[2] /math.min(yGridMax, self.placeGridSize.Get())) *math.min(yGridMax, self.placeGridSize.Get())
}
end
localfunctionDoEntityClick(mousePos, button)
ifself.hoveredItemandbutton==1then
ifself.selectedPropertythen
self.selectedProperty.SetSelected(false)
self.selectedProperty=false
end
ifGlobal.IGNORE_MOVE_ON_SELECTandnotself.selectedItemthen
-- Stop entities repositioning when clicking on them followed by an accidental mouse movement.
self.ignoreMouseMove=true
end
self.selectedItem=self.hoveredItem
self.selectedOffset=util.Subtract(LevelHandler.WorldToHg(mousePos), self.selectedItem.GetPosition())
self.selectedProperty=self.selectedItem.GetDefaultSelectedProperty()
self.selectedProperty.SetSelected(true)
returntrue
elseifself.selectedItemandbutton==2then
ifself.selectedPropertythen
self.selectedProperty.SetSelected(false)
self.selectedProperty=false
end
self.selectedItem=false
returntrue
end
end
localfunctionDoPropertyClick(mousePos, button, mouseMove)
if (notmouseMove) andself.selectedPropertyandself.selectedProperty.HandleMousePressandself.selectedProperty.HandleMousePress(mousePos, button) then
returntrue
end
if (notmouseMove) andself.hoveredPropertyandbutton==1then
ifself.selectedPropertythen
self.selectedProperty.SetSelected(false)
end
self.selectedProperty=self.hoveredProperty
self.selectedProperty.SetSelected(true)
returntrue
elseifself.selectedPropertyandbutton==1andmousePos[1] <Global.VIEW_WIDTH+Global.MAIN_PADDINGthen
ifself.selectedProperty.HandleWorldClickthen
self.selectedProperty.HandleWorldClick(LevelHandler.WorldToHg(mousePos), mouseMove, self.selectedOffset)
returntrue
end
elseifself.selectedPropertyandbutton==2then
api.DeselectProperty()
end
end
localfunctionDoPropertyKeyPress(key, scancode, isRepeat)
ifself.selectedPropertyandself.selectedProperty.HandleKeyPressthen
self.selectedProperty.HandleKeyPress(key)
end
end
functionapi.DeselectProperty()
ifself.selectedPropertythen
self.selectedProperty.SetSelected(false)
self.selectedProperty=false
end
end
functionapi.Update(dt)
end
functionapi.MousePressed(x, y, button)
self.ignoreMouseMove=false
localmousePos=self.world.GetMousePosition()
ifDoPropertyClick(mousePos, button) then
returntrue
end
ifDoEntityClick(mousePos, button) then
returntrue
end
end
functionapi.MouseMoved(x, y, button, dx, dy)
ifself.ignoreMouseMovethen
return
end
localmousePos=self.world.GetMousePosition()
ifDoPropertyClick(mousePos, button, true) then
returntrue
end
end
functionapi.KeyPressed(key, scancode, isRepeat)
ifDoPropertyKeyPress(key, scancode, isRepeat) then
returntrue
end
ifkey=="l" and (love.keyboard.isDown("lctrl") orlove.keyboard.isDown("rctrl")) then
LoadLevel()
end
ifkey=="s" and (love.keyboard.isDown("lctrl") orlove.keyboard.isDown("rctrl")) then
SaveLevel()
end
end
localfunctionDrawEntityProperties(drawQueue, propList, mousePos)
localoffset, hovered=0, false
fori=1, #propListdo
offset, hovered=propList[i].DrawProperty(drawQueue, Global.VIEW_WIDTH+30, offset, mousePos)
ifhoveredthen
self.hoveredProperty=hovered
end
end
end
functionapi.Draw(drawQueue)
localmousePos=self.world.GetMousePosition()
self.hoveredItem=false
self.hoveredProperty=false
localhgPos=LevelHandler.WorldToHg(mousePos)
localhitEntity=EntityHandler.HitTest(hgPos)
ifhitEntitythen
self.hoveredItem=hitEntity
end
ifself.hoveredItemthen
self.hoveredItem.DrawOutline(drawQueue, "hover")
end
ifself.selectedItemthen
self.selectedItem.DrawOutline(drawQueue, "selected")
DrawEntityProperties(drawQueue, self.selectedItem.GetPropertyList(), mousePos)
else
DrawEntityProperties(drawQueue, self.propList, mousePos)
end
end
functionapi.UpdateLevelParams(level)
self.levelName.Set(level.name)
self.levelFile.Set(level.fileName)
self.levelWidth.Set(level.width)
self.levelHeight.Set(level.height)
self.timeLength.Set(level.timeLength)
self.timeSpeed.Set(level.timeSpeed)
end
localfunctionSetupMenu()
localfunctionSetWidth(newVal)
LevelHandler.SetWidth(newVal)
end
localfunctionSetHeight(name)
LevelHandler.SetHeight(newVal)
end
localfunctionSetTimeLength(newVal)
LevelHandler.SetLevelParameter("timeLength", newVal)
end
localfunctionSetTimeSpeed(newVal)
LevelHandler.SetLevelParameter("timeSpeed", newVal)
end
localfunctionToggleWall(pos, fromMouseMove, offset, size)
ifnotfromMouseMovethen
self.wallAddMode=notLevelHandler.WallAt(pos)
end
size= (sizeor0) *LevelHandler.GetTileSize()
forx=pos[1] -size, pos[1] +size, LevelHandler.GetTileSize() do
fory=pos[2] -size, pos[2] +size, LevelHandler.GetTileSize() do
ifself.wallAddModethen
LevelHandler.AddWall({x, y})
else
LevelHandler.RemoveWall({x, y})
end
end
end
end
localfunctionDeleteEntity(pos)
EntityHandler.RemoveEntitiesAtPos(pos)
end
localfunctionAddDefaultEntity(name, data)
data=dataor {}
data.pos= {LevelHandler.Width() *Global.HG_GRID_SIZE*0.5, LevelHandler.Height() *Global.HG_GRID_SIZE*0.5}
EntityHandler.AddEntity(name, data)
end
self.levelName=NewProp.textBox(api, "Level Name", "")
self.levelFile=NewProp.textBox(api, "Level File", "")
self.saveButton=NewProp.clickButton(api, "Save (ctrl+S)", SaveLevel)
self.loadButton=NewProp.clickButton(api, "Load (ctrl+L)", LoadLevel)
self.levelPath=NewProp.heading(api, love.filesystem.getSaveDirectory() .."/levels", 2)
self.levelWidth=NewProp.numberBox(api, "Level Width", LevelHandler.Width(), 1, false, 1, SetWidth)
self.levelHeight=NewProp.numberBox(api, "Level Height",LevelHandler.Height(), 1, false, 1, SetHeight)
self.timeLength=NewProp.numberBox(api, "Time Length (s)", LevelHandler.GetTimeLength(), 60, false, Global.FRAMES_PER_SECOND, SetTimeLength)
self.timeSpeed=NewProp.numberBox(api, "Time Speed (s/s)", LevelHandler.GetTimeSpeed(), 1, false, 1, SetTimeSpeed)
self.placeGridSize=NewProp.numberBox(api, "Place Grid Snap", 800, 100, 3200, 100)
self.toggleWallSmall=NewProp.worldClickButton(api, "Wall Brush 1", ToggleWall, {0})
self.toggleWallMedium=NewProp.worldClickButton(api, "Wall Brush 2", ToggleWall, {1})
self.toggleWallLarge=NewProp.worldClickButton(api, "Wall Brush 3", ToggleWall, {2})
self.deleteEntity=NewProp.worldClickButton(api, "Delete Entities", DeleteEntity)
self.boxSelector=NewProp.enumBox(api, "", "", {"box", "bomb", "balloon", "light"}, AddDefaultEntity, "New Box")
self.pickupSelector=NewProp.enumBox(api, "", "", Global.PICKUP_LIST,
function (name) AddDefaultEntity("pickup", {pickupType=name}) end, "New Pickup")
self.platformSelector=NewProp.enumBox(api, "", "", {"elevator", "platform", "door"},
function (name) AddDefaultEntity("platform", platformUtilities.GetDefaultPlatform(name)) end, "New Platform")
self.portalSelector=NewProp.enumBox(api, "", "", {"win", "zero", "reverse"},
function (name) AddDefaultEntity("portal", portalUtilities.GetDefaultPortal(name)) end, "New Portal")
self.buttonSelector=NewProp.enumBox(api, "", "", {"momentarySwitch", "stickySwitch"},
function (name)
localbuttonType, buttonData=buttonUtilities.GetDefaultButton(name)
AddDefaultEntity(buttonType, buttonData)
end, "New Button")
self.propList= {
self.levelName,
self.levelFile,
self.saveButton,
self.loadButton,
self.levelPath,
self.levelWidth,
self.levelHeight,
self.timeLength,
self.timeSpeed,
NewProp.heading(api, ""),
self.placeGridSize,
self.toggleWallSmall,
self.toggleWallMedium,
self.toggleWallLarge,
self.deleteEntity,
NewProp.heading(api, ""),
self.boxSelector,
self.pickupSelector,
self.platformSelector,
self.portalSelector,
self.buttonSelector,
}
end
functionapi.ResetState()
ifself.selectedPropertythen
self.selectedProperty.SetSelected(false)
self.selectedProperty=false
end
self.selectedItem=false
end
functionapi.Initialize(world)
self= {
world=world,
}
SetupMenu()
end
returnapi