Skip to content
Snippets Groups Projects
Commit 3791030e authored by DarkGod's avatar DarkGod
Browse files

Merge branch 'absolute_tiles' into 'master'

Absolute tiles

Made it possible for Entity to use absolute dta paths in image=, and for talents and effects as well.
Also support for addon+path syntax, didn't know which would be more desirable.
parents 26b351a1 49820869
No related branches found
No related tags found
No related merge requests found
......@@ -49,9 +49,26 @@ function _M:init(w, h, fontname, fontsize, texture, allow_backcolor)
self.texture_store = {}
end
function concatPrefix(prefix, image_file)
if image_file:sub(1, 1) == "/" then
return image_file
else
return prefix..image_file
end
end
function baseImageFile(image_file)
local _, _, addon, rfile = image_file:find("^([^+]+)%+(.+)$")
if addon and rfile then
return "/data-"..addon.."/gfx/"..rfile
else
return concatPrefix(base_prefix, image_file)
end
end
function _M:loadImage(image)
local s = core.display.loadImage(self.prefix..image)
if not s then s = core.display.loadImage(self.base_prefix..image) end
local s = core.display.loadImage(concatPrefix(self.prefix, image))
if not s then s = core.display.loadImage(baseImageFile(image)) end
return s
end
......@@ -92,7 +109,7 @@ function _M:get(char, fr, fg, fb, br, bg, bb, image, alpha, do_outline, allow_ti
local is_image = false
if (self.use_images or not dochar) and image and #image > 4 then
if allow_tileset and self.texture then
local ts, fx, fy, tsx, tsy = self:checkTileset(self.prefix..image)
local ts, fx, fy, tsx, tsy = self:checkTileset(concatPrefix(self.prefix, image))
if ts then
self.repo[char] = self.repo[char] or {}
self.repo[char][fgidx] = self.repo[char][fgidx] or {}
......@@ -101,8 +118,8 @@ function _M:get(char, fr, fg, fb, br, bg, bb, image, alpha, do_outline, allow_ti
end
end
print("Loading tile", image)
s = core.display.loadImage(self.prefix..image)
if not s then s = core.display.loadImage(self.base_prefix..image) end
s = core.display.loadImage(concatPrefix(self.prefix, image))
if not s then s = core.display.loadImage(baseImageFile(image)) end
if s then is_image = true end
end
......
......@@ -19,6 +19,7 @@
local tacticals = {}
local Entity = require "engine.Entity"
local Tiles = require "engine.Tiles"
local oldNewTalent = Talents.newTalent
Talents.newTalent = function(self, t)
......@@ -47,7 +48,7 @@ Talents.newTalent = function(self, t)
if not t.image then
t.image = "talents/"..(t.short_name or t.name):lower():gsub("[^a-z0-9_]", "_")..".png"
end
if fs.exists("/data/gfx/"..t.image) then t.display_entity = Entity.new{image=t.image, is_talent=true}
if fs.exists(Tiles.baseImageFile(t.image)) then t.display_entity = Entity.new{image=t.image, is_talent=true}
else t.display_entity = Entity.new{image="talents/default.png", is_talent=true}
end
return oldNewTalent(self, t)
......
......@@ -32,6 +32,7 @@ local Entity = require "engine.Entity"
local Chat = require "engine.Chat"
local Map = require "engine.Map"
local Level = require "engine.Level"
local Tiles = require "engine.Tiles"
local resolveSource = function(self)
if self.src and self.src.resolveSource then
......@@ -56,7 +57,7 @@ TemporaryEffects.newEffect = function(self, t)
if not t.image then
t.image = "effects/"..(t.name):lower():gsub("[^a-z0-9_]", "_")..".png"
end
if fs.exists("/data/gfx/"..t.image) then t.display_entity = Entity.new{image=t.image, is_effect=true}
if fs.exists(Tiles.baseImageFile(t.image)) then t.display_entity = Entity.new{image=t.image, is_effect=true}
else t.display_entity = Entity.new{image="effects/default.png", is_effect=true} print("===", t.type, t.name)
end
t.getName = getName
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment