Skip to content

Commit fe2ee7f

Browse files
committed
fix: restore pairs(objects) order
1 parent d786d67 commit fe2ee7f

File tree

6 files changed

+79
-176
lines changed

6 files changed

+79
-176
lines changed

animation.lua

+5-5
Original file line numberDiff line numberDiff line change
@@ -871,15 +871,15 @@ function animation:update(dt)
871871
elseif v[1] == "transformenemy" then
872872
transformenemyanimation(v[2])
873873
elseif v[1] == "killallenemies" then
874-
for i2, v2 in pairs(objects) do
875-
if i1 ~= "tile" and i2 ~= "buttonblock" then
876-
for i, v in pairs(objects[i2]) do
877-
if v.active and v.shotted and (not v.resistseverything) then
874+
for i2, v2 in kpairs(objects, objectskeys) do
875+
if i2 ~= "tile" and i2 ~= "buttonblock" then
876+
for i3, v3 in pairs(objects[i2]) do
877+
if v3.active and v3.shotted and (not v3.resistseverything) then
878878
local dir = "right"
879879
if math.random(1,2) == 1 then
880880
dir = "left"
881881
end
882-
v:shotted(dir)
882+
v3:shotted(dir)
883883
end
884884
end
885885
end

game.lua

+34-163
Original file line numberDiff line numberDiff line change
@@ -712,7 +712,7 @@ function game_update(dt)
712712
end
713713
--UPDATE OBJECTS
714714
local delete
715-
for i, v in pairs(objects) do
715+
for i, v in kpairs(objects, objectskeys) do
716716
if i ~= "tile" and i ~= "portalwall" and i ~= "screenboundary" and i ~= "coin" and i ~= "risingwater" and i ~= "clearpipesegment" and i ~= "tracksegment" and i ~= "funnel" and i ~= "clearpipe" then
717717
delete = nil
718718
for j, w in pairs(v) do
@@ -1617,7 +1617,7 @@ function game_draw()
16171617
--[[for j, w in pairs(objects["redseesaw"]) do --has overlapping shadows
16181618
w:draw()
16191619
end]]
1620-
for j, w in pairs(objects) do
1620+
for j, w in kpairs(objects, objectskeys) do
16211621
if j ~= "tile" then
16221622
for i, v in pairs(w) do
16231623
if v.drawable and (not v.nodropshadow) then--and not v.drawback then
@@ -2040,7 +2040,7 @@ function game_draw()
20402040
end
20412041

20422042
--OBJECTS
2043-
for j, w in pairs(objects) do
2043+
for j, w in kpairs(objects, objectskeys) do
20442044
if j ~= "tile" then
20452045
for i, v in pairs(w) do
20462046
if v.drawable and not v.drawback then
@@ -2141,7 +2141,7 @@ function game_draw()
21412141
for j, w in pairs(objects["tilemoving"]) do
21422142
w:draw()
21432143
end
2144-
for j, w in pairs(objects) do
2144+
for j, w in kpairs(objects, objectskeys) do
21452145
if j ~= "tile" then
21462146
for i, v in pairs(w) do
21472147
if v.drawable and (not v.nodropshadow) then--and not v.drawback then
@@ -2305,7 +2305,7 @@ function game_draw()
23052305
if HITBOXDEBUG and (editormode or testlevel) then
23062306
local lw = love.graphics.getLineWidth()
23072307
love.graphics.setLineWidth(.5*scale)
2308-
for i, v in pairs(objects) do
2308+
for i, v in kpairs(objects, objectskeys) do
23092309
for j, k in pairs(v) do
23102310
if k.width then
23112311
if xscroll >= k.x-width and k.x+k.width > xscroll then
@@ -4118,161 +4118,32 @@ function startlevel(level, reason)
41184118
portals = {}
41194119
blockedportaltiles = {}
41204120

