Skip to content

Commit

Permalink
皮肤模块添加语法注释
Browse files Browse the repository at this point in the history
气泡和宝石皮肤优化场地绘制流程
框架跟进
  • Loading branch information
MrZ626 committed Nov 7, 2023
1 parent 94ca640 commit 0028fad
Show file tree
Hide file tree
Showing 11 changed files with 92 additions and 52 deletions.
2 changes: 1 addition & 1 deletion Zenitha
Submodule Zenitha updated 1 files
+4 −4 gcExtend.lua
7 changes: 7 additions & 0 deletions assets/game/gemPlayer.lua
Original file line number Diff line number Diff line change
Expand Up @@ -809,6 +809,13 @@ function GP:render()

-- Grid & Cells
skin.drawFieldBackground(settings.fieldSize)
local F=self.field
for y=1,#F do for x=1,#F[1] do
local C=F[y][x]
if C then
skin.drawFieldCell(C,F,(x-1)*40+2,-y*40+2)
end
end end
skin.drawFieldCell(self.field)

self:triggerEvent('drawInField') -- From frame's bottom-left, 40px a cell
Expand Down
9 changes: 8 additions & 1 deletion assets/game/puyoPlayer.lua
Original file line number Diff line number Diff line change
Expand Up @@ -1091,7 +1091,14 @@ function PP:render()

-- Grid & Cells
skin.drawFieldBackground(settings.fieldW)
skin.drawFieldCell(self.field)

local F=self.field
for y=1,#F do for x=1,#F[1] do
local C=F[y][x]
if C then
skin.drawFieldCell(C,F,(x-1)*40+2,-y*40+2)
end
end end

self:triggerEvent('drawBelowBlock') -- From frame's bottom-left, 40px a cell

Expand Down
42 changes: 19 additions & 23 deletions assets/skin/gem_template.lua
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ local max,min=math.max,math.min

local COLOR=COLOR

---@type Techmino.skin.gem
local S={}

local crossR,crossL=1,6
Expand Down Expand Up @@ -156,31 +157,26 @@ local function drawGem(g)
gc_rectangle('line',-12,-12,24,24)
end
end
function S.drawFieldCell(F)
function S.drawFieldCell(G,_,x,y)
gc_setLineWidth(2)
for y=1,#F do for x=1,#F[1] do
local G=F[y][x]
if G then
gc_push('transform')
if G.moveTimer then
local d=G.moveTimer/G.moveDelay
if G.fall then
d=-d*(d-2)
else
d=-math.cos(d*math.pi)/2+.5
end
gc_translate(45*(x+d*G.dx)-22.5,-45*(y+d*G.dy)+22.5)
else
gc_translate(45*x-22.5,-45*y+22.5)
end
if G.clearTimer and not G.generate then
local i=G.clearTimer/G.clearDelay
gc_scale(-2*i^2+3*i)
end
drawGem(G)
gc_pop()
gc_push('transform')
if G.moveTimer then
local d=G.moveTimer/G.moveDelay
if G.fall then
d=-d*(d-2)
else
d=-math.cos(d*math.pi)/2+.5
end
end end
gc_translate(45*(x+d*G.dx)-22.5,-45*(y+d*G.dy)+22.5)
else
gc_translate(45*x-22.5,-45*y+22.5)
end
if G.clearTimer and not G.generate then
local t=G.clearTimer/G.clearDelay
gc_scale(-2*t^2+3*t)
end
drawGem(G)
gc_pop()
end

function S.drawGarbageBuffer(garbageBuffer)
Expand Down
46 changes: 39 additions & 7 deletions assets/skin/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,50 @@ local SKIN={}
SKIN.time=0
local function _getTime() return SKIN.time end

function SKIN.add(name,data)
---@class Techmino.skin
---@field base string
---@field getTime function
---@field drawFieldBackground fun(fieldW:number)
---@field drawFieldBorder fun()
---@field drawFieldCell fun(C:Techmino.Cell, F:Techmino.RectField, x:number, y:number)
---@field drawFloatHold fun(n:number|string, B:table, handX:number, handY:number, unavailable:boolean)
---@field drawHeightLines fun(fieldW:number, maxSpawnH:number, spawnH,lockoutH:number, deathH:number, voidH:number)
---@field drawDasIndicator fun(dir:number , charge:number, dasMax:number, arrMax:number, dasHalt:number)
---@field drawDelayIndicator fun(color:Zenitha.Color, value:number)
---@field drawGarbageBuffer fun(garbageBuffer:table)
---@field drawLockDelayIndicator fun(freshCondition:string, freshChance:number)
---@field drawGhost fun(B:table, handX:number, ghostY:number)
---@field drawHand fun(B:table, handX:number, handY:number)
---@field drawNextBorder fun(slot:number)
---@field drawNext fun(n:number, B:table, unavailable:boolean)
---@field drawHoldBorder fun(mode:string, slot:number)
---@field drawHold fun(n:number, B:table, unavailable:boolean)
---@field drawTime fun(time:number)
---@field drawInfoPanel fun(x:number, y:number, w:number, h:number)
---@field drawStartingCounter fun(readyDelay:number)

