diff --git a/colorconstants.lua b/colorconstants.lua index d8b3a21..b8c6054 100644 --- a/colorconstants.lua +++ b/colorconstants.lua @@ -22,9 +22,15 @@ local _tl_compat; if (tonumber((_VERSION or ''):match('[%d.]*$')) or 0) < 5.3 th + local colors = { + + ["black"] = { 136 / 255, 55 / 255, 41 / 255 }, + ["white"] = { 136 / 255, 55 / 255, 41 / 255 }, + + ["brown"] = { 136 / 255, 55 / 255, 41 / 255 }, ["green"] = { 72 / 255, 180 / 255, 66 / 255 }, ["blue"] = { 27 / 255, 30 / 255, 249 / 255 }, diff --git a/colorconstants.tl b/colorconstants.tl index 9f79166..4e52e04 100644 --- a/colorconstants.tl +++ b/colorconstants.tl @@ -24,7 +24,13 @@ --["purple"] = {128 / 255, 7 / 255, 128 / 255}, } as ConstantsTable, constans_mt as metatable) --end +-- TODO Расширить палитру парами дополненных цветов local colors: {string:{number}} = { + -- отладочные цвета + ["black"] = {136 / 255, 55 / 255, 41 / 255}, + ["white"] = {136 / 255, 55 / 255, 41 / 255}, + + -- основные цвета ["brown"] = {136 / 255, 55 / 255, 41 / 255}, ["green"] = {72 / 255, 180 / 255, 66 / 255}, ["blue"] = {27 / 255, 30 / 255, 249 / 255}, diff --git a/layout.lua b/layout.lua index f8c1d8f..3992f25 100644 --- a/layout.lua +++ b/layout.lua @@ -139,6 +139,7 @@ function splitvByNum(tbl, piecesNum) return _tl_table_unpack(subTbls) end +-- что делает эта функция? function shrink(tbl, value) assertHelper(tbl) assert(type(value) == "number", string.format("number expected, but %s is", type(value))) diff --git a/nback.lua b/nback.lua index 47f5789..f7615c7 100644 --- a/nback.lua +++ b/nback.lua @@ -163,6 +163,9 @@ local yield = coroutine.yield + + + @@ -1143,6 +1146,7 @@ function Nback:check(signalType) end function Nback:resize(neww, newh) + colprint('Nback:resize()') print(string.format("resized to %d * %d", neww, newh)) self:buildLayout() @@ -1152,6 +1156,13 @@ function Nback:resize(neww, newh) self.cellWidth = math.ceil(self.layout.center.h / self.dim) self.bhupur_h = self.cellWidth * self.dim + + print(inspect(self.layout)) + + print('Nback:resize() x0, y0', + self.layout.center.x + (self.layout.center.w - self.layout.center.h) / 2, + self.layout.center.y) + self.x0, self.y0 = self.layout.center.x + (self.layout.center.w - self.layout.center.h) / 2, self.layout.center.y self.processor = require("coroprocessor").new() @@ -1206,20 +1217,35 @@ end function Nback:drawActiveSignal() print('Nback:drawActiveSignal()') + local pos = self.signals.pos[self.currentSig] + print("self.signals", inspect(self.signals)) print("self.signals.pos", inspect(self.signals.pos[self.currentSig])) print('pos', inspect(pos)) local x, y = pos.x, pos.y - print('self.current_sig', inspect(self.currentSig)) - print('self.signals.color', inspect(self.signals.color)) - print('colorConstants.colors', inspect(colorConstants.colors)) - print('hmm', inspect(self.signals.color[self.currentSig])) + if (not x) or (not y) then + x, y = 1, 1 + colprint('No right position, using default (1, 1)') + end + + print('x, y', x, y) + + + + + + + + local sig_color = colorConstants.colors[self.signals.color[self.currentSig]] - print('sig_color', sig_color) + if not sig_color then + colprint('Not right color, using default.') + sig_color = colorConstants.colors['black'] + end if self.figureAlpha then sig_color[4] = self.figureAlpha @@ -1228,6 +1254,7 @@ function Nback:drawActiveSignal() end local curtype = self.signals.form[self.currentSig] + print(x, y, inspect(curtype), inspect(sig_color)) self.signalView:draw(x, y, curtype, sig_color) end @@ -1236,6 +1263,7 @@ function Nback:drawField() g.setColor(self.fieldColor) local oldwidth = g.getLineWidth() g.setLineWidth(2) + print('self.x0, self.y0', self.x0, self.y0) for i = 0, self.dim do g.line(self.x0, self.y0 + i * self.cellWidth, diff --git a/nback.tl b/nback.tl index 1cafd7f..5d19573 100644 --- a/nback.tl +++ b/nback.tl @@ -113,8 +113,11 @@ global type Nback = record shaderTimeEnabled: boolean figureAlpha: number bhupur_h: number + + -- координаты левого верхнего угла экрана(в пикселях?) x0: number y0: number + processor: CoroProcessor statisticRender: StatisticRender volume: number @@ -1143,6 +1146,7 @@ function Nback:check(signalType: Signals.EqKeys) end function Nback:resize(neww: integer, newh: integer) + colprint('Nback:resize()') print(string.format("resized to %d * %d", neww, newh)) self:buildLayout() @@ -1152,6 +1156,13 @@ function Nback:resize(neww: integer, newh: integer) self.cellWidth = math.ceil(self.layout.center.h / self.dim) self.bhupur_h = self.cellWidth * self.dim + + print(inspect(self.layout)) + + print('Nback:resize() x0, y0', + self.layout.center.x + (self.layout.center.w - self.layout.center.h) / 2, + self.layout.center.y) + self.x0, self.y0 = self.layout.center.x + (self.layout.center.w - self.layout.center.h) / 2, self.layout.center.y self.processor = require "coroprocessor".new() @@ -1206,20 +1217,35 @@ end function Nback:drawActiveSignal() print('Nback:drawActiveSignal()') + local pos = self.signals.pos[self.currentSig] + print("self.signals", inspect(self.signals)) print("self.signals.pos", inspect(self.signals.pos[self.currentSig])) print('pos', inspect(pos)) local x, y = pos.x, pos.y + if (not x) or (not y) then + x, y = 1, 1 + colprint('No right position, using default (1, 1)') + end + + print('x, y', x, y) + + --[[ print('self.current_sig', inspect(self.currentSig)) print('self.signals.color', inspect(self.signals.color)) print('colorConstants.colors', inspect(colorConstants.colors)) print('hmm', inspect(self.signals.color[self.currentSig])) + print('sig_color', sig_color) + --]] local sig_color = colorConstants.colors[self.signals.color[self.currentSig]] - print('sig_color', sig_color) + if not sig_color then + colprint('Not right color, using default.') + sig_color = colorConstants.colors['black'] + end if self.figureAlpha then sig_color[4] = self.figureAlpha @@ -1228,6 +1254,7 @@ function Nback:drawActiveSignal() end --print("sig_color[4]", sig_color[4]) local curtype: string = self.signals.form[self.currentSig] + print(x, y, inspect(curtype), inspect(sig_color)) self.signalView:draw(x, y, curtype, sig_color) end @@ -1236,6 +1263,7 @@ function Nback:drawField() g.setColor(self.fieldColor) local oldwidth = g.getLineWidth() g.setLineWidth(2) + print('self.x0, self.y0', self.x0, self.y0) for i = 0, self.dim do -- horizontal g.line(self.x0, self.y0 + i * self.cellWidth, diff --git a/signal_quad_field.lua b/signal_quad_field.lua index 7575890..6145552 100644 --- a/signal_quad_field.lua +++ b/signal_quad_field.lua @@ -36,7 +36,6 @@ local inspect = require("inspect") - local SignalView_mt = { @@ -109,6 +108,7 @@ end function SignalView:setCorner(x, y) + print('SignalView:setCorner()', x, y) self.x0, self.y0 = x, y end @@ -128,7 +128,7 @@ end function SignalView:draw(xd, yd, type_, color) - print('SignalView:draw()', xd, yd, type_, color) + diff --git a/signal_quad_field.tl b/signal_quad_field.tl index 481b758..f8537f3 100644 --- a/signal_quad_field.tl +++ b/signal_quad_field.tl @@ -22,7 +22,6 @@ global type SignalView = record resize: function(SignalView, number, number) resize: function(SignalView, width: number) rhombus: function(SignalView, x: number, y: number, w: number, h: number) - setCorner: function(SignalView, number, number) setCorner: function(SignalView, x: number, y: number) trdown: function(SignalView, x: number, y: number, w: number, h: number) trup: function(SignalView, x: number, y: number, w: number, h: number) @@ -109,6 +108,7 @@ end -- установить координаты левого верхнего угла, от которого идет отсчет ячеек. -- обязательно вызывать перед рисовкой. function SignalView:setCorner(x: number, y: number) + print('SignalView:setCorner()', x, y) self.x0, self.y0 = x, y end @@ -128,7 +128,7 @@ end -- треугольник вверх, пересечение треугольников, ромб) -- color - текущий цвет function SignalView:draw(xd: number, yd: number, type_: string, color: {number}) - print('SignalView:draw()', xd, yd, type_, color) + --print('SignalView:draw()', xd, yd, inspect(type_), inspect(color)) --local currentHex = self.hexfield:get(xd, yd)