4121+
objectskeys = {
4122+
"mariohammer", "icicle", "thwomp", "threeup", "ceilblocker", "energyball", "belt", "brofireball", "bomb",
4123+
"musicchanger", "mole", "lightbridge", "splunkin", "bulletbill", "cannonballcannon", "randomizer",
4124+
"collectable", "plant", "lakito", "laser", "squid", "star", "bowser", "powblock", "animationoutput",
4125+
"chainchomp", "energylauncher", "skewer", "platformspawner", "collectablelock", "cubedispenser", "door",
4126+
"bigmole", "hammersuit", "flipblock", "notgate", "frozencoin", "portalent", "yoshi", "coin", "bigbill",
4127+
"torpedolauncher", "seesawplatform", "groundlight", "koopa", "flyingfish", "kingbill", "spike", "donut",
4128+
"player", "mushroom", "clearpipesegment", "angrysun", "turretshot", "edgewrap", "spikeball", "rocketturret",
4129+
"redseesaw", "koopaling", "levelball", "torpedoted", "upfire", "magikoopa", "fireball", "cheep", "pixeltile",
4130+
"tilemoving", "platform", "drybones", "hammerbro", "animationtrigger", "meteor", "pushbutton", "leaf",
4131+
"wrench", "hammer", "muncher", "fire", "faithplate", "castlefire", "ninji", "doorsprite", "boo",
4132+
"blocktogglebutton", "iceball", "longfire", "animatedtiletrigger", "cannonball", "tiletool", "text",
4133+
"turretrocket", "funnel", "trackcontroller", "rsflipflop", "portalwall", "smallspring", "core",
4134+
"screenboundary", "boomboom", "cappy", "grinder", "ice", "checkpointflag", "plantfire", "geldispenser",
4135+
"castlefirefire", "tracksegment", "plantcreepersegment", "rockywrench", "wallindicator", "oneup", "box",
4136+
"snakeblock", "risingwater", "plantcreeper", "orgate", "pbutton", "delayer", "camerastop", "vine", "glados",
4137+
"gel", "yoshiegg", "spring", "pokey", "sidestepper", "windleaf", "button", "turret", "flower", "tile",
4138+
"mariotail", "laserdetector", "regiontrigger", "boomerang", "smbsitem", "walltimer", "fuzzy", "frogsuit",
4139+
"checkpoint", "lightbridgebody", "andgate", "fishbone", "goomba", "squarewave", "parabeetle", "amp",
4140+
"energycatcher", "pedestal", "buttonblock", "enemy", "enemytool", "barrel", "poisonmush"
4141+
}
41214142
objects = {}
4122-
objects["player"] = {}
4123-
objects["portalwall"] = {}
4124-
objects["tile"] = {}
4125-
objects["tilemoving"] = {}
4126-
objects["enemy"] = {}
4127-
objects["goomba"] = {}
4128-
objects["koopa"] = {}
4129-
objects["mushroom"] = {}
4130-
objects["flower"] = {}
4131-
objects["oneup"] = {}
4132-
objects["star"] = {}
4133-
objects["vine"] = {}
4134-
objects["box"] = {}
4135-
objects["door"] = {}
4136-
objects["button"] = {}
4137-
objects["groundlight"] = {}
4138-
objects["wallindicator"] = {}
4139-
objects["walltimer"] = {}
4140-
objects["notgate"] = {}
4141-
objects["lightbridge"] = {}
4142-
objects["lightbridgebody"] = {}
4143-
objects["faithplate"] = {}
4144-
objects["laser"] = {}
4145-
objects["laserdetector"] = {}
4146-
objects["gel"] = {}
4147-
objects["geldispenser"] = {}
4148-
objects["cubedispenser"] = {}
4149-
objects["pushbutton"] = {}
4150-
objects["bulletbill"] = {}
4151-
objects["hammerbro"] = {}
4152-
objects["hammer"] = {}
4153-
objects["fireball"] = {}
4154-
objects["platform"] = {}
4155-
objects["platformspawner"] = {}
4156-
objects["plant"] = {}
4157-
objects["castlefire"] = {}
4158-
objects["castlefirefire"] = {}
4159-
objects["fire"] = {}
4160-
objects["bowser"] = {}
4161-
objects["spring"] = {}
4162-
objects["cheep"] = {}
4163-
objects["flyingfish"] = {}
4164-
objects["upfire"] = {}
4165-
objects["seesawplatform"] = {}
4166-
objects["ceilblocker"] = {}
4167-
objects["lakito"] = {}
4168-
objects["squid"] = {}
4169-
objects["poisonmush"] = {}
4170-
objects["bigbill"] = {}
4171-
objects["kingbill"] = {}
4172-
objects["sidestepper"] = {}
4173-
objects["barrel"] = {}
4174-
objects["icicle"] = {}
4175-
objects["angrysun"] = {}
4176-
objects["splunkin"] = {}
4177-
objects["threeup"] = {}
4178-
objects["brofireball"] = {}
4179-
objects["smbsitem"] = {}
4180-
objects["thwomp"] = {}
4181-
objects["fishbone"] = {}
4182-
objects["drybones"] = {}
4183-
objects["muncher"] = {}
4184-
objects["meteor"] = {}
4185-
objects["donut"] = {}
4186-
objects["boomerang"] = {}
4187-
objects["parabeetle"] = {}
4188-
objects["ninji"] = {}
4189-
objects["hammersuit"] = {}
4190-
objects["mariohammer"] = {}
4191-
objects["boo"] = {}
4192-
objects["mole"] = {}
4193-
objects["bigmole"] = {}
4194-
objects["bomb"] = {}
4195-
objects["plantfire"] = {}
4196-
objects["flipblock"] = {}
4197-
objects["torpedoted"] = {}
4198-
objects["torpedolauncher"] = {}
4199-
objects["frogsuit"] = {}
4200-
objects["boomboom"] = {}
4201-
objects["levelball"] = {}
4202-
objects["leaf"] = {}
4203-
objects["mariotail"] = {}
4204-
objects["windleaf"] = {}
4205-
objects["energylauncher"] = {}
4206-
objects["energyball"] = {}
4207-
objects["energycatcher"] = {}
4208-
objects["turret"] = {}
4209-
objects["turretshot"] = {}
4210-
objects["blocktogglebutton"] = {}
4211-
objects["buttonblock"] = {}
4212-
objects["squarewave"] = {}
4213-
objects["delayer"] = {}
4214-
objects["coin"] = {}
4215-
objects["frozencoin"] = {}
4216-
objects["amp"] = {}
4217-
objects["fuzzy"] = {}
4218-
objects["funnel"] = {}
4219-
objects["longfire"] = {}
4220-
objects["cannonball"] = {}
4221-
objects["cannonballcannon"] = {}
4222-
objects["rocketturret"] = {}
4223-
objects["turretrocket"] = {}
4224-
objects["glados"] = {}
4225-
objects["core"] = {}
4226-
objects["pedestal"] = {}
4227-
objects["portalent"] = {}
4228-
objects["text"] = {}
4229-
objects["regiontrigger"] = {}
4230-
objects["tiletool"] = {}
4231-
objects["iceball"] = {}
4232-
objects["enemytool"] = {}
4233-
objects["randomizer"] = {}
4234-
objects["yoshiegg"] = {}
4235-
objects["yoshi"] = {}
4236-
objects["musicchanger"] = {}
4237-
objects["pbutton"] = {}
4238-
objects["pokey"] = {}
4239-
objects["chainchomp"] = {}
4240-
objects["rockywrench"] = {}
4241-
objects["wrench"] = {}
4242-
objects["koopaling"] = {}
4243-
objects["checkpoint"] = {}
4244-
objects["doorsprite"] = {}
4245-
objects["magikoopa"] = {}
4246-
objects["skewer"] = {}
4247-
objects["belt"] = {}
4248-
objects["animationtrigger"] = {}
4249-
objects["animationoutput"] = {}
4250-
objects["animatedtiletrigger"] = {}
4251-
objects["rsflipflop"] = {}
4252-
objects["orgate"] = {}
4253-
objects["andgate"] = {}
4254-
objects["collectable"] = {}
4255-
objects["collectablelock"] = {}
4256-
objects["powblock"] = {}
4257-
objects["smallspring"] = {}
4258-
objects["risingwater"] = {}
4259-
objects["redseesaw"] = {}
4260-
objects["snakeblock"] = {}
4261-
objects["spike"] = {}
4262-
objects["spikeball"] = {}
4263-
objects["camerastop"] = {}
4264-
objects["clearpipesegment"] = {}
4265-
objects["plantcreeper"] = {}
4266-
objects["plantcreepersegment"] = {}
4267-
objects["tracksegment"] = {}
4268-
objects["trackcontroller"] = {}
4269-
objects["checkpointflag"] = {}
4270-
objects["ice"] = {}
4271-
objects["grinder"] = {}
4272-
4273-
objects["cappy"] = {}
4274-
4275-
objects["screenboundary"] = {}
4143+
for i = 1, #objectskeys do
4144+
local key = objectskeys[i]
4145+
objects[key] = {}
4146+
end
42764147
objects["screenboundary"]["left"] = screenboundary:new(0)
42774148