---@class Techmino.skin.mino: Techmino.skin

---@class Techmino.skin.puyo: Techmino.skin

---@class Techmino.skin.gem: Techmino.skin
---@field drawSwapCursor fun(cx:number, cy:number, lock:boolean)
---@field drawTwistCursor fun(sx:number, sy:number)

---@param name string
---@param skin Techmino.skin
function SKIN.add(name,skin)
assert(type(name)=='string',"Skin name must be string")
assert(not SKIN[name],"Skin "..name.." already exists")
assert(type(data)=='table',"Skin must be table")
assert(getmetatable(data)==nil,"Skin table must not have metatable")
assert(type(skin)=='table',"Skin must be table")
assert(getmetatable(skin)==nil,"Skin table must not have metatable")

assert(not data.getTime,"Skin mustn't define 'getTime'")
data.getTime=_getTime
assert(not skin.getTime,"Skin mustn't define 'getTime'")
skin.getTime=_getTime

setmetatable(data,{__index=data.base and assert(skinLib[data.base],"no base skin named "..tostring(data.base))})
setmetatable(skin,{__index=skin.base and assert(skinLib[skin.base],"no base skin named "..tostring(skin.base))})

skinLib[name]=data
skinLib[name]=skin
end

function SKIN.get(name)
Expand Down
1 change: 1 addition & 0 deletions assets/skin/mino_interior.lua
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ local gc_printf=gc.printf

local COLOR=COLOR

---@type Techmino.skin.mino
local S={}
S.base='mino_simp'

Expand Down
1 change: 1 addition & 0 deletions assets/skin/mino_plastic.lua
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ local min=math.min

local COLOR=COLOR

---@type Techmino.skin.mino
local S={}
S.base='mino_template'

Expand Down
3 changes: 2 additions & 1 deletion assets/skin/mino_simp.lua
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,11 @@
]]
local gc=love.graphics
local gc_setColor,gc_setLineWidth=gc.setColor,gc.setLineWidth
local gc_line,gc_rectangle=gc.line,gc.rectangle
local gc_line=gc.line

local COLOR=COLOR

---@type Techmino.skin.mino
local S={}
S.base='mino_template'

Expand Down
1 change: 1 addition & 0 deletions assets/skin/mino_template.lua
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ local max,min=math.max,math.min

local COLOR=COLOR

---@type Techmino.skin.mino
local S={}

local crossR,crossL=1,6
Expand Down
17 changes: 7 additions & 10 deletions assets/skin/puyo_jelly.lua
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ local gc_translate=gc.translate
local gc_setColor=gc.setColor
local gc_rectangle=gc.rectangle

---@type Techmino.skin.puyo
local S={}
S.base='puyo_template'

Expand All @@ -16,17 +17,13 @@ local function drawSide(B,x,y,bx,by)
if B[y+1] then t=B[y+1][x ] if t and t.connClear and t.color==c then gc_rectangle('fill',bx+8, by, 24, 5) end end
end

function S.drawFieldCell(F)
F=F._matrix
function S.drawFieldCell(C,F,x,y)
local flashing=S.getTime()%100<=50
for y=1,#F do for x=1,#F[1] do
local C=F[y][x]
if C and (not C.clearing or flashing) then
gc_setColor(ColorTable[C.color])
gc_rectangle('fill',(x-1)*40+2,-y*40+2,36,36,15)
drawSide(F,x,y,(x-1)*40,-y*40)
end
end end
if C and (not C.clearing or flashing) then
gc_setColor(ColorTable[C.color])
gc_rectangle('fill',(x-1)*40+2,-y*40+2,36,36,15)
drawSide(F,x,y,(x-1)*40,-y*40)
end
end

function S.drawHand(B,handX,handY)
Expand Down
15 changes: 6 additions & 9 deletions assets/skin/puyo_template.lua
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ local gc_setColor=gc.setColor
local gc_rectangle=gc.rectangle
local gc_setLineWidth=gc.setLineWidth

---@type Techmino.skin.puyo
local S={}
S.base='mino_template'

Expand All @@ -13,16 +14,12 @@ function S.drawFieldBackground(fieldW)
gc_rectangle('fill',0,0,40*fieldW,-80*fieldW)
end

function S.drawFieldCell(F)
F=F._matrix
function S.drawFieldCell(C,_,x,y)
local flashing=S.getTime()%100<=50
for y=1,#F do for x=1,#F[1] do
local C=F[y][x]
if C and (not C.clearing or flashing) then
gc_setColor(ColorTable[C.color])
gc_rectangle('fill',(x-1)*40+2,-y*40+2,36,36,15)
end
end end
if C and (not C.clearing or flashing) then
gc_setColor(ColorTable[C.color])
gc_rectangle('fill',x,y,36,36,15)
end
end

function S.drawGhost(B,handX,ghostY)
Expand Down

0 comments on commit 0028fad

Please sign in to comment.