From 250d75ee77d38721fd253fd123791e5c45a413cb Mon Sep 17 00:00:00 2001 From: Kazhnuz Date: Sun, 13 Sep 2020 16:57:06 +0200 Subject: [PATCH] fix: mark as local some forgotten local variables --- .vscode/settings.json | 6 +++++- sonic-radiance.love/core/input.lua | 1 + .../core/modules/assets/background.lua | 2 +- .../core/modules/gamesystem/init.lua | 2 +- .../core/modules/menusystem/grid.lua | 14 +++++++------- .../core/modules/world/actors/baseactor.lua | 2 +- .../core/modules/world/camera/init.lua | 2 +- sonic-radiance.love/core/options.lua | 6 +++--- sonic-radiance.love/core/utils/graphics.lua | 2 +- sonic-radiance.love/core/utils/math.lua | 2 +- .../game/abstractmobs/character.lua | 4 ++-- sonic-radiance.love/game/init.lua | 9 ++++----- sonic-radiance.love/game/loot/pocket.lua | 2 +- .../scenes/overworld/charsetmanager.lua | 2 +- .../scenes/overworld/screens/menu.lua | 2 +- 15 files changed, 31 insertions(+), 27 deletions(-) diff --git a/.vscode/settings.json b/.vscode/settings.json index bb5418c..2f0c7a5 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -2,6 +2,10 @@ "Lua.diagnostics.globals": [ "love", "unpack", - "loadstring" + "loadstring", + "game", + "core", + "scenes", + "utils" ] } diff --git a/sonic-radiance.love/core/input.lua b/sonic-radiance.love/core/input.lua index 2d6c4c6..b7c01cd 100644 --- a/sonic-radiance.love/core/input.lua +++ b/sonic-radiance.love/core/input.lua @@ -69,6 +69,7 @@ end function InputManager:getKey(sourceid, padkey) local padkey = padkey + local key for k,v in pairs(self.data[sourceid].keys) do if (k == padkey) then key = v end end diff --git a/sonic-radiance.love/core/modules/assets/background.lua b/sonic-radiance.love/core/modules/assets/background.lua index 7a0ac56..4c4ecca 100644 --- a/sonic-radiance.love/core/modules/assets/background.lua +++ b/sonic-radiance.love/core/modules/assets/background.lua @@ -32,7 +32,7 @@ function Background:new(filepath) self.batch = love.graphics.newSpriteBatch(self.image , 1000 ) self.width, self.height = self.image:getDimensions() - screenwidth, screenheight = core.screen:getDimensions() + local screenwidth, screenheight = core.screen:getDimensions() local w = math.floor(screenwidth / self.width) * self.width + 1 local h = math.floor(screenheight / self.height) * self.height + 1 diff --git a/sonic-radiance.love/core/modules/gamesystem/init.lua b/sonic-radiance.love/core/modules/gamesystem/init.lua index c3c7fe8..2fca259 100644 --- a/sonic-radiance.love/core/modules/gamesystem/init.lua +++ b/sonic-radiance.love/core/modules/gamesystem/init.lua @@ -137,7 +137,7 @@ function GameSystem:write() if (self.currentSlot > 0) then local data = self:getData() - savepath = self:getSavePath(self.currentSlot, true) + local savepath = self:getSavePath(self.currentSlot, true) binser.writeFile(savepath, data) end end diff --git a/sonic-radiance.love/core/modules/menusystem/grid.lua b/sonic-radiance.love/core/modules/menusystem/grid.lua index 8db8209..d23895e 100644 --- a/sonic-radiance.love/core/modules/menusystem/grid.lua +++ b/sonic-radiance.love/core/modules/menusystem/grid.lua @@ -147,7 +147,7 @@ end -- Handle the keyboard/manette functions function GridBox:keyreleased(key, code) - slotID = self:getWidgetSlot(self.widget.selected) + local slotID = self:getWidgetSlot(self.widget.selected) local col, line = self.cursor.x, self.cursor.y if key == 'left' then self:moveCol(-1) @@ -181,13 +181,13 @@ function GridBox:moveCol(direction) if utils.math.sign(xx - orig_x) == direction then if utils.math.pointDistance(orig_x, orig_y, xx, yy) < distance then distance = utils.math.pointDistance(orig_x, orig_y, xx, yy) - nearestWidget = v.widgetID + nearastWidget = v.widgetID end end end - if nearestWidget ~= 0 then - self.widget.selected = nearestWidget + if nearastWidget ~= 0 then + self.widget.selected = nearastWidget end end @@ -202,13 +202,13 @@ function GridBox:moveLine(direction) if utils.math.sign(yy - orig_y) == direction then if utils.math.pointDistance(orig_x, orig_y, xx, yy) < distance then distance = utils.math.pointDistance(orig_x, orig_y, xx, yy) - nearestWidget = v.widgetID + nearastWidget = v.widgetID end end end - if nearestWidget ~= 0 then - self.widget.selected = nearestWidget + if nearastWidget ~= 0 then + self.widget.selected = nearastWidget end end diff --git a/sonic-radiance.love/core/modules/world/actors/baseactor.lua b/sonic-radiance.love/core/modules/world/actors/baseactor.lua index 7b82f46..a82f1c2 100644 --- a/sonic-radiance.love/core/modules/world/actors/baseactor.lua +++ b/sonic-radiance.love/core/modules/world/actors/baseactor.lua @@ -118,7 +118,7 @@ function BaseActor:setFilter() end function BaseActor:getFuturePosition(dt) - local dx, dy + local dx, dy, dz dx = self.x + self.xsp * dt dy = self.y + self.ysp * dt dz = self.z + self.zsp * dt diff --git a/sonic-radiance.love/core/modules/world/camera/init.lua b/sonic-radiance.love/core/modules/world/camera/init.lua index 9a136c4..129a338 100644 --- a/sonic-radiance.love/core/modules/world/camera/init.lua +++ b/sonic-radiance.love/core/modules/world/camera/init.lua @@ -178,7 +178,7 @@ function CameraSystem:attachView(id) self.current_canvas = love.graphics.getCanvas() love.graphics.setCanvas(view.canvas) love.graphics.clear() - + local tx, ty, scale if id ~= nil then -- Du à la manière dont fonctionne STI, on est obligé de récupérer les info -- de position de camera pour afficher la carte par rapport à ces infos diff --git a/sonic-radiance.love/core/options.lua b/sonic-radiance.love/core/options.lua index 1c0252b..fc523e7 100644 --- a/sonic-radiance.love/core/options.lua +++ b/sonic-radiance.love/core/options.lua @@ -119,7 +119,7 @@ function OptionsManager:getTranslationDefaultData() local _path = TRANSLATION_PATH .. "init.lua" local fileinfo = love.filesystem.getInfo(_path) local datas = nil - + local lang if fileinfo ~= nil then lang = require(TRANSLATION_PATH) lang.current = lang.default or "en" @@ -144,12 +144,12 @@ end function OptionsManager:write() local data = self:getData() - filepath = self:getFile(true) + local filepath = self:getFile(true) binser.writeFile(filepath, data) end function OptionsManager:read() - filepath = self:getFile(true) + local filepath = self:getFile(true) if utils.filesystem.exists("options.data") then local loadedDatas = binser.readFile(filepath) self.controller.debug:print("core/options", "data file found, loading it") diff --git a/sonic-radiance.love/core/utils/graphics.lua b/sonic-radiance.love/core/utils/graphics.lua index 9a90841..516edea 100644 --- a/sonic-radiance.love/core/utils/graphics.lua +++ b/sonic-radiance.love/core/utils/graphics.lua @@ -69,7 +69,7 @@ function Graphics.printWithSpacing(text, spacing, align, x, y, r, sx, sy, ox, oy for i=1, lenght do local char = string.sub(text, i, i) - pos = math.floor(x + xx - width) + local pos = math.floor(x + xx - width) love.graphics.print(char, pos, y) xx = xx + font:getWidth(char) + spacing end diff --git a/sonic-radiance.love/core/utils/math.lua b/sonic-radiance.love/core/utils/math.lua index 151c525..5112c45 100644 --- a/sonic-radiance.love/core/utils/math.lua +++ b/sonic-radiance.love/core/utils/math.lua @@ -63,7 +63,7 @@ function Math.vector(x1, y1, x2, y2) local vecx, vecy vecx = x2 - x1 - vexy = y2 - y1 + vecy = y2 - y1 return vecx, vecy end diff --git a/sonic-radiance.love/game/abstractmobs/character.lua b/sonic-radiance.love/game/abstractmobs/character.lua index 09bd505..6c24ec9 100644 --- a/sonic-radiance.love/game/abstractmobs/character.lua +++ b/sonic-radiance.love/game/abstractmobs/character.lua @@ -71,8 +71,8 @@ end function AbstractCharacter:setLevel(newlevel) self.level = newlevel local exp, exp_next, exp_current - exp_min = charutils.getExpValue(self.level) - exp_max = charutils.getExpValue(self.level + 1) + local exp_min = charutils.getExpValue(self.level) + local exp_max = charutils.getExpValue(self.level + 1) exp = self.exp self.exp = math.max(math.min(exp, exp_max - 1), exp_min) diff --git a/sonic-radiance.love/game/init.lua b/sonic-radiance.love/game/init.lua index 2e8a302..7e99fc0 100644 --- a/sonic-radiance.love/game/init.lua +++ b/sonic-radiance.love/game/init.lua @@ -64,7 +64,7 @@ end function Game:read(save_id) self.slot = save_id if (self.slot > 0) then - filepath = self:getSaveFile(self.slot, true) + local filepath = self:getSaveFile(self.slot, true) if love.filesystem.exists("save" .. self.slot .. ".save") then local loadedDatas = binser.readFile(filepath) @@ -78,7 +78,7 @@ function Game:write(save_id) if (self.slot > 0) then local data = self:getData() - filepath = self:getSaveFile(self.slot, true) + local filepath = self:getSaveFile(self.slot, true) binser.writeFile(filepath, data) end end @@ -99,7 +99,7 @@ end function Game:resetSaves() for i=1, self.slotNumber do - filepath = self:getSaveFile(i, true) + local filepath = self:getSaveFile(i, true) if love.filesystem.exists("save" .. i .. ".save") then love.filesystem.remove( "save" .. i .. ".save" ) end @@ -111,8 +111,7 @@ function Game:update(dt) end function Game:getTime() - local time = self.gametime - local hours, minute, seconds + local hours, minutes, seconds seconds = math.floor(self.gametime) minutes = math.floor(seconds / 60) hours = math.floor(minutes / 60) diff --git a/sonic-radiance.love/game/loot/pocket.lua b/sonic-radiance.love/game/loot/pocket.lua index 536106b..39cf081 100644 --- a/sonic-radiance.love/game/loot/pocket.lua +++ b/sonic-radiance.love/game/loot/pocket.lua @@ -19,7 +19,7 @@ function Pocket:addItem(item, number) end if (not success) then - itemData = {} + local itemData = {} itemData.name = item itemData.number = number table.insert(self.list, itemData) diff --git a/sonic-radiance.love/scenes/overworld/charsetmanager.lua b/sonic-radiance.love/scenes/overworld/charsetmanager.lua index 52f7a46..2fa72ef 100644 --- a/sonic-radiance.love/scenes/overworld/charsetmanager.lua +++ b/sonic-radiance.love/scenes/overworld/charsetmanager.lua @@ -28,7 +28,7 @@ function Charset:addChar(ii, jj) local charx, chary = (jj-1)*(CHARWIDTH*3), (ii-1)*(CHARHEIGHT*4) local char = {} for i=1, 4 do - animatedDirection = {} + local animatedDirection = {} local running = {} for j=1, 3 do local x, y = charx + ((j-1)*CHARWIDTH), (chary + (i-1)*CHARHEIGHT) diff --git a/sonic-radiance.love/scenes/overworld/screens/menu.lua b/sonic-radiance.love/scenes/overworld/screens/menu.lua index 2491ac3..9d8b753 100644 --- a/sonic-radiance.love/scenes/overworld/screens/menu.lua +++ b/sonic-radiance.love/scenes/overworld/screens/menu.lua @@ -90,7 +90,7 @@ end function menu.BoxedWidget:drawCanvas() love.graphics.draw(self.box, 0, 0) - h = math.floor(self.height / 2) - (self.font:getHeight() / 2) - 1 + local h = math.floor(self.height / 2) - (self.font:getHeight() / 2) - 1 love.graphics.setColor(0, 0, 0, .8) self.font:print(self.label, 17, h, "left") self.font:print(self.label2, self.width - 8, h, "right")