42784149
splitxscroll = {0}
@@ -4894,8 +4765,8 @@ function loadmap(filename)
48944765
table.sort(checkpoints)
48954766

48964767
--Add links
4897-
for i, v in pairs(objects) do
4898-
for j, w in pairs(v) do
4768+
for key, value in kpairs(objects, objectskeys) do
4769+
for j, w in pairs(value) do
48994770
if w.link then
49004771
w:link()
49014772
end
@@ -6052,7 +5923,7 @@ function insideportal(x, y, width, height) --returns whether an object is in, an
60525923
end
60535924

60545925
function moveoutportal() --pushes objects out of the portal i in.
6055-
for i, v in pairs(objects) do
5926+
for i, v in kpairs(objects, objectskeys) do
60565927
if i ~= "tile" and i ~= "portalwall" then
60575928
for j, w in pairs(v) do
60585929
if w.active and w.static == false then
@@ -8774,7 +8645,7 @@ function convertr(r, types, dontgivedefaultvalues) --convert right cick values
87748645
end
87758646

87768647
function lightsoutstencil()
8777-
for i2, v2 in pairs(objects) do
8648+
for i2, v2 in kpairs(objects, objectskeys) do
87788649
if i2 ~= "tile" and i2 ~="buttonblock" and i2 ~= "clearpipesegment" then
87798650
for i, v in pairs(objects[i2]) do
87808651
if (v.active or (i2 == "player" or i2 == "enemy")) and v.light and onscreen(v.x+v.width/2-v.light, v.y+v.height/2-v.light, v.light*2, v.light*2) then

