Add Construct modes

This commit is contained in:
NOT_A_ROBOT
2023-09-18 12:49:17 +07:00
parent 7141f46948
commit a475232432
21 changed files with 557 additions and 195 deletions

View File

@@ -0,0 +1,117 @@
local gc_setColor,gc_draw=love.graphics.setColor,love.graphics.draw
local ply_applyField=PLY.draw.applyField
local holePatterns={
{-1,21,-1,21,-1,21,-1,21,-1,21},
{21,-1,21,-1,21,-1,21,-1,21,-1}
}
local targetField={}
local function generateGuide(y,mirror)
local tfLength=#targetField
if tfLength>y then return end
mirror=mirror and 1 or 0
for i=tfLength,y do
table.insert(targetField,TABLE.shift(
holePatterns[(i+mirror)%2+1]
))
end
end
local function calculateRankPts(P)
local points=1
for y=1,#P.field do
local flag
for x=1,10 do
-- X guide is filled
if P.field[y][x]>0 and targetField[y][x]<0 then flag=true break end
-- Block guide is empty
if P.field[y][x]==0 and targetField[y][x]>0 then flag=true break end
end
if flag then break end
points=points+1
end
P.modeData.rankPts=points
P.modeData.maxRankPts=math.max(points,P.modeData.maxRankPts)
end
return {
fkey1=function(P) P.modeData.showGuide=not P.modeData.showGuide end,
fkey2=function(P)
P.modeData.mirror=not P.modeData.mirror
TABLE.cut(targetField)
generateGuide(#P.field+10,P.modeData.mirror)
calculateRankPts(P)
end,
mesDisp=function(P)
local D=P.modeData
mText(TEXTOBJ.grade,63,190)
mText(TEXTOBJ.line,63,310)
setFont(55)
GC.mStr(getConstructGrade(D.rankPts),63,125)
GC.mStr(D.rankPts-1,63,245)
-- Display highest grade
if D.maxRankPts>D.rankPts then
gc_setColor(COLOR.lX)
setFont(20)
GC.mStr(text.highest:repD(getConstructGrade(D.maxRankPts)),63,216)
GC.mStr(text.highest:repD(D.maxRankPts+1),63,336)
end
ply_applyField(P)
local mark=TEXTURE.puzzleMark
if D.showGuide then
local firstMistake=nil
for y=1,D.rankPts+1 do
for x=1,10 do
local texture=targetField[y][x]
-- Missing blocks
if not P:solid(x,y) and texture>0 then
-- Missing block under overhang
if P:solid(x,y+1) then
firstMistake=firstMistake or y
gc_setColor(COLOR.R)
else
gc_setColor(COLOR.Z)
end
gc_draw(mark[texture],30*x-30,600-30*y)
elseif texture<0 then
-- X always gets displayed, color changes based on whether there is a block there
if P:solid(x,y) then
gc_setColor(COLOR.R)
firstMistake=firstMistake or y
elseif D.rankPts>y then
gc_setColor(COLOR.G)
else
gc_setColor(COLOR.Z)
end
gc_draw(mark[texture],30*x-30,600-30*y)
end
end
if y==firstMistake then
gc_setColor(1,0,0,.2*(math.sin(2*TIME())+1))
love.graphics.rectangle("fill",0,600-30*y,300,30)
end
end
end
PLY.draw.cancelField()
end,
task=function(P)
local D=P.modeData
D.rankPts=1
D.maxRankPts=1
D.showGuide=true
D.mirror=false
TABLE.cut(targetField)
generateGuide(10)
end,
hook_drop=function(P)
local D=P.modeData
calculateRankPts(P)
generateGuide(#P.field+10)
end
}

View File

@@ -0,0 +1,117 @@
local gc_setColor,gc_draw=love.graphics.setColor,love.graphics.draw
local ply_applyField=PLY.draw.applyField
local targetField={}
local function getOpenHole(y,mirror)
if mirror then y=y+9 end
return -math.abs(((y-1) % 18)-9)+10
end
local function generateGuide(y,mirror)
local l=#targetField
if l>y then
return
end
for i=l,y do
targetField[i] = {}
local h=getOpenHole(i,mirror)
for j=1,10 do
targetField[i][j]=h==j and 21 or -1
end
end
end
local function calculateRankPts(P)
local points=1
for y=1,#P.field do
local holePos=getOpenHole(y,P.modeData.mirror)
local flag
for x=1,10 do
if P.field[y][x]>0 and holePos~=x then flag=true break end
if P.field[y][x]==0 and holePos==x then flag=true break end
end
if flag then break end
if P:solid(holePos,y+1) then break end
points=points+1
end
P.modeData.rankPts=points
P.modeData.maxRankPts=math.max(points,P.modeData.maxRankPts)
end
return {
fkey1=function(P) P.modeData.showGuide=not P.modeData.showGuide end,
fkey2=function(P)
P.modeData.mirror=not P.modeData.mirror
TABLE.cut(targetField)
generateGuide(#P.field+10,P.modeData.mirror)
calculateRankPts(P)
end,
mesDisp=function(P)
local D=P.modeData
mText(TEXTOBJ.grade,63,190)
mText(TEXTOBJ.line,63,310)
setFont(55)
GC.mStr(getConstructGrade(D.rankPts),63,125)
GC.mStr(D.rankPts-1,63,245)
-- Display highest grade
if D.maxRankPts>D.rankPts then
gc_setColor(COLOR.lX)
setFont(20)
GC.mStr(text.highest:repD(getConstructGrade(D.maxRankPts)),63,216)
GC.mStr(text.highest:repD(D.maxRankPts+1),63,336)
end
ply_applyField(P)
local mark=TEXTURE.puzzleMark
if D.showGuide then
local firstMistake=nil
for y=1,D.rankPts+1 do
for x=1,10 do
local texture=targetField[y][x]
-- Missing blocks
if not P:solid(x,y) and texture>0 then
-- Missing block under overhang
if P:solid(x,y+1) then
firstMistake=firstMistake or y
gc_setColor(COLOR.R)
else
gc_setColor(COLOR.Z)
end
gc_draw(mark[texture],30*x-30,600-30*y)
elseif texture<0 then
-- X always gets displayed, color changes based on whether there is a block there
if P:solid(x,y) then
gc_setColor(COLOR.R)
firstMistake=firstMistake or y
elseif D.rankPts>y then
gc_setColor(COLOR.G)
else
gc_setColor(COLOR.Z)
end
gc_draw(mark[texture],30*x-30,600-30*y)
end
end
if y==firstMistake then
gc_setColor(1,0,0,.2*(math.sin(2*TIME())+1))
love.graphics.rectangle("fill",0,600-30*y,300,30)
end
end
end
PLY.draw.cancelField()
end,
task=function(P)
local D=P.modeData
D.rankPts=1
D.showGuide=true
D.maxRankPts=1
D.mirror=false
TABLE.cut(targetField)
generateGuide(10,D.mirror)
end,
hook_drop=function(P)
calculateRankPts(P)
generateGuide(#P.field+10,P.modeData.mirror)
end
}

View File

@@ -0,0 +1,117 @@
local gc_setColor,gc_draw=love.graphics.setColor,love.graphics.draw
local ply_applyField=PLY.draw.applyField
local targetField={}
local function getOpenHole(y,mirror)
if mirror then y=y+9 end
return -math.abs(((y-1) % 18)-9)+10
end
local function generateGuide(y,mirror)
local l=#targetField
if l>y then
return
end
for i=l,y do
targetField[i] = {}
local h=getOpenHole(i,mirror)
for j=1,10 do
targetField[i][j]=h==j and -1 or 21
end
end
end
local function calculateRankPts(P)
local points=1
for y=1,#P.field do
local holePos=getOpenHole(y,P.modeData.mirror)
local flag
for x=1,10 do
if P.field[y][x]>0 and holePos==x then flag=true break end
if P.field[y][x]==0 and holePos~=x then flag=true break end
end
if flag then break end
if not P:solid(holePos,y+1) then break end
points=points+1
end
P.modeData.rankPts=points
P.modeData.maxRankPts=math.max(points,P.modeData.maxRankPts)
end
return {
fkey1=function(P) P.modeData.showGuide=not P.modeData.showGuide end,
fkey2=function(P)
P.modeData.mirror=not P.modeData.mirror
TABLE.cut(targetField)
generateGuide(#P.field+10,P.modeData.mirror)
calculateRankPts(P)
end,
mesDisp=function(P)
local D=P.modeData
mText(TEXTOBJ.grade,63,190)
mText(TEXTOBJ.line,63,310)
setFont(55)
GC.mStr(getConstructGrade(D.rankPts),63,125)
GC.mStr(D.rankPts-1,63,245)
-- Display highest grade
if D.maxRankPts>D.rankPts then
gc_setColor(COLOR.lX)
setFont(20)
GC.mStr(text.highest:repD(getConstructGrade(D.maxRankPts)),63,216)
GC.mStr(text.highest:repD(D.maxRankPts+1),63,336)
end
ply_applyField(P)
local mark=TEXTURE.puzzleMark
if D.showGuide then
local firstMistake=nil
for y=1,D.rankPts+1 do
for x=1,10 do
local texture=targetField[y][x]
-- Missing blocks
if not P:solid(x,y) and texture>0 then
-- Missing block under overhang
if P:solid(x,y+1) then
firstMistake=firstMistake or y
gc_setColor(COLOR.R)
else
gc_setColor(COLOR.Z)
end
gc_draw(mark[texture],30*x-30,600-30*y)
elseif texture<0 then
-- X always gets displayed, color changes based on whether there is a block there
if P:solid(x,y) then
gc_setColor(COLOR.R)
firstMistake=firstMistake or y
elseif D.rankPts>y then
gc_setColor(COLOR.G)
else
gc_setColor(COLOR.Z)
end
gc_draw(mark[texture],30*x-30,600-30*y)
end
end
if y==firstMistake then
gc_setColor(1,0,0,.2*(math.sin(2*TIME())+1))
love.graphics.rectangle("fill",0,600-30*y,300,30)
end
end
end
PLY.draw.cancelField()
end,
task=function(P)
local D=P.modeData
D.rankPts=1
D.showGuide=true
D.maxRankPts=1
D.mirror=false
TABLE.cut(targetField)
generateGuide(10,D.mirror)
end,
hook_drop=function(P)
calculateRankPts(P)
generateGuide(#P.field+10,P.modeData.mirror)
end
}

View File

@@ -1,69 +0,0 @@
local gc_setColor,gc_draw=love.graphics.setColor,love.graphics.draw
local ply_applyField=PLY.draw.applyField
local function getOpenHole(num)
return -math.abs(((num-1) % 18)-9)+10
end
local F={}
-- local ranks={"10","9","8","7","6","5","4","3","2","1","S1","S2","S3","S4","S5","S6","S7","S8","S9","GM","GM+","TM","TM+","TM+₂","TM+₃", "TM+₄","TM+₅"}
-- lines: 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26
local function generateGuide(num)
local l=#F
if l>num then
return
end
for i=l,num do
F[i] = {}
local h=getOpenHole(i)
for j=1,10 do
F[i][j]=h==j and -1 or 21
end
end
end
return {
fkey1=function(P) P.modeData.showGuide=not P.modeData.showGuide end,
mesDisp=function(P)
mText(TEXTOBJ.grade,63,190)
mText(TEXTOBJ.line,63,310)
setFont(55)
GC.mStr(getSecretGrade(P.modeData.rankPts),63,125)
GC.mStr(P.modeData.rankPts-1,63,245)
ply_applyField(P)
local mark=TEXTURE.puzzleMark
gc_setColor(1,1,1)
if P.modeData.showGuide then
for y=1,P.modeData.rankPts+1 do for x=1,10 do
local T=F[y][x]
if T~=0 then
gc_draw(mark[T],30*x-30,600-30*y)
end
end end
end
PLY.draw.cancelField()
end,
task=function(P)
P.modeData.rankPts=1
P.modeData.showGuide=true
generateGuide(10)
end,
hook_drop=function(P)
local D=P.modeData
D.rankPts=0
for i=1,#P.field do
local h=getOpenHole(i)
local flag
for j=1,10 do
if P.field[i][j]>0 and h==j then flag=true break end-- goto post_pts_calc
if P.field[i][j]==0 and h~=j then flag=true break end-- goto post_pts_calc
end
if flag then break end
if i==#P.field then break end-- goto post_pts_calc
if P.field[i+1][h]==0 then break end-- goto post_pts_calc
D.rankPts=D.rankPts+1
end
-- ::post_pts_calc::
generateGuide(D.rankPts+20)
end
}