Skip to content

Commit

Permalink
new bagline system (#963)
Browse files Browse the repository at this point in the history
closes #940
  • Loading branch information
ImpleLee authored Sep 11, 2023
1 parent 7141f46 commit 452fa65
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 11 deletions.
6 changes: 4 additions & 2 deletions parts/player/draw.lua
Original file line number Diff line number Diff line change
Expand Up @@ -569,8 +569,10 @@ local function _drawNext(P,repMode)
end
if ENV.bagLine then
gc_setColor(.8,.8,.8,.8)
for i=-P.pieceCount%ENV.bagLine,N-1,ENV.bagLine do-- i=phase
gc_rectangle('fill',1,72*i+3,98,2)
for i=1,ENV.nextCount+1 do
if queue[i] and queue[i].bagLine>0 then
gc_rectangle('fill',1,72*(i-1)+3,98,2)
end
end
end
gc_translate(-488,-20)
Expand Down
17 changes: 11 additions & 6 deletions parts/player/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -331,15 +331,14 @@ local function _applyGameEnv(P)-- Finish gameEnv processing
ENV.arr=max(ENV.arr,ENV.minarr)
ENV.sdarr=max(ENV.sdarr,ENV.minsdarr)

ENV.bagLine=ENV.bagLine and (ENV.sequence=='bag' or ENV.sequence=='loop') and #ENV.seqData

if ENV.nextCount==0 then
ENV.nextPos=false
end

local seqGen=coroutine.create(getSeqGen(ENV.sequence))
local seqCalled=false
local initSZOcount=0
local bagLineCounter=0
function P:newNext()
local status,piece
if seqCalled then
Expand All @@ -348,7 +347,9 @@ local function _applyGameEnv(P)-- Finish gameEnv processing
status,piece=coroutine.resume(seqGen,P.seqRND,P.gameEnv.seqData)
seqCalled=true
end
if status and piece then
if not status then
assert(piece=='cannot resume dead coroutine')
elseif piece then
if ENV.noInitSZO and initSZOcount<5 then
initSZOcount=initSZOcount+1
if piece==1 or piece==2 or piece==6 then
Expand All @@ -357,9 +358,13 @@ local function _applyGameEnv(P)-- Finish gameEnv processing
initSZOcount=5
end
end
P:getNext(piece)
elseif not status then
assert(piece=='cannot resume dead coroutine')
P:getNext(piece,bagLineCounter)
bagLineCounter=0
else
if ENV.bagLine then
bagLineCounter=bagLineCounter+1
end
P:newNext()
end
end
for _=1,ENV.trueNextCount do
Expand Down
7 changes: 4 additions & 3 deletions parts/player/player.lua
Original file line number Diff line number Diff line change
Expand Up @@ -1415,7 +1415,7 @@ function Player:hold(ifpre,force)
end
end

function Player:getBlock(id,name,color)-- Get a block object
function Player:getBlock(id,name,color,bagLineCounter)-- Get a block object
local ENV=self.gameEnv
local dir=ENV.face[id]
return {
Expand All @@ -1425,10 +1425,11 @@ function Player:getBlock(id,name,color)-- Get a block object
RS=self.RS,
name=name or id,
color=ENV.bone and 17 or color or ENV.skin[id],
bagLine=bagLineCounter,
}
end
function Player:getNext(id)-- Push a block to nextQueue
ins(self.nextQueue,self:getBlock(id))
function Player:getNext(id,bagLineCounter)-- Push a block to nextQueue
ins(self.nextQueue,self:getBlock(id,nil,nil,bagLineCounter))
if self.bot then
self.bot:pushNewNext(id)
end
Expand Down
6 changes: 6 additions & 0 deletions parts/player/seqGenerators.lua
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ local seqGenerators={
local bag={}
while true do
if #bag==0 then
yield(nil)
for i=1,len do
bag[i]=seq0[len-i+1]
end
Expand Down Expand Up @@ -35,11 +36,13 @@ local seqGenerators={
end
end
-- Finish
yield(nil)
for i=1,len do yield(bag[i]) end
end
bag={}
while true do
if #bag==0 then
yield(nil)
for i=1,len do
bag[i]=seq0[len-i+1]
end
Expand Down Expand Up @@ -189,6 +192,7 @@ local seqGenerators={
local bufferSeq,bag={},{}
while true do
if #bag==0 then
yield(nil)
for i=1,#seq0 do bufferSeq[i]=seq0[i] end
repeat
local r=rem(bufferSeq,rndGen:random(#bag))
Expand All @@ -210,6 +214,7 @@ local seqGenerators={
local bag={}
while true do
if #bag==0 then
yield(nil)
for i=1,len do
bag[i]=seq0[len-i+1]
end
Expand All @@ -235,6 +240,7 @@ local seqGenerators={
local unknown={}
local extra=-1
local function init()
yield(nil)
for i=1,len do
unknown[i]=1
end
Expand Down

0 comments on commit 452fa65

Please sign in to comment.