Refactoring and weapons class

This commit is contained in:
Marco Giacomelli 2024-04-24 11:11:16 +02:00
commit c33488fabd
4 changed files with 240 additions and 134 deletions

View file

@ -1,15 +1,71 @@
--[[pod_format="raw",created="2024-04-14 13:41:07",modified="2024-04-14 14:05:57",revision=2]]
include("cirno.lua")
--cd("/cirnofarm/src")
--include("/cirnofarm/src/cirno.lua")
function make_path(name)
local base_path = "/cirnofarm/src/" -- Change this when releasing
return base_path .. name
end
local _modules = {}
function loadfile (filename)
local src = fetch(filename)
if (type(src) ~= "string") then
notify("could not include "..filename)
stop()
return
end
-- https://www.lua.org/manual/5.4/manual.html#pdf-load
-- chunk name (for error reporting), mode ("t" for text only -- no binary chunk loading), _ENV upvalue
-- @ is a special character that tells debugger the string is a filename
local func,err = load(src, "@"..filename, "t", _ENV)
-- syntax error while loading
if (not func) then
send_message(3, {event="report_error", content = "*syntax error"})
send_message(3, {event="report_error", content = tostr(err)})
stop()
return
end
return func
end
function require(name)
local already_imported = _modules[name]
if already_imported ~= nil then
return already_imported
end
local filename = fullpath(name:gsub ('%.', '/') ..'.lua')
local func = loadfile (filename)
local module = func(name)
_modules[name]=module
return module
end
--local strawberry = require(make_path("strawberry"))
--strawberry.func()
local cirno = require(make_path("cirno"))
local mouse_debug = require(make_path("mouse_debug"))
tile_width = 16
tile_height = 16
function _init()
cirno_init()
cirno.init()
end
function _update()
cirno_update()
cirno.update()
end
function _draw()
cls(0)
cirno_draw()
cirno.draw()
mouse_debug.draw(3, tile_width, tile_height)
end