physics.lua

+3-3
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ local rotatepoint, getslopey
5151
function physicsupdate(dt)
5252
local lobjects = objects
5353

54-
for j, w in pairs(lobjects) do
54+
for j, w in kpairs(lobjects, objectskeys) do
5555
if j ~= "tile" and j ~= "buttonblock" and j ~= "tracksegment" then
5656
for i, v in pairs(w) do
5757
local oldspeedx = v.speedx
@@ -128,7 +128,7 @@ function physicsupdate(dt)
128128
local latetable = {"portalwall", "castlefirefire", "platform"}
129129

130130
--VS OTHER OBJECTS --but not portalwall
131-
for h, u in pairs(lobjects) do
131+
for h, u in kpairs(lobjects, objectskeys) do
132132
if h ~= "tile" and h ~= "buttonblock" and h ~= "tracksegment" then
133133
local pass = true
134134
for k, l in pairs(latetable) do
@@ -955,7 +955,7 @@ function checkrect(x, y, width, height, list, statics, condition)
955955
end
956956
end
957957

958-
for i, v in pairs(objects) do
958+
for i, v in kpairs(objects, objectskeys) do
959959
local contains = false
960960

961961
if list and list ~= "all" then

powblock.lua

+2-2
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ function powblock:hit()
8888
self.explode = true
8989
self.active = false
9090

91-
for i2, v2 in pairs(objects) do
91+
for i2, v2 in kpairs(objects, objectskeys) do
9292
if i1 ~= "tile" and i2 ~= "buttonblock" then
9393
for i, v in pairs(objects[i2]) do
9494
if v.active and v.shotted and onscreen(v.x,v.y) and (not v.resistspowblock) and v.speedy == 0 then
@@ -152,4 +152,4 @@ end
152152

153153
function powblock:passivecollide(a, b)
154154
return false
155-
end
155+
end

smbsitem.lua

+2-2
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,7 @@ function smbsitem:action(b)
158158
end
159159
playsound(keysound)
160160
elseif self.t == "luckystar" then
161-
for i2, v2 in pairs(objects) do
161+
for i2, v2 in kpairs(objects, objectskeys) do
162162
if i1 ~= "tile" and i2 ~= "buttonblock" then
163163
for i, v in pairs(objects[i2]) do
164164
if v.active and v.shotted and onscreen(v.x,v.y) and (not v.resistspowblock) then
@@ -191,4 +191,4 @@ end
191191
function smbsitem:jump(x)
192192
self.falling = true
193193
self.speedy = -mushroomjumpforce
194-
end
194+
end

utils.lua

+33-1
Original file line numberDiff line numberDiff line change
@@ -59,14 +59,46 @@ end
5959
--------------
6060

6161
function hasvalue(tab, val)
62-
for i, value in ipairs(tab) do
62+
for i, value in pairs(tab) do
6363
if value == val then
6464
return true
6565
end
6666
end
6767
return false
6868
end
6969

70+
function spairs(t, compare)
71+
local sorted = {}
72+
for k in pairs(t) do
73+
table.insert(sorted, k)
74+
end
75+
76+
if compare then
77+
table.sort(sorted, function(a,b) return compare(a,b,t) end)
78+
else
79+
table.sort(sorted)
80+
end
81+
82+
-- iterator
83+
local i = 0
84+
return function()
85+
i = i + 1
86+
if sorted[i] then
87+
return sorted[i], t[sorted[i]]
88+
end
89+
end
90+
end
91+
92+
function kpairs(t, keys)
93+
local i = 0
94+
return function()
95+
i = i + 1
96+
if keys[i] then
97+
return keys[i], t[keys[i]]
98+
end
99+
end
100+
end
101+
70102
function isPaused(source)
71103
return pausedaudio and hasvalue(pausedaudio, source)
72104
end

0 commit comments

Comments
 (0)