From 7557a1da192f1ba5d86301730e6ef21fb4d755be Mon Sep 17 00:00:00 2001 From: Kazhnuz Date: Sun, 16 Jun 2019 17:56:55 +0200 Subject: [PATCH] refactor(main): remove every function already provided by gamecore --- CHANGELOG.md | 5 + imperium-porcorum.love/libs/classic.lua | 68 ------------ .../libs/loveutils/filesystem.lua | 16 --- .../libs/loveutils/graphics.lua | 64 ----------- .../libs/loveutils/init.lua | 7 -- .../libs/loveutils/math.lua | 104 ------------------ imperium-porcorum.love/main.lua | 21 ---- 7 files changed, 5 insertions(+), 280 deletions(-) delete mode 100644 imperium-porcorum.love/libs/classic.lua delete mode 100644 imperium-porcorum.love/libs/loveutils/filesystem.lua delete mode 100644 imperium-porcorum.love/libs/loveutils/graphics.lua delete mode 100644 imperium-porcorum.love/libs/loveutils/init.lua delete mode 100644 imperium-porcorum.love/libs/loveutils/math.lua diff --git a/CHANGELOG.md b/CHANGELOG.md index a444582..35acb6e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -17,6 +17,11 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), - **levels:** use the right drawing method for debris' texture +### Removed + +- **main:** All functions already provided by gamecore have been removed. + +- **libs:** All librairies provided by gamecore have been removed from the old `libs/` path. ## Imperium-Porcorum 0.0.1 diff --git a/imperium-porcorum.love/libs/classic.lua b/imperium-porcorum.love/libs/classic.lua deleted file mode 100644 index cbd6f81..0000000 --- a/imperium-porcorum.love/libs/classic.lua +++ /dev/null @@ -1,68 +0,0 @@ --- --- classic --- --- Copyright (c) 2014, rxi --- --- This module is free software; you can redistribute it and/or modify it under --- the terms of the MIT license. See LICENSE for details. --- - - -local Object = {} -Object.__index = Object - - -function Object:new() -end - - -function Object:extend() - local cls = {} - for k, v in pairs(self) do - if k:find("__") == 1 then - cls[k] = v - end - end - cls.__index = cls - cls.super = self - setmetatable(cls, self) - return cls -end - - -function Object:implement(...) - for _, cls in pairs({...}) do - for k, v in pairs(cls) do - if self[k] == nil and type(v) == "function" then - self[k] = v - end - end - end -end - - -function Object:is(T) - local mt = getmetatable(self) - while mt do - if mt == T then - return true - end - mt = getmetatable(mt) - end - return false -end - - -function Object:__tostring() - return "Object" -end - - -function Object:__call(...) - local obj = setmetatable({}, self) - obj:new(...) - return obj -end - - -return Object diff --git a/imperium-porcorum.love/libs/loveutils/filesystem.lua b/imperium-porcorum.love/libs/loveutils/filesystem.lua deleted file mode 100644 index 3d38e27..0000000 --- a/imperium-porcorum.love/libs/loveutils/filesystem.lua +++ /dev/null @@ -1,16 +0,0 @@ -local Filesystem = {} - -function Filesystem.exists(filepath) - local info = love.filesystem.getInfo( filepath ) - local exists = false - - if (info == nil) then - exists = false - else - exists = true - end - - return exists -end - -return Filesystem diff --git a/imperium-porcorum.love/libs/loveutils/graphics.lua b/imperium-porcorum.love/libs/loveutils/graphics.lua deleted file mode 100644 index aee9777..0000000 --- a/imperium-porcorum.love/libs/loveutils/graphics.lua +++ /dev/null @@ -1,64 +0,0 @@ -local Graphics = {} - -function Graphics.resetColor() - love.graphics.setColor(1,1,1,1) -end - -function Graphics.box(x, y, w, h) - local x = math.floor(x) - local y = math.floor(y) - local w = math.floor(w) - local h = math.floor(h) - local a = a or 1 - - local r, g, b, a = love.graphics.getColor( ) - - love.graphics.setColor(r, g, b, 0.3 * a) - love.graphics.rectangle("fill", x, y, w, h) - - love.graphics.setColor(r, g, b, a) - love.graphics.rectangle("line", x, y, w, h) -end - -function Graphics.print(text, x, y, align, r, sx, sy, ox, oy, kx, ky) - local width - local font = love.graphics.getFont() - width = font:getWidth(text) - - if align == "center" then - width = (width/2) - elseif align == "right" then - width = width - else - width = 0 - end - - love.graphics.print(text, x - (width), y, r, sx, sy, ox, oy, kx, ky) -end - -function Graphics.printWithSpacing(text, x, y, spacing, align, r, sx, sy, ox, oy, kx, ky) - -- DO NOT USE THIS FUNCTION IN A "UPDATE" FUNCTION ! - -- it's pretty heavy to use as it use a loop to get every character in a text - local font = love.graphics.getFont() - local xx = 0 - local lenght = string.len(text) - local basewidth = font:getWidth(text) - local width = basewidth + (spacing * lenght) - - if align == "center" then - width = (width/2) - elseif align == "right" then - width = width - else - width = 0 - end - - for i=1, lenght do - local char = string.sub(text, i, i) - pos = math.floor(x + xx - width) - love.graphics.print(char, pos, y) - xx = xx + font:getWidth(char) + spacing - end -end - -return Graphics diff --git a/imperium-porcorum.love/libs/loveutils/init.lua b/imperium-porcorum.love/libs/loveutils/init.lua deleted file mode 100644 index 0f6ea3c..0000000 --- a/imperium-porcorum.love/libs/loveutils/init.lua +++ /dev/null @@ -1,7 +0,0 @@ -local cwd = (...):gsub('%.init$', '') .. "." - -return { - math = require(cwd .. "math"), - graphics = require(cwd .. "graphics"), - filesystem = require(cwd .. "filesystem") -} diff --git a/imperium-porcorum.love/libs/loveutils/math.lua b/imperium-porcorum.love/libs/loveutils/math.lua deleted file mode 100644 index 7738f68..0000000 --- a/imperium-porcorum.love/libs/loveutils/math.lua +++ /dev/null @@ -1,104 +0,0 @@ -local Math = {} - -function Math.wrap(x, startnumber, endnumber) - local delta = endnumber - startnumber - if delta < 0 then - err("endnumber must be larger than startnumber") - end - while x >= endnumber do - x = x - delta - end - - while x < startnumber do - x = x + delta - end - - return x -end - -function Math.sign(x) - if (x < 0) then - return -1 - elseif (x > 0) then - return 1 - else - return 0 - end -end - -function Math.round(num) - return math.floor(num + 0.5) -end - -function Math.vector(x1, y1, x2, y2) - local vecx, vecy - - vecx = x2 - x1 - vexy = y2 - y1 - - return vecx, vecy -end - -function Math.getMiddlePoint(x1, y1, x2, y2) - local newx, newy, vecx, vecy - - vecx = math.max(x1, x2) - math.min(x1, x2) - vecy = math.max(y1, y2) - math.min(y1, y2) - - newx = math.min(x1, x2) + (vecx / 2) - newy = math.min(y1, y2) + (vecy / 2) - - return newx, newy -end - -function Math.pointDistance(x1, y1, x2, y2) - local vecx, vecy - - vecx = math.max(x1, x2) - math.min(x1, x2) - vecy = math.max(y1, y2) - math.min(y1, y2) - - return math.sqrt(vecx^2 + vecy^2) - -end - -function Math.pointDirection(x1,y1,x2,y2) - local vecx, vecy, angle - vecy = y2 - y1 - vecx = x2 - x1 - angle = math.atan2(vecy, vecx) - - return angle -end - -function Math.numberToString(x, length) - local length = length or 1 - local string = "" - local x = x - if (x >= math.pow(10, length)) then - x = unitsNumber*10 - 1 - string = string .. x - else - for i=1, (length-1) do - if (x < math.pow(10, length-i)) then - string = string .. "0" - end - end - string = string .. x - end - return string -end - -function Math.floorCoord(x, y) - return math.floor(x), math.floor(y) -end - -function Math.pixeliseCoord(x, y, factor) - x, y = Math.floorCoord(x / factor, y / factor) - - x = x * factor - y = y * factor - - return x, y -end - -return Math diff --git a/imperium-porcorum.love/main.lua b/imperium-porcorum.love/main.lua index dcbc9b8..eabff10 100644 --- a/imperium-porcorum.love/main.lua +++ b/imperium-porcorum.love/main.lua @@ -1,18 +1,13 @@ -- On commence par charger les différentes librairies utilisées par le jeu, -- afin d'y avoir accès dans toutes les scènes et les modules du jeu -Object = require "libs.classic" local Core = require "core" local Game = require "game" -utils = require "libs.loveutils" -- On charge après cela les différentes scènes, qui sont les différents types -- d'écrant avec lesquels le joueur interagira scenes = require "scenes" -love.graphics.setDefaultFilter( "nearest", "nearest", 1 ) -io.stdout:setvbuf("no") - function love.load() -- On charge la scene de départ (pour l'instant le menu, bientôt une scene spéciale pour ça) core = Core() game = Game() @@ -20,19 +15,3 @@ function love.load() -- On charge la scene de départ (pour l'instant le menu, b scenes.MainMenu() end - -function love.update(dt) - core:update(dt) -end - -function love.draw() - core:draw() -end - -function love.mousemoved(x, y, dx, dy) - core:mousemoved(x, y, dx, dy) -end - -function love.mousepressed( x, y, button, istouch ) - core:mousepressed(x, y, button, istouch) -end