Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
Windblade-GR01 committed Nov 6, 2021
2 parents 77146df + cd9c93a commit 40a0221
Show file tree
Hide file tree
Showing 2 changed files with 96 additions and 27 deletions.
11 changes: 11 additions & 0 deletions external/script/global.lua
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,7 @@ local endFlag = false

--function called during match via config.json CommonLua
function loop()
hook.run("loop.start")
if start == nil then --match started via command line without -loadmotif flag
if esc() then
endMatch()
Expand Down Expand Up @@ -225,6 +226,7 @@ function loop()
--dialogue
if indialogue() then
start.f_dialogue()
hook.run("loop.dialog")
--match end
elseif roundstate() == -1 then
if not endFlag then
Expand All @@ -244,11 +246,20 @@ function loop()
clearColor(motif.selectbgdef.bgclearcolor[1], motif.selectbgdef.bgclearcolor[2], motif.selectbgdef.bgclearcolor[3])
togglePostMatch(false)
end
if winnerteam() ~= -1 and player(winnerteam()) and roundstate() == 4 then
--turns life recovery
start.f_turnsRecovery()
--rank
start.f_rank()
end
hook.run("loop."..gamemode().."#always")
--pause menu
if main.pauseMenu then
playerBufReset()
menu.f_run()
hook.run("loop.pause")
else
hook.run("loop."..gamemode())
main.f_cmdInput()
--esc / m
if (esc() or (main.f_input(main.t_players, {'m'})) and not network()) and not start.challengerInit then
Expand Down
112 changes: 85 additions & 27 deletions external/script/main.lua
Original file line number Diff line number Diff line change
Expand Up @@ -369,11 +369,37 @@ end

main.font = {}
main.font_def = {}

--hooks for existing lua functions, to make it easier to insert things into other functions.
hook = {
lists = {}
}

function hook.add(list,name,func)
if hook.lists[list] == nil then
hook.lists[list] = {}
end
hook.lists[list][name] = func
end

function hook.run(list,...)
if hook.lists[list] then
for i,k in pairs(hook.lists[list]) do
k(...)
end
end
end

function hook.stop(list,name)
hook.lists[list][name] = nil
end

text = {}
color = {}
rect = {}
--create text
function text:create(t)
local t = t or {}
t.font = t.font or -1
t.bank = t.bank or 0
t.align = t.align or 0
Expand Down Expand Up @@ -418,44 +444,69 @@ function text:create(t)
return t
end

text.new = text.create

function text:setAlign(align)

if align:lower() == "left" then
self.align = -1
elseif align:lower() == "center" or align:lower() == "middle" then
self.align = 0
elseif align:lower() == "right" then
self.align = 1
end
textImgSetAlign(self.ti,self.align)
return self

end

--update text
function text:update(t)
local ok = false
local fontChange = false
for k, v in pairs(t) do
if self[k] ~= v then
if k == 'font' or k == 'height' then
fontChange = true
if type(t) == "table" then
local ok = false
local fontChange = false
for k, v in pairs(t) do
if self[k] ~= v then
if k == 'font' or k == 'height' then
fontChange = true
end
self[k] = v
ok = true
end
self[k] = v
ok = true
end
end
if not ok then return end
if fontChange and self.font ~= -1 then
if main.font[self.font .. self.height] == nil then
main.font[self.font .. self.height] = fontNew(self.font, self.height)
end
if main.font_def[self.font .. self.height] == nil then
main.font_def[self.font .. self.height] = fontGetDef(main.font[self.font .. self.height])
if not ok then return end
if fontChange and self.font ~= -1 then
if main.font[self.font .. self.height] == nil then
main.font[self.font .. self.height] = fontNew(self.font, self.height)
end
if main.font_def[self.font .. self.height] == nil then
main.font_def[self.font .. self.height] = fontGetDef(main.font[self.font .. self.height])
end
textImgSetFont(self.ti, main.font[self.font .. self.height])
end
textImgSetFont(self.ti, main.font[self.font .. self.height])
textImgSetBank(self.ti, self.bank)
textImgSetAlign(self.ti, self.align)
textImgSetText(self.ti, self.text)
textImgSetColor(self.ti, self.r, self.g, self.b)
if self.defsc then main.f_disableLuaScale() end
textImgSetPos(self.ti, self.x + main.f_alignOffset(self.align), self.y)
textImgSetScale(self.ti, self.scaleX, self.scaleY)
textImgSetWindow(self.ti, self.window[1], self.window[2], self.window[3] - self.window[1], self.window[4] - self.window[2])
if self.defsc then main.f_setLuaScale() end
else
self.text = t
textImgSetText(self.ti, self.text)
end
textImgSetBank(self.ti, self.bank)
textImgSetAlign(self.ti, self.align)
textImgSetText(self.ti, self.text)
textImgSetColor(self.ti, self.r, self.g, self.b)
if self.defsc then main.f_disableLuaScale() end
textImgSetPos(self.ti, self.x + main.f_alignOffset(self.align), self.y)
textImgSetScale(self.ti, self.scaleX, self.scaleY)
textImgSetWindow(self.ti, self.window[1], self.window[2], self.window[3] - self.window[1], self.window[4] - self.window[2])
if self.defsc then main.f_setLuaScale() end

return self
end

--draw text
function text:draw()
if self.font == -1 then return end
textImgDraw(self.ti)

return self
end

--create color
Expand Down Expand Up @@ -530,6 +581,7 @@ end

--create rect
function rect:create(t)
local t = t or {}
t.x1 = t.x1 or 0
t.y1 = t.y1 or 0
t.x2 = t.x2 or 0
Expand All @@ -542,6 +594,8 @@ function rect:create(t)
return t
end

rect.new = rect.create

--modify rect
function rect:update(t)
for i, k in pairs(t) do
Expand All @@ -550,13 +604,17 @@ function rect:update(t)
if t.r or t.g or t.b or t.src or t.dst then
self.color = color:new(t.r or self.r, t.g or self.g, t.b or self.b, t.src or self.src, t.dst or self.dst)
end

return self
end

--draw rect
function rect:draw()
if self.defsc then main.f_disableLuaScale() end
fillRect(self.x1, self.y1, self.x2, self.y2, self.r, self.g, self.b, self.src, self.dst)
if self.defsc then main.f_setLuaScale() end

return self
end

--create textImg based on usual motif parameters
Expand Down Expand Up @@ -3965,7 +4023,7 @@ end
for _, v in ipairs(config.Modules) do
table.insert(t_modules, v)
end
if motif.module ~= '' then table.insert(t_modules, motif.module) end
if motif.files.module ~= '' then table.insert(t_modules, motif.files.module) end
for _, v in ipairs(t_modules) do
print('Loading module: ' .. v)
v = v:gsub('^%s*[%./\\]*', '')
Expand Down

0 comments on commit 40a0221

Please sign in to comment.