bunch of stuff

This commit is contained in:
Patrick Schwarzer 2025-04-12 10:04:38 +02:00
parent 77c93bf874
commit d220cfb9da
5 changed files with 93 additions and 42 deletions

27
.vscode/launch.json vendored
View file

@ -1,15 +1,28 @@
{ {
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0", "version": "0.2.0",
"configurations": [ "configurations": [
{ {
"type": "lua-local",
"request": "launch", "request": "launch",
"name": "Debug", "name": "Debug",
"program": "${workspaceFolder}/main.lua", "program": {
"type": "node-terminal", "command": "love"
"command": "./love.AppImage . && exit" },
} "args": [
".",
"debug"
],
},
{
"type": "lua-local",
"request": "launch",
"name": "Release",
"program": {
"command": "love"
},
"args": [
".",
],
},
] ]
} }

View file

@ -1,14 +1,24 @@
local test = 1 NAME = "Test"
AUTHOR = "Tarion"
VERSION = 0
local test = 0
local delay = 0 local delay = 0
function Load()
end
function Update(dt, curTime) function Update(dt, curTime)
if (curTime > delay) then end
delay = curTime + 1
function KeyPressed(key)
if (key == "f5") then
test = test + 1 test = test + 1
Sprite("testSprites.png")
end end
end end
function Draw() function Draw()
print("Counter: " .. test, 10, 10) print("Loaded Sprites: " .. test, 10, 10)
end end

View file

Before

Width:  |  Height:  |  Size: 961 B

After

Width:  |  Height:  |  Size: 961 B

Before After
Before After

View file

@ -1,23 +1,41 @@
local curTime = 0 local function CalculateMemoryUsage()
function CurTime()
return curTime
end end
local function LoadSprite(name)
name = "games/" .. name
local info = love.filesystem.getInfo(name)
if (not info) then
error("Failed to load Sprite! ("..name..")")
return
end
virtual.currentMemory = virtual.currentMemory + info.size
local newSprite = love.graphics.newImage(name)
end
-- Establish Sandbox
-- Everything in the table is what the Sandbox has access to
local consoleEnv = { local consoleEnv = {
Load = function() end, NAME = "NULL",
Update = function(dt) end, AUTHOR = "NULL",
Draw = function() end, VERSION = 0,
KeyPressed = love.keypressed,
KeyDown = love.keyboard.wasPressed, Load,
Update,
Draw,
KeyPressed,
Sprite = LoadSprite,
print = love.graphics.print, print = love.graphics.print,
} }
consoleEnv._G = consoleEnv consoleEnv._G = consoleEnv
setmetatable(consoleEnv, { setmetatable(consoleEnv, {
__index = function(_, key) __index = function(_, key)
return function(...) end return function(...) end -- Return an empty function to avoid erroring, not perfect, but works most of the time
end end
}) })
@ -31,32 +49,42 @@ function loadGame(gameName)
if not ok then if not ok then
error("Error running sandbox file (2): " .. execErr) error("Error running sandbox file (2): " .. execErr)
end end
love.window.setTitle(consoleEnv.NAME or "NULL")
end end
local maxScaling = 4 local maxScaling = 4
function love.load() function love.load()
love.window.setTitle("Fantasy Console") love.window.setTitle("Waiting for Game")
love.graphics.setDefaultFilter("nearest", "nearest")
font = love.graphics.newImageFont("font.png", " ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789.:;<=>?-+*/)('&%$#ß!@[ß]^_{|}~", -1)
--font = love.graphics.newFont("monogram.ttf", 16)
--font:setFilter("nearest", "nearest")
-- Console Variables
curTime = 0
scaling = 4 scaling = 4
keysPressed = {}
-- Setup Window
love.graphics.setDefaultFilter("nearest", "nearest")
font = love.graphics.newImageFont("font.png", " ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789.:;<=>?-+*/)('&%$#ß!@[ß]^_{|}~", -1)
love.window.updateWindow() love.window.updateWindow()
love.keyboard.keysPressed = {} -- Create Virtual Console
virtual = {
maxMemory = 16000,
currentMemory = 0,
loadedSprites = {},
loadedSounds = {},
loadedFonts = {},
}
loadGame("test") loadGame("test")
-- Track memory usage using this if (consoleEnv.Load) then
info = love.filesystem.getInfo( "font.png" ) consoleEnv.Load()
end
print(info.size)
end end
function love.keypressed(key) function love.keypressed(key)
@ -64,15 +92,15 @@ function love.keypressed(key)
love.event.quit() love.event.quit()
end end
love.keyboard.keysPressed[key] = true keysPressed[key] = true
if (consoleEnv.WasKeyPressed) then if (consoleEnv.KeyPressed) then
consoleEnv.WasKeyPressed(key) consoleEnv.KeyPressed(key)
end end
end end
function love.keyboard.wasPressed(key) function love.keyboard.wasPressed(key)
return love.keyboard.keysPressed[key] return keysPressed[key]
end end
function love.window.updateWindow() function love.window.updateWindow()
@ -92,7 +120,7 @@ function love.update(dt)
love.window.updateWindow() love.window.updateWindow()
end end
love.keyboard.keysPressed = {} keysPressed = {}
if (consoleEnv.Update) then if (consoleEnv.Update) then
consoleEnv.Update(dt, curTime) consoleEnv.Update(dt, curTime)
@ -104,7 +132,7 @@ function love.draw()
love.graphics.setFont(font) love.graphics.setFont(font)
love.graphics.print("0/32 KB used", 3, 0) love.graphics.print(virtual.currentMemory/1000 .. "/" .. virtual.maxMemory/1000 .. " KB", 2, 2)
if (consoleEnv.Draw) then if (consoleEnv.Draw) then
consoleEnv.Draw() consoleEnv.Draw()

Binary file not shown.