mirror of
https://gitea.com/SweetSea-ButImNotSweet/tromi_mobile.git
synced 2025-01-08 17:33:09 +08:00
Update modules
This commit is contained in:
@@ -133,10 +133,9 @@ function Grid:applyPiece(piece)
|
|||||||
self:applyBigPiece(piece)
|
self:applyBigPiece(piece)
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
offsets = piece:getBlockOffsets()
|
for index, offset in pairs(piece:getBlockOffsets()) do
|
||||||
for index, offset in pairs(offsets) do
|
local x = piece.position.x + offset.x
|
||||||
x = piece.position.x + offset.x
|
local y = piece.position.y + offset.y
|
||||||
y = piece.position.y + offset.y
|
|
||||||
if y + 1 > 0 and y < self.height then
|
if y + 1 > 0 and y < self.height then
|
||||||
self.grid[y+1][x+1] = {
|
self.grid[y+1][x+1] = {
|
||||||
skin = piece.skin,
|
skin = piece.skin,
|
||||||
|
|||||||
@@ -137,15 +137,16 @@ local global_toggle=false
|
|||||||
VCTRL={}
|
VCTRL={}
|
||||||
VCTRL.focus=nil -- Focusing buttons
|
VCTRL.focus=nil -- Focusing buttons
|
||||||
|
|
||||||
|
---@type table
|
||||||
---@class VCTRL.data
|
---@class VCTRL.data
|
||||||
---@field type string
|
---@field type 'button'
|
||||||
---@field x number
|
---@field x number
|
||||||
---@field y number
|
---@field y number
|
||||||
---@field shape string
|
---@field shape? string
|
||||||
---@field key string
|
---@field key? string
|
||||||
---@field iconSize number
|
---@field iconSize? number
|
||||||
---@field alpha number
|
---@field alpha? number
|
||||||
---@field show boolean
|
---@field show? boolean
|
||||||
|
|
||||||
---@param ... VCTRL.data
|
---@param ... VCTRL.data
|
||||||
---Adding (multiple) virtual button(s)
|
---Adding (multiple) virtual button(s)
|
||||||
|
|||||||
@@ -17,7 +17,7 @@ local function checkColorTableValidation(C)
|
|||||||
end
|
end
|
||||||
|
|
||||||
---@class BUTTON.button
|
---@class BUTTON.button
|
||||||
---@field text? string # Name of the button, will be used to show
|
---@field text? string|function # Name of the button, will be used to show
|
||||||
---@field textOrientation? "center"|"justify"|"left"|"right"
|
---@field textOrientation? "center"|"justify"|"left"|"right"
|
||||||
---
|
---
|
||||||
---@field x? number # Position of the button (x, y, w, h)
|
---@field x? number # Position of the button (x, y, w, h)
|
||||||
@@ -86,14 +86,16 @@ function button:draw()
|
|||||||
love.graphics.setColor(self.textColor)
|
love.graphics.setColor(self.textColor)
|
||||||
love.graphics.setFont(self.font)
|
love.graphics.setFont(self.font)
|
||||||
|
|
||||||
|
local text = type(self.text) == 'function' and self.text() or self.text
|
||||||
|
|
||||||
local lineAmount
|
local lineAmount
|
||||||
do
|
do
|
||||||
local _, t = self.font:getWrap(self.text, self.w)
|
local _, t = self.font:getWrap(text, self.w)
|
||||||
lineAmount = #t
|
lineAmount = #t
|
||||||
end
|
end
|
||||||
local textHeight = self.font:getHeight() * (lineAmount * 0.5)
|
local textHeight = self.font:getHeight() * (lineAmount * 0.5)
|
||||||
local textPos = self.y + (self.h * 0.5) - textHeight
|
local textPos = self.y + (self.h * 0.5) - textHeight
|
||||||
love.graphics.printf(self.text, self.x, textPos, self.w, self.textOrientation)
|
love.graphics.printf(text, self.x, textPos, self.w, self.textOrientation)
|
||||||
|
|
||||||
love.graphics.setColor(self.borderColor)
|
love.graphics.setColor(self.borderColor)
|
||||||
love.graphics.rectangle('line', self.x, self.y, self.w, self.h, self.r)
|
love.graphics.rectangle('line', self.x, self.y, self.w, self.h, self.r)
|
||||||
@@ -150,7 +152,11 @@ local BUTTON = {}
|
|||||||
---***WARNING! THIS FUNCTION WILL RAISE EXCEPTION IF DATA IS INVALID!***
|
---***WARNING! THIS FUNCTION WILL RAISE EXCEPTION IF DATA IS INVALID!***
|
||||||
function BUTTON.checkDataValidation(D, safe)
|
function BUTTON.checkDataValidation(D, safe)
|
||||||
if not safe then
|
if not safe then
|
||||||
assert(type(D.text) == "string","[text] is missing, or you just passed an empty data?")
|
if type(D.text) == 'function' then
|
||||||
|
assert(type(D.text()) == 'string', "[text] is a function but it doesn't return any string?!")
|
||||||
|
elseif type(D.text) ~= 'string' then
|
||||||
|
error("[text] must be a string or a function returns string, got "..type(D.text))
|
||||||
|
end
|
||||||
|
|
||||||
assert(type(D.x) == "number" , "[x] must be a integer")
|
assert(type(D.x) == "number" , "[x] must be a integer")
|
||||||
assert(type(D.y) == "number" , "[y] must be a integer")
|
assert(type(D.y) == "number" , "[y] must be a integer")
|
||||||
@@ -178,7 +184,7 @@ function BUTTON.checkDataValidation(D, safe)
|
|||||||
end
|
end
|
||||||
|
|
||||||
---@class BUTTON.newData
|
---@class BUTTON.newData
|
||||||
---@field text string # Name of the button, will be used to show
|
---@field text string|function # Name of the button, will be used to show. If function provided, it should return the string!
|
||||||
---@field textOrientation? "center"|"justify"|"left"|"right"
|
---@field textOrientation? "center"|"justify"|"left"|"right"
|
||||||
---
|
---
|
||||||
---@field x number # Position of the button (x, y, w, h)
|
---@field x number # Position of the button (x, y, w, h)
|
||||||
@@ -210,6 +216,8 @@ end
|
|||||||
---@nodiscard
|
---@nodiscard
|
||||||
---Create a new button, provide you a table with 4 functions inside: draw and update, press and release<br>
|
---Create a new button, provide you a table with 4 functions inside: draw and update, press and release<br>
|
||||||
---You need to put them into intended callbacks :)
|
---You need to put them into intended callbacks :)
|
||||||
|
---
|
||||||
|
---Remember to fill 5 necessary parameters: name, x, y, w and h
|
||||||
function BUTTON.new(D)
|
function BUTTON.new(D)
|
||||||
local B = setmetatable(D, button)
|
local B = setmetatable(D, button)
|
||||||
BUTTON.checkDataValidation(B)
|
BUTTON.checkDataValidation(B)
|
||||||
@@ -231,7 +239,7 @@ end
|
|||||||
-- < EXTRA GENERAL OPTIONS >
|
-- < EXTRA GENERAL OPTIONS >
|
||||||
|
|
||||||
---Draw all buttons in provided list
|
---Draw all buttons in provided list
|
||||||
---@param list table<BUTTON.button>
|
---@param list table<any,BUTTON.button>
|
||||||
function BUTTON.draw(list)
|
function BUTTON.draw(list)
|
||||||
for _, v in pairs(list) do v:draw() end
|
for _, v in pairs(list) do v:draw() end
|
||||||
end
|
end
|
||||||
|
|||||||
11
load.lua
11
load.lua
@@ -1,6 +1,7 @@
|
|||||||
-- Bigint library
|
-- Bigint library
|
||||||
bigint = require "libs.bigint.bigint"
|
bigint = require "libs.bigint.bigint"
|
||||||
number_names = require "libs.bigint.named-powers-of-ten"
|
number_names = require "libs.bigint.named-powers-of-ten"
|
||||||
|
require "libs.simple-slider"
|
||||||
|
|
||||||
-- Fonts
|
-- Fonts
|
||||||
FONT_tromi = love.graphics.newFont('res/fonts/monofonto rg.otf', 28)
|
FONT_tromi = love.graphics.newFont('res/fonts/monofonto rg.otf', 28)
|
||||||
@@ -25,13 +26,15 @@ BUTTON.setDefaultOption{
|
|||||||
love.graphics.rectangle('fill', self.x, self.y, self.w, self.h, self.r)
|
love.graphics.rectangle('fill', self.x, self.y, self.w, self.h, self.r)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
local text = type(self.text) == 'function' and self.text() or self.text
|
||||||
|
|
||||||
local lineAmount
|
local lineAmount
|
||||||
do
|
do
|
||||||
local _, t
|
local _, t
|
||||||
if need_big_font then
|
if need_big_font then
|
||||||
_, t = FONT_big:getWrap(self.text, self.w * 2)
|
_, t = FONT_big:getWrap(text, self.w * 2)
|
||||||
else
|
else
|
||||||
_, t = FONT_tromi:getWrap(self.text, self.w * 2)
|
_, t = FONT_tromi:getWrap(text, self.w * 2)
|
||||||
end
|
end
|
||||||
lineAmount = #t
|
lineAmount = #t
|
||||||
end
|
end
|
||||||
@@ -42,9 +45,9 @@ BUTTON.setDefaultOption{
|
|||||||
local textPos = self.y + (self.h * 0.5) - textHeight
|
local textPos = self.y + (self.h * 0.5) - textHeight
|
||||||
|
|
||||||
if need_big_font then
|
if need_big_font then
|
||||||
drawBigText(self.text, self.x, textPos, self.w, 'center')
|
drawBigText(text, self.x, textPos, self.w, 'center')
|
||||||
else
|
else
|
||||||
drawText(self.text, self.x, textPos, self.w, 'center')
|
drawText(text, self.x, textPos, self.w, 'center')
|
||||||
end
|
end
|
||||||
|
|
||||||
love.graphics.setColor(1, 1, 1, 0.8)
|
love.graphics.setColor(1, 1, 1, 0.8)
|
||||||
|
|||||||
21
main.lua
21
main.lua
@@ -1,9 +1,6 @@
|
|||||||
if os.getenv("LOCAL_LUA_DEBUGGER_VSCODE")=="1" then
|
if os.getenv("LOCAL_LUA_DEBUGGER_VSCODE")=="1" then
|
||||||
lldebugger=require('lldebugger')
|
LLDEBUGGER=require('lldebugger')
|
||||||
lldebugger.start()
|
LLDEBUGGER.start()
|
||||||
REQUEST_BREAK=lldebugger.requestBreak
|
|
||||||
else
|
|
||||||
REQUEST_BREAK=function()end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
require 'funcs'
|
require 'funcs'
|
||||||
@@ -97,10 +94,9 @@ function love.draw()
|
|||||||
love.graphics.push()
|
love.graphics.push()
|
||||||
|
|
||||||
SCENE:render()
|
SCENE:render()
|
||||||
|
|
||||||
-- -- Grid system
|
-- -- Grid system
|
||||||
-- local grid_width, grid_height = 40, 20
|
-- local grid_width, grid_height = 40, 20
|
||||||
-- love.graphics.replaceTransform(GLOBAL_TRANSFORM)
|
|
||||||
|
|
||||||
-- love.graphics.setColor(1,1,1,0.5)
|
-- love.graphics.setColor(1,1,1,0.5)
|
||||||
-- love.graphics.setLineWidth(1)
|
-- love.graphics.setLineWidth(1)
|
||||||
-- -- From 0 to X
|
-- -- From 0 to X
|
||||||
@@ -112,6 +108,15 @@ function love.draw()
|
|||||||
-- love.graphics.line(0, grid_height * iy, 640, grid_height * iy)
|
-- love.graphics.line(0, grid_height * iy, 640, grid_height * iy)
|
||||||
-- end
|
-- end
|
||||||
|
|
||||||
|
local x, y = GLOBAL_TRANSFORM:inverseTransformPoint(love.mouse.getPosition())
|
||||||
|
love.graphics.setColor(0, 0, 0, 0.8)
|
||||||
|
love.graphics.rectangle("fill", 5, 450, 115, 25)
|
||||||
|
drawText(string.format("X: %.1d; Y: %.1d", x, y), 10, 455, 110, "left")
|
||||||
|
|
||||||
|
love.graphics.setColor(1, 1, 1, 1)
|
||||||
|
love.graphics.setLineWidth(2)
|
||||||
|
love.graphics.rectangle("line", 0, 0, 640, 480)
|
||||||
|
|
||||||
love.graphics.pop()
|
love.graphics.pop()
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -361,7 +366,7 @@ function love.run()
|
|||||||
end
|
end
|
||||||
|
|
||||||
function love.errorhandler(msg)
|
function love.errorhandler(msg)
|
||||||
local msg = msg or "REV! BÀ ĂN CÁI TỜ TIN NHẮN LỖI RỒI À?!"
|
local msg = msg or "I don't know if mycophobia's real name is \"mycophobiatrophilusiania\" or not.\nBUT WHO ATE THE ERROR MESSAGE?! DTET_ENJOYER, DID YOU?\n"
|
||||||
local showScreenshot = false
|
local showScreenshot = false
|
||||||
local errorCopied = false
|
local errorCopied = false
|
||||||
local enter_fullscreen = SETTINGS and SETTINGS["fullscreen"] or false
|
local enter_fullscreen = SETTINGS and SETTINGS["fullscreen"] or false
|
||||||
|
|||||||
Reference in New Issue
Block a user