Created
August 3, 2016 19:01
-
-
Save treamology/e6679b323e263169942bbc39e445efae to your computer and use it in GitHub Desktop.
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
local autocache = {} | |
local new_image = love.graphics.newImage | |
local new_font = love.graphics.newFont | |
local new_image_font = love.graphics.newImageFont | |
local cachedImages = {} | |
local cachedFonts = {} | |
local function newImage(name, ...) | |
if type(name) ~= "string" then | |
return new_image(name, ...) | |
end | |
if cachedImages[name] == nil then | |
print("Loading image " .. name) | |
cachedImages[name] = new_image(name, ...) | |
end | |
return cachedImages[name] | |
end | |
local function newFont(name, ...) | |
if cachedFonts[name] == nil then | |
print("Loading font " .. name) | |
cachedFonts[name] = new_font(name, ...) | |
end | |
return cachedFonts[name] | |
end | |
local function newImageFont(name, ...) | |
if cachedFonts[name] == nil then | |
print("Loading font " .. name) | |
cachedFonts[name] = new_image_font(name, ...) | |
end | |
return cachedFonts[name] | |
end | |
love.graphics.newImage = newImage | |
love.graphics.newFont = newFont | |
love.graphics.newImageFont = newImageFont | |
autocache.cachedImages = cachedImages | |
autocache.cachedFonts = cachedFonts | |
return autocache |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment