-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Image data is now managed without needing to serialize it out
Games load and save again, though not fully successfully. Refactor for image management is much cleaner than previous implementations. Closes #109
- Loading branch information
Showing
16 changed files
with
196 additions
and
284 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
-- Copyright (c) 2021 Trevor Redfern | ||
-- | ||
-- This software is released under the MIT License. | ||
-- https://opensource.org/licenses/MIT | ||
|
||
local tables = require "moonpie.tables" | ||
local class = require "moonpie.class" | ||
local Colors = require "game.rules.graphics.colors" | ||
local Wrapper = class({}) | ||
local ImageManager = {} | ||
local store = {} | ||
local imageData = {} | ||
|
||
|
||
function Wrapper:constructor(imageKey) | ||
self.imageKey = imageKey | ||
self.color = Colors.drawDefault | ||
end | ||
|
||
function Wrapper:draw(sx, sy) | ||
-- This works around getting access back to the image manager on reloading | ||
local mgr = require "game.rules.graphics.image_manager" | ||
local i, q = mgr.get(self.imageKey) | ||
love.graphics.setColor(self.color) | ||
if q then | ||
love.graphics.draw(i, q, sx, sy) | ||
else | ||
love.graphics.draw(i, sx, sy) | ||
end | ||
end | ||
|
||
function Wrapper:setColor(c) | ||
self.color = c | ||
end | ||
|
||
function ImageManager.set(key, image, quad) | ||
store[key] = tables.pack(image, quad) | ||
end | ||
|
||
function ImageManager.get(key) | ||
if store[key] then | ||
return tables.unpack(store[key]) | ||
end | ||
end | ||
|
||
function ImageManager.load(key, filename, quadData) | ||
local q = nil | ||
imageData[filename] = imageData[filename] or love.graphics.newImage(filename) | ||
if quadData then | ||
local x, y, w, h = tables.unpack(quadData) | ||
q = love.graphics.newQuad(x, y, w, h, imageData[filename]) | ||
end | ||
|
||
ImageManager.set(key, imageData[filename], q) | ||
return ImageManager.getDrawable(key) | ||
end | ||
|
||
function ImageManager.getDrawable(key) | ||
return Wrapper:new(key) | ||
end | ||
|
||
|
||
return ImageManager |
Oops, something went wrong.