Skip to content

Commit

Permalink
Try to compile Teal project. Gooi not used anymore.
Browse files Browse the repository at this point in the history
  • Loading branch information
nagolove committed Apr 13, 2021
1 parent 84386af commit 4863f26
Show file tree
Hide file tree
Showing 23 changed files with 1,100 additions and 772 deletions.
9 changes: 5 additions & 4 deletions alignedlabels.lua
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
local _tl_compat; if (tonumber((_VERSION or ''):match('[%d.]*$')) or 0) < 5.3 then local p, m = pcall(require, 'compat53.module'); if p then _tl_compat = m end end; local assert = _tl_compat and _tl_compat.assert or assert; local ipairs = _tl_compat and _tl_compat.ipairs or ipairs; local pairs = _tl_compat and _tl_compat.pairs or pairs; local string = _tl_compat and _tl_compat.string or string; require("love")
local _tl_compat; if (tonumber((_VERSION or ''):match('[%d.]*$')) or 0) < 5.3 then local p, m = pcall(require, 'compat53.module'); if p then _tl_compat = m end end; local assert = _tl_compat and _tl_compat.assert or assert; local ipairs = _tl_compat and _tl_compat.ipairs or ipairs; local math = _tl_compat and _tl_compat.math or math; local pairs = _tl_compat and _tl_compat.pairs or pairs; local string = _tl_compat and _tl_compat.string or string; require("love")

local g = love.graphics

