Skip to content

Commit

Permalink
Autotiler now actually uses all adjecent tiles
Browse files Browse the repository at this point in the history
Fixed oversight in mapcoder after refactor
Trailing whitespace and local/global janitor
  • Loading branch information
Cruor committed Jul 14, 2019
1 parent fcb16fa commit c91fb5e
Show file tree
Hide file tree
Showing 30 changed files with 52 additions and 57 deletions.
5 changes: 3 additions & 2 deletions src/autotiler.lua
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ local function getPaddingOrCenterQuad(x, y, tile, tiles, meta, airTile, emptyTil

else
local center = meta.center[tile]

return center:len > 0 and center or defaultQuad, defaultSprite
end
end
Expand All @@ -100,14 +100,15 @@ end

local function getMaskQuadsFromTiles(x, y, masks, tiles, tile, ignore, air, wildcard)
if masks then
-- Getting upvalue
local checkTile = checkTile

local a, b, c = checkTile(tile, tiles:get(x - 1, y - 1, tile), ignore, air, wildcard), checkTile(tile, tiles:get(x + 0, y - 1, tile), ignore, air, wildcard), checkTile(tile, tiles:get(x + 1, y - 1, tile), ignore, air, wildcard)
local d, f = checkTile(tile, tiles:get(x - 1, y + 0, tile), ignore, air, wildcard), checkTile(tile, tiles:get(x + 1, y + 0, tile), ignore, air, wildcard)
local g, h, i = checkTile(tile, tiles:get(x - 1, y + 1, tile), ignore, air, wildcard), checkTile(tile, tiles:get(x + 0, y + 1, tile), ignore, air, wildcard), checkTile(tile, tiles:get(x + 1, y + 1, tile), ignore, air, wildcard)

for j, maskData <- masks do
if checkMaskFromTiles(maskData.mask, a, b, c, d, nil, f, g, h, j) then
if checkMaskFromTiles(maskData.mask, a, b, c, d, nil, f, g, h, i) then
return true, maskData.quads, maskData.sprites
end
end
Expand Down
10 changes: 5 additions & 5 deletions src/celeste_render.lua
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ function celesteRender.getOrCacheTileSpriteQuad(cache, tile, texture, quad, fg)

local quadCache = cache[tile][fg]
local quadX, quadY = quad[1], quad[2]

if not quadCache:get0(quadX, quadY) then
local spriteMeta = atlases.gameplay[texture]
local spritesWidth, spritesHeight = spriteMeta.image:getDimensions
Expand Down Expand Up @@ -369,7 +369,7 @@ end

function celesteRender.getEntityBatch(room, entities, viewport, forceRedraw, registeredEntities)
registeredEntities = registeredEntities or entityHandler.registeredEntities

roomCache[room.name] = roomCache[room.name] or {}

if forceRedraw and roomCache[room.name].entities.result ~= nil then
Expand Down Expand Up @@ -402,7 +402,7 @@ local function getTriggerBatchTaskFunc(room, triggers, viewport)
local height = trigger.height or 16

love.graphics.setColor(colors.triggerColor)

love.graphics.rectangle("line", x, y, width, height)
love.graphics.rectangle("fill", x, y, width, height)

Expand All @@ -415,7 +415,7 @@ local function getTriggerBatchTaskFunc(room, triggers, viewport)
local offsetY = (textHeight - height) / 2

love.graphics.printf(displayName, x, y, width, "center", 0, triggerFontSize, triggerFontSize, offsetX, offsetY)

love.graphics.setColor(colors.default)
end

Expand Down Expand Up @@ -529,7 +529,7 @@ local function getRoomCanvas(room, viewport, selected)

if orderedBatches then
local canvas = love.graphics.newCanvas(room.width or 0, room.height or 0)

canvas:renderTo(function()
for depth, batch <- orderedBatches do
batch:draw()
Expand Down
2 changes: 1 addition & 1 deletion src/conf.lua
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,6 @@ function love.conf(t)
t.window.minheight = 720

t.window.icon = "assets/logo-256.png"

t.window.vsync = true
end
8 changes: 4 additions & 4 deletions src/config.lua
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ function config.readConfigData(filename)
if fh then
local content = fh:read("*a")
res = utils.unserialize(content)

fh:close()
end

Expand All @@ -40,7 +40,7 @@ end
-- This prevents corruption of data if program is terminated while writing
function config.writeConfigData(filename, data, pretty)
pretty = pretty == nil or pretty

local success, content = false, nil

if data then
Expand All @@ -49,8 +49,8 @@ function config.writeConfigData(filename, data, pretty)

if success then
lfs.mkdir(utils.dirname(filename))
fh = io.open(tempFilename, "wb")
local fh = io.open(tempFilename, "wb")

if fh then
fh:write(content)
fh:close()
Expand Down
2 changes: 1 addition & 1 deletion src/debug_utils.lua
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ end

function debugUtils.redrawMap()
print("! Redrawing map")

celesteRender.invalidateRoomCache()
celesteRender.clearBatchingTasks()
end
Expand Down
2 changes: 1 addition & 1 deletion src/defaults/viewer/entity.lua
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ local missing = {}
function missing.draw(room, entity)
local x = entity.x or 0
local y = entity.y or 0

love.graphics.setColor(colors.entityMissingColor)
love.graphics.rectangle("fill", x - 2, y - 2, 5, 5)
love.graphics.setColor(colors.default)
Expand Down
2 changes: 1 addition & 1 deletion src/drawing.lua
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ end
function drawing.getSimpleCurve(start, stop, control, resolution)
control = control or {(start[1] + stop[1]) / 2, (start[2] + stop[2]) / 2}
resolution = resolution or 16

local res = $()

for i = 0, resolution do
Expand Down
2 changes: 1 addition & 1 deletion src/entities/introCar.lua
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ function introCar.sprite(room, entity)
local wheelSprite = drawableSpriteStruct.spriteFromTexture(wheelsTexture, entity)
wheelSprite:setJustification(0.5, 1.0)
wheelSprite.depth = 3

sprites += bodySprite
sprites += wheelSprite

Expand Down
2 changes: 1 addition & 1 deletion src/entities/refill.lua
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ refill.depth = -100

function refill.sprite(room, entity)
local texture = getTexture(entity)

return drawableSpriteStruct.spriteFromTexture(texture, entity)
end

Expand Down
2 changes: 1 addition & 1 deletion src/entities/templeEye.lua
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ local function isBackground(room, entity)

local tx = math.floor(x / 8) + 1
local ty = math.floor(y / 8) + 1

return room.tilesFg.matrix:get(tx, ty, "0") == "0"
end

Expand Down
2 changes: 1 addition & 1 deletion src/entities/wire.lua
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ function wire.draw(room, entity)
tr, tg, tb = r, g, b
end
end

local start = {entity.x, entity.y}
local stop = entity.nodes[1]
local control = {
Expand Down
6 changes: 3 additions & 3 deletions src/filesystem.lua
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ filesystem.remove = os.remove

function filesystem.isFile(path)
local attrs = lfs.attributes(path)

return attrs and attrs.mode == "file"
end

Expand All @@ -61,14 +61,14 @@ end

function filesystem.saveDialog(path, filter)
-- TODO - This is a blocking call, consider running in own thread
-- TODO - Verify arguments, documentation was very existant
-- TODO - Verify arguments, documentation was very existant

return nfd.save(filter, nil, path)
end

function filesystem.openDialog(path, filter)
-- TODO - This is a blocking call, consider running in own thread
-- TODO - Verify arguments, documentation was very existant
-- TODO - Verify arguments, documentation was very existant

return nfd.open(filter, nil, path)
end
Expand Down
4 changes: 2 additions & 2 deletions src/initial_startup.lua
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ function startup.findCelesteDirectory()
local selected = filesystem.openDialog()

if selected then
local valid, fixed = startup.verifyCelesteDir(selected)
local valid, fixed = startup.verifyCelesteDir(selected)

if valid then
return true, fixed
Expand All @@ -75,7 +75,7 @@ end
function startup.init()
if startup.requiresInit() then
local found, celesteDir = startup.findCelesteDirectory()

if found then
local conf = config.readConfig(settingsPath) or {}
conf.celeste_dir = celesteDir
Expand Down
8 changes: 3 additions & 5 deletions src/input_device.lua
Original file line number Diff line number Diff line change
Expand Up @@ -30,17 +30,15 @@ end

-- Use inputDeviceMt if no other metatable is already set for the device
function inputHandler.newInputDevice(device, devices)
local newDevice = device

devices = devices or inputHandler.inputDevices

if not getmetatable(device) then
newDevice = setmetatable(newDevice, inputDeviceMt)
device = setmetatable(device, inputDeviceMt)
end

table.insert(devices, newDevice)
table.insert(devices, device)

return newDevice
return device
end

return inputHandler
2 changes: 1 addition & 1 deletion src/input_devices/tool_device.lua
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ local device = setmetatable({_enabled = true, _type = "device"}, toolProxyMt)
function device.mousepressed(x, y, button, istouch, presses)
if state.map ~= nil then
local currentTool = toolHandler.currentTool

if button == actionButton then
local mapX, mapY = viewport.getMapCoordinates(x, y)

Expand Down
3 changes: 0 additions & 3 deletions src/input_handler.lua
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,8 @@ local inputDevice = require("input_device")
local inputHandler = {}

local mouseButtonsPressed = {}

local dragTreshold = 2

local echoDevice = true

function inputHandler.getMouseDrag(x, y, button)
local from = mouseButtonsPressed[button]
local startX, startY = from[1], from[2]
Expand Down
4 changes: 2 additions & 2 deletions src/loading.lua
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@ local loading = {}
loading.spriteSheet = love.graphics.newImage("assets/loading-256.png")
loading.quadSize = 256
loading.quads = {}

for y = 0, loading.spriteSheet:getHeight() - loading.quadSize, loading.quadSize do
for x = 0, loading.spriteSheet:getWidth() - loading.quadSize, loading.quadSize do
table.insert(loading.quads, love.graphics.newQuad(x, y, loading.quadSize, loading.quadSize, loading.spriteSheet:getDimensions()))
end
end

loading.duration = 1
loading.currentTime = 0

Expand Down
8 changes: 4 additions & 4 deletions src/mapcoder.lua
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ end

function mapcoder.decodeFile(path, header)
header = header or "CELESTE MAP"

local fh = io.open(path, "rb")
local res = {}

Expand Down Expand Up @@ -217,7 +217,7 @@ function mapcoder.encodeTable(fh, data, lookup)
binfile.writeShort(fh, #children)

for i, child <- children do
mapcoder.encodeTable(fh, child, lookup)
mapcoder.encodeTable(fh, child, lookup)
end
end

Expand All @@ -238,7 +238,7 @@ function mapcoder.encodeFile(path, data, header)
header = header or "CELESTE MAP"

local fh = utils.getFileHandle(path, "wb")

local stringsSeen = countStrings(data)
local lookupStrings = $()

Expand All @@ -258,7 +258,7 @@ function mapcoder.encodeFile(path, data, header)
binfile.writeString(fh, lookup)
end

encodeTable(fh, data, lookupStrings)
mapcoder.encodeTable(fh, data, lookupStrings)

fh:close()

Expand Down
2 changes: 1 addition & 1 deletion src/selene_main.lua
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ end
function love.update(dt)
tasks.processTasks(1 / 144)
inputHandler.update(dt)

if viewerState.map then
-- TODO - Find some sane values for this
celesteRender.processTasks(viewerState, 1 / 60, math.huge, 1 / 240, math.huge)
Expand Down
4 changes: 2 additions & 2 deletions src/serialize.lua
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ function serialize.countKeys(t)

for k, v in pairs(t) do
if type(k) == "number" then
numerical = numerical +1
numerical = numerical + 1
end

total = total + 1
Expand Down Expand Up @@ -63,7 +63,7 @@ function serialize.serialize(t, pretty, seen, depth, success)
key = "[" .. string.format("%q", k) .. "]"

elseif ktyp == "number" then
if numIndices > length then
if numIndices > length then
key = "[" .. tonumber(k) .. "]"

else
Expand Down
4 changes: 2 additions & 2 deletions src/sprite_loader.lua
Original file line number Diff line number Diff line change
Expand Up @@ -87,10 +87,10 @@ function spriteLoader.loadSpriteAtlas(metaFn, atlasDir)
local sprite = {
x = binfile.readSignedShort(fh),
y = binfile.readSignedShort(fh),

width = binfile.readSignedShort(fh),
height = binfile.readSignedShort(fh),

offsetX = binfile.readSignedShort(fh),
offsetY = binfile.readSignedShort(fh),
realWidth = binfile.readSignedShort(fh),
Expand Down
4 changes: 2 additions & 2 deletions src/structs/drawable_sprite.lua
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ local function setColor(target, color)
end

return success

elseif colorType == "table" and (#color == 3 or #color == 4) then
target.color = color

Expand Down Expand Up @@ -84,7 +84,7 @@ end

function drawableSpriteStruct.spriteFromTexture(texture, data)
data = data or {}

local atlas = data.atlas or "gameplay"
local spriteMeta = atlases[atlas][texture]

Expand Down
2 changes: 1 addition & 1 deletion src/structs/hotkey.lua
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ hotkeyMt.__index = {}
hotkeyMt.__index.active = hotkeyStruct.hotkeyActive
hotkeyMt.__index.callbackIfActive = hotkeyStruct.callbackIfActive

function hotkeyMt.__call(self)
function hotkeyMt.__call(self)
self:callback()
end

Expand Down
2 changes: 1 addition & 1 deletion src/structs/map.lua
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ function mapStruct.encode(map)
__children = children
})
end

if map.rooms:len > 0 then
local children = {}

Expand Down
Loading

0 comments on commit c91fb5e

Please sign in to comment.