-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.lua
153 lines (141 loc) · 3.71 KB
/
main.lua
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
--globalvariable
require("src/globals/!globals")
--load block and tiles
LoadBlocksAndTiles("src/blocksandtiles")
function love.run()
if love.load then
love.load(Loveargs.parseGameArguments(arg), arg)
end
if Lovetimer then
Lovetimer.step()
end
local dt = 0
return function()
if Loveevent then
Loveevent.pump()
for name, a, b, c, d, e, f in Loveevent.poll() do
if name == "quit" then
if not love.quit or not love.quit() then
return a or 0
end
end
Lovehandlers[name](a, b, c, d, e, f)
end
end
if Lovetimer then
dt = Lovetimer.step()
end
if love.update then
love.update(dt)
end
if Lovegraphics and Lovegraphics.isActive() then
Lovegraphics.origin()
Lovegraphics.clear(Lovegraphics.getBackgroundColor())
if love.draw then
love.draw()
end
Lovegraphics.present()
end
end
end
function FixHudHotbarandTileScaling()
local scaleCoefficient = 0.7
InterfaceWidth = Lovegraphics.getWidth() * scaleCoefficient
InterfaceHeight = Lovegraphics.getHeight() * scaleCoefficient
end
function love.load()
_JPROFILER.push("frame")
_JPROFILER.push("Mainload")
Lovefilesystem.setIdentity("LuaCraft")
love.mouse.setGrabbed(true)
love.mouse.setVisible(true)
SetCurrentGameState(GamestateMainMenu2)
--create_Test_Thread()
InitializeGame()
FixHudHotbarandTileScaling()
_JPROFILER.pop("Mainload")
_JPROFILER.pop("frame")
end
function love.textinput(text)
LuaCraftCurrentGameState:textinput(text)
end
function love.resize(w, h)
_JPROFILER.push("frame")
_JPROFILER.push("Mainresize")
LuaCraftCurrentGameState:resize(w, h)
LuaCraftCurrentGameState:resizeMenu()
local scaleCoefficient = 0.7
InterfaceWidth = w * scaleCoefficient
InterfaceHeight = h * scaleCoefficient
_JPROFILER.pop("Mainresize")
_JPROFILER.pop("frame")
end
function love.update(dt)
_JPROFILER.push("frame")
_JPROFILER.push("MainUpdate")
local message = EnableTestUnitWaitingScreenChannel:pop()
if message then
EnableTestUnitWaitingScreen = false
end
if ResetMovementKeys == true then
ReLoadMovementKeyValues()
ResetMovementKeys = false
end
UpdateGame(dt)
if HudTimeLeft > 0 then
HudTimeLeft = HudTimeLeft - dt
if HudTimeLeft <= 0 or LuaCraftCurrentGameState ~= GameStatePlayingGame2 then
HudMessage = ""
end
end
_JPROFILER.pop("MainUpdate")
_JPROFILER.pop("frame")
end
function love.draw()
_JPROFILER.push("frame")
_JPROFILER.push("MainDraw")
SetFont()
LuaCraftCurrentGameState:draw()
if HudMessage ~= nil then
local width, height = Lovegraphics.getDimensions()
local font = Lovegraphics.getFont()
-- Calculate the width and height of the text
local textWidth = font:getWidth(HudMessage)
local textHeight = font:getHeight(HudMessage)
-- Calculate the position to center the text
local x = (width - textWidth) / 2
local y = (height - textHeight) / 2 + 280
Lovegraphics.print(HudMessage, x, y)
end
_JPROFILER.pop("MainDraw")
_JPROFILER.pop("frame")
end
function love.mousemoved(x, y, dx, dy)
_JPROFILER.push("frame")
_JPROFILER.push("Mainmousemoved")
LuaCraftCurrentGameState:mousemoved(x, y, dx, dy)
_JPROFILER.pop("Mainmousemoved")
_JPROFILER.pop("frame")
end
function love.wheelmoved(x, y)
if FixinputforDrawCommandInput == false then
PlayerInventory.hotbarSelect = math.floor(((PlayerInventory.hotbarSelect - y - 1) % 9 + 1) + 0.5)
end
end
function love.mousepressed(x, y, b)
_JPROFILER.push("frame")
_JPROFILER.push("mousepressed")
LuaCraftCurrentGameState:mousepressed(x, y, b)
_JPROFILER.pop("mousepressed")
_JPROFILER.pop("frame")
end
function love.keypressed(k)
_JPROFILER.push("frame")
_JPROFILER.push("MainKeypressed")
KeyPressed(k)
_JPROFILER.pop("MainKeypressed")
_JPROFILER.pop("frame")
end
function love.quit()
_JPROFILER.write("_JPROFILER.mpack")
end