Expand Down Expand Up @@ -82,15 +82,16 @@ function AlignedLabels:draw(x, y)
g.print(v, i - self.font:getWidth(v) / 2, y)
i = i + dw
elseif type(v) == "table" then
local width = 0
local width = 0.
for _, g in ipairs(v) do
width = width + self.font:getWidth(g)
end
assert(#(v) == #self.colors[k])

assert(#(v) == #self.colors[math.floor(k)])
local xpos = i - width / 2
for j, p in pairs(v) do

g.setColor(self.colors[k][j])
g.setColor(self.colors[math.floor(k)][math.floor(j)])
g.print(p, xpos, y)
xpos = xpos + self.font:getWidth(p)
end
Expand Down
9 changes: 5 additions & 4 deletions alignedlabels.tl
Original file line number Diff line number Diff line change
Expand Up @@ -78,19 +78,20 @@ function AlignedLabels:draw(x: number, y: number)
g.setFont(self.font)
for k, v in pairs(self.data as {any:any}) do
if type(v) == "string" then
g.setColor(self.colors[k as number])
g.setColor(self.colors[k as integer])
g.print(v as string, i - self.font:getWidth(v as string) / 2, y)
i = i + dw
elseif type(v) == "table" then
local width = 0
local width = 0.
for _, g in ipairs(v as {string}) do
width = width + self.font:getWidth(g)
end
assert(#(v as {string}) == #self.colors[k as number])
--assert(#(v as {string}) == #self.colors[k as number])
assert(#(v as {string}) == #self.colors[math.floor(k as number)])
local xpos = i - width / 2
for j, p in pairs(v as {any:any}) do
--print(type(self.colors[k]), inspect(self.colors[k]), k, j)
g.setColor(self.colors[k as number][j as number])
g.setColor(self.colors[math.floor(k as number)][math.floor(j as number)])
g.print(p as string, xpos, y)
xpos = xpos + self.font:getWidth(p as string)
end
Expand Down
8 changes: 4 additions & 4 deletions background.lua
Original file line number Diff line number Diff line change
Expand Up @@ -173,9 +173,9 @@ function Block:process(dt)


self.active = false
self.back.blocks[self.xidx][self.yidx] = {}
self.back.blocks[math.floor(self.xidx)][math.floor(self.yidx)] = {}

self.back.blocks[self.newXidx][self.newYidx] = self
self.back.blocks[math.floor(self.newXidx)][math.floor(self.newYidx)] = self
self.oldXidx, self.oldYidx = self.xidx, self.yidx
self.xidx = self.newXidx
self.yidx = self.newYidx
Expand Down Expand Up @@ -291,7 +291,7 @@ function Background:fillGrid()

local fieldWidth, fieldHeight = #self.blocks, #self.blocks[1]
self.execList = {}
for i = 1, self.emptyNum do
for _ = 1, self.emptyNum do

local xidx = math.random(1, fieldWidth)
local yidx = math.random(1, fieldHeight)
Expand Down Expand Up @@ -325,7 +325,7 @@ function Background:update(dt)
print(string.format("v.xidx = %d, v.yidx = %d", v.xidx, v.yidx))


local x, y = self:findDirection(xidx, yidx)
local x, y = self:findDirection(math.floor(xidx), math.floor(yidx))



Expand Down
12 changes: 6 additions & 6 deletions background.tl
Original file line number Diff line number Diff line change
Expand Up @@ -173,9 +173,9 @@ function Block:process(dt: number): boolean
-- приехали
-- флаг ничего не делает, влияет только на рисовку обводки блока.
self.active = false
self.back.blocks[self.xidx][self.yidx] = {}
self.back.blocks[math.floor(self.xidx)][math.floor(self.yidx)] = {}
--print("self.newXidx, self.newYidx", self.newXidx, self.newYidx)
self.back.blocks[self.newXidx][self.newYidx] = self
self.back.blocks[math.floor(self.newXidx)][math.floor(self.newYidx)] = self
self.oldXidx, self.oldYidx = self.xidx, self.yidx
self.xidx = self.newXidx
self.yidx = self.newYidx
Expand All @@ -186,7 +186,7 @@ function Block:process(dt: number): boolean
return ret
end

function Background:get(xidx: number, yidx: number): Block
function Background:get(xidx: integer, yidx: integer): Block
local firstColumn = self.blocks[1]
--print("xidx, yidx", xidx, yidx)
if xidx >= 1 and xidx <= #self.blocks and
Expand All @@ -203,7 +203,7 @@ end
-- Как можно разделить функцию на две части?
-- Скажем одна делает обращение к массиву с проверкой границ и отладочным
-- выводом, а другая - занимается поиском подходящей ячейки.
function Background:findDirection(xidx: number, yidx: number): number, number
function Background:findDirection(xidx: integer, yidx: integer): integer, integer
local x, y = xidx, yidx
-- почему-то иногда возвращает не измененный результат, тот же, что и ввод.
-- приводит к падению программы
Expand Down Expand Up @@ -291,7 +291,7 @@ function Background:fillGrid()

local fieldWidth, fieldHeight = #self.blocks, #self.blocks[1]
self.execList = {}
for i = 1, self.emptyNum do
for _ = 1, self.emptyNum do
-- случайный пустой блок, куда будет двигаться сосед
local xidx = math.random(1, fieldWidth)
local yidx = math.random(1, fieldHeight)
Expand Down Expand Up @@ -325,7 +325,7 @@ function Background:update(dt: number)
print(string.format("v.xidx = %d, v.yidx = %d", v.xidx, v.yidx))

-- поиск индексов нового блока по новым рассчитанным индексам
local x, y = self:findDirection(xidx, yidx)
local x, y = self:findDirection(math.floor(xidx), math.floor(yidx))
--print(string.format("x - xidx = %d, y - yidx = %d", xidx, yidx))
--print(string.format("xidx = %d, yidx = %d", xidx, yidx))
--print(string.format("xidx - x = %d, yidx - y = %d",
Expand Down
63 changes: 53 additions & 10 deletions cmn.lua
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
local _tl_compat; if (tonumber((_VERSION or ''):match('[%d.]*$')) or 0) < 5.3 then local p, m = pcall(require, 'compat53.module'); if p then _tl_compat = m end end; local ipairs = _tl_compat and _tl_compat.ipairs or ipairs; local pairs = _tl_compat and _tl_compat.pairs or pairs; local string = _tl_compat and _tl_compat.string or string; require("love")
require("nbtypes")
require("constants")

local i18n = require("i18n")
local gooi = require("gooi.gooi")

local serpent = require("serpent")


Expand All @@ -11,6 +12,29 @@ onAndroid = love.system.getOS() == "Android"
useKeyboard = true
preventiveFirstRun = true

require("pviewer")
require("menu")
require("help")
require("tiledbackground")







function initGlobals()
menu = require("menu").new()
pviewer = require("pviewer").new()
help = require("help").new()

tiledback = require("tiledbackground"):new()
end





function pack(...)
return { ... }
end
Expand Down Expand Up @@ -100,21 +124,40 @@ function percentage(signals, pressed)
end


function storeGooi()



local g = { components = gooi.components }
gooi.components = {}
return g
















function storeUI()





return {}
end

function restoreGooi(g)
function restoreUI(g)
if g == nil then
error("g == nil")
end

gooi.components = g.components

end

function compareDates(now, date)
Expand All @@ -132,7 +175,7 @@ function compareDates(now, date)
local result = i18n("moreTime")


local t1, t2, diff = now.yday * 24 + now.hour, date.yday * 24 + date.hour, 0
local t1, t2, diff = now.yday * 24 + now.hour, date.yday * 24 + date.hour, 0.
if date.year == now.year then
diff = t1 - t2
else
Expand Down Expand Up @@ -163,11 +206,11 @@ function readSettings()
local result

if data then
local ok, func = serpent.load(data)
local ok, res = serpent.load(data)
if not ok then
result = getDefaultSettings()
else
result = func()
result = res
end
else
result = getDefaultSettings()
Expand Down
50 changes: 46 additions & 4 deletions cmn.tl
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ require "nbtypes"
require "constants"

local i18n = require "i18n"
local gooi = require "gooi.gooi"
--local gooi = require "gooi.gooi"
local serpent = require "serpent"

global settings: Settings
Expand All @@ -12,6 +12,29 @@ global onAndroid = love.system.getOS() == "Android"
global useKeyboard = true
global preventiveFirstRun = true

require "pviewer"
require "menu"
require "help"
require "tiledbackground"

global menu: Menu
global pviewer: Pviewer
global help: Help
global tiledback: TiledBackround
--global nback: Nback

function initGlobals()
menu = require "menu".new()
pviewer = require "pviewer".new()
help = require "help".new()
--nback = require "nback".new()
tiledback = require "tiledbackground":new()
end

--return {
--initGlobals = initGlobals,
--}

function pack(...: any): any
return {...}
end
Expand Down Expand Up @@ -101,6 +124,7 @@ function percentage(signals: Signals, pressed: Signals.Eq): Percentage
end
--require "deepcopy"

--[[
function storeGooi(): Gooi
--local g = { components = deepcopy(gooi.components) }
--print("gooi.components", inspect(gooi.components))
Expand All @@ -117,6 +141,24 @@ function restoreGooi(g: Gooi)
--assert(g)
gooi.components = g.components
end
--]]

function storeUI(): any
--local g = { components = deepcopy(gooi.components) }
--print("gooi.components", inspect(gooi.components))
--local g = { components = table.deepcopy(gooi.components) }
--local g = { components = gooi.components }
--gooi.components = {}
return {}
end

function restoreUI(g: any)
if g == nil then
error("g == nil")
end
--assert(g)
--gooi.components = g.components
end

function compareDates(now: Date, date: Date): string
local ranges = {
Expand All @@ -133,7 +175,7 @@ function compareDates(now: Date, date: Date): string
local result = i18n("moreTime")
--print("now", inspect(os.date("*t")))
--print("date", inspect(date))
local t1, t2, diff = now.yday * 24 + now.hour, date.yday * 24 + date.hour, 0
local t1, t2, diff = now.yday * 24 + now.hour, date.yday * 24 + date.hour, 0.
if date.year == now.year then
diff = t1 - t2
else
Expand Down Expand Up @@ -164,11 +206,11 @@ function readSettings(): Settings
local result: Settings

if data then
local ok, func = serpent.load(data)
local ok, res = serpent.load(data)
if not ok then
result = getDefaultSettings()
else
result = func() as Settings
result = res as Settings
end
else
result = getDefaultSettings()
Expand Down
2 changes: 2 additions & 0 deletions globals.tl
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
--require "nback"
--[[
require "menu"
require "pviewer"
require "help"
Expand All @@ -21,3 +22,4 @@ end
return {
initGlobals = initGlobals,
}
--]]
1 change: 0 additions & 1 deletion gooi
Submodule gooi deleted from d2f075
2 changes: 1 addition & 1 deletion help.tl
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ require "layout"
require "cmn"
require "globals"

local gooi = require "gooi.gooi"
--local gooi = require "gooi.gooi"
local pallete = require "pallete"
local fonts = require "fonts"
local i18n = require "i18n"
Expand Down
Loading

0 comments on commit 4863f26

Please sign in to comment.