From 4947daa76b38c9af9cbdc48c8f40be12a22f733a Mon Sep 17 00:00:00 2001 From: "Squishy (C6H12O6+NaCl+H2O)" <106439598+SweetSea-ButImNotSweet@users.noreply.github.com> Date: Mon, 20 May 2024 23:42:08 +0700 Subject: [PATCH] Design a error screen --- main.lua | 129 +++++++++++++++++++++++++++++++++++++++++++++++++ scene/game.lua | 3 +- 2 files changed, 130 insertions(+), 2 deletions(-) diff --git a/main.lua b/main.lua index 677a606..0b9a80e 100644 --- a/main.lua +++ b/main.lua @@ -22,6 +22,7 @@ LOADING_IMAGE_FILE = love.graphics.newImage('res/loading.png') --- Show the loading text while we are loading resources
--- **WARNING**: should only be used while loading the game! function ShowLoadingText(thing) + love.resize(love.graphics.getDimensions()) love.graphics.replaceTransform(GLOBAL_TRANSFORM) love.graphics.setFont(love.graphics.newFont(20)) love.graphics.clear() @@ -161,6 +162,7 @@ function love.keypressed(key, scancode) elseif scancode == "f2" and SCENE.title ~= "Input Config" and SCENE.title ~= "Game" then SCENE = InputConfigScene() elseif scancode == "f12" then REQUEST_BREAK() + elseif scancode == "f11" then error("TEST") -- function keys are reserved elseif string.match(scancode, "^f[1-9]$") or string.match(scancode, "^f1[0-2]+$") then return @@ -368,6 +370,133 @@ function love.run() end end +function love.errorhandler(msg) + local showScreenshot = false + local errorCopied = false + + -- Reset audio. + if love.audio then love.audio.stop() end + + -- Render everything again in a canva + love.graphics.origin() + local screenshot_canva, screenshot_canva_scale + local ok, _ = pcall(function() + if love.graphics.getSystemLimits().texturesize >= 1280 then + screenshot_canva = love.graphics.newCanvas(1280, 960) + screenshot_canva_scale = 0.5 + else + error() + end + end) + if not ok then + screenshot_canva = love.graphics.newCanvas(640, 480) + screenshot_canva_scale = 1 + end + + love.graphics.setCanvas(screenshot_canva) + pcall( + function() + love.graphics.origin() + local transformer = love.math.newTransform(0, 0, 0, 2, 2) + love.graphics.replaceTransform(transformer) + SCENE:render() + end + ) + love.graphics.setCanvas() + + -- Handling the error + local err={"Error:"..msg} + local c=2 + for l in debug.traceback("",2):gmatch("(.-)\n") do + if c>2 then + if not l:find("boot") then + err[c]=l:gsub("^\t*","") + c=c+1 + end + else + err[2]="Traceback" + c=3 + end + end + print("\n"..table.concat(err,"\n",1,c-2)) + local p = table.concat(err,"\n", 4) + + local function draw() + love.graphics.origin() + love.graphics.replaceTransform(GLOBAL_TRANSFORM) + love.graphics.clear() + + love.graphics.setColor(1, 1, 1) + love.graphics.draw(screenshot_canva, 0, 0, 0, screenshot_canva_scale) + + if not showScreenshot then + love.graphics.setColor(0, 0, 0, 0.75) + love.graphics.rectangle("fill", 0, 0, 640, 480) + drawText([[ +OH NO! Tromi has crashed. +Since this is not the official port, please do not report any bugs to mycophobia. +Instead, report this to me via my Discord ``sweetsea`` with a screenshot of this. + +REMEMBER TO SCREENSHOT BECAUSE ERROR INFO IS NOT SAVED! + +Ctrl + C: copy the error info | If you click or tap, a window appear with 4 options: +Space : show/hide screenshot | OK: Quit Copy: copy error info +Escape : Quit | Cancel: Go back Show: show/hide screenshot + +Traceback:]]..(errorCopied and " (Copied to clipboard)" or ""), + 20, 10, 620, "left") + drawText(p, 40, 200, 600, "left") + end + + love.graphics.present() + end + + local fullErrorText = p + local function copyToClipboard() + love.system.setClipboardText(fullErrorText) + errorCopied = true + end + + local buttons = {"OK", "Cancel", "Copy", "Show"} + + return function() + love.event.pump() + + for e, a, b, c in love.event.poll() do + if e == "quit" then + return 1 + elseif e == "keypressed" and a == "escape" then + return 1 + elseif e == "keypressed" and a == "c" and love.keyboard.isDown("lctrl", "rctrl") then + copyToClipboard() + elseif e == "keypressed" and a == "space" then + showScreenshot = not showScreenshot + elseif e == "keypressed" and a == "f4" then + SETTINGS["fullscreen"] = not SETTINGS["fullscreen"] + love.window.setFullscreen(SETTINGS["fullscreen"]) + elseif e == "touchpressed" or e == "mousepressed" then + local pressed = love.window.showMessageBox("Quit Tromi?", "Remember to save a copy of screenshot, since they are not saved!", buttons) + if pressed == 1 then + return 1 + elseif pressed == 3 then + copyToClipboard() + elseif pressed == 4 then + showScreenshot = not showScreenshot + end + elseif e == "resize" then + love.resize(love.graphics.getDimensions()) + end + end + + draw() + + if love.timer then + love.timer.sleep(0.1) + end + end + +end + local minos = {'R_d', 'O_d', 'Y_d', 'G_d', 'C_d', 'B_d', 'M_d'} local main_bg_grid = {} for x=1, 40 do diff --git a/scene/game.lua b/scene/game.lua index b298b7d..537463c 100644 --- a/scene/game.lua +++ b/scene/game.lua @@ -4,8 +4,7 @@ GameScene.title = "Game" local tas = false function GameScene:new(player_name, replay_file, replay_grade) - local game_mode = require 'game.gamemode' - local ruleset + game_mode = require 'game.gamemode' VCTRL[9].show = false; VCTRL[10].show = false -- Hide SELECT and QUIT button if PENTO_MODE then