Files
texturepack_toolkit.lua :
update.lua :
data.lua :
Code: Select all
function findmodname()
-- find the current mod name
return debug.getinfo(2, "S").source:sub(2):match("(.*)/")
end
function prequire(f)
-- protected variant of require
local s,e=pcall(function()require(f)end)
if not s then
if type(value)=="string" then
print(f..":"..e)
else
print(f..": can't load "..findmodname().."/"..string.gsub(f, "%.", "/")..".lua")
end
end
end
function patch()
-- apply texturepack
local function foreach(d,g,t,n,p,i)
if d[n]~=nil then
if type(d[n])=="function" then d[n](n,p,i) else p[i]=d[n] end
end
if type(t)=="table" then
for k,v in pairs(t) do foreach(d,g,v,n.."."..k,t,k) end
elseif type(t)=="string" then
if g[t]~=nil then
if type(g[t])=="function" then g[t](n,p,i) else p[i]=g[t] end
end
end
end
foreach(overwrite_data,overwrite_graphics,data.raw,"data.raw")
end
overwrite_data = {}
overwrite_graphics = {}
modname = findmodname()
------ Methods updating texture list ------
function merge(t1,t2)
-- extend table with content based on key
for k,v in pairs(t2) do
t1[k]=v
end
end
function update(t1,t2)
-- update already defined key only
for k,v in pairs(t2) do
if t1[k] ~= nil then t1[k]=v end
end
end
------ patching methods ------
function replace(r)
--replace the texture with the new version and apply modifications on neighbors keys
return function(n,p,i)
p[i]=string.gsub(p[i],"(__[a-zA-Z0-9]+__)",findmodname().."/%1")
if r ~= nil then
for k,v in pairs(r) do
p[k]=v
end
end
end
end
function neighbors(r)
--apply modifications on neighbors keys
return function(n,p,i)
if r ~= nil then
for k,v in pairs(r) do
p[k]=v
end
end
end
end
function combine(r)
--apply multiple patching methods
return function(n,p,i)
if r ~= nil then
for _,v in pairs(r) do
v(n,p,i)
end
end
end
end
function fix(k,t)
--change a value by those indicated
return function(n,p,i)
if t[p[k]] ~= nil then
p[k]=t[p[k]]
end
end
end
Code: Select all
require("lfs")
function script_path()
return debug.getinfo(2, "S").source:sub(2):match("(.*/)")
end
function dirtree(dir)
assert(dir and dir ~= "", "directory parameter is missing or empty")
if string.sub(dir, -1) == "/" then
dir=string.sub(dir, 1, -2)
end
local function yieldtree(dir)
for entry in lfs.dir(dir) do
if entry ~= "." and entry ~= ".." then
entry=dir.."/"..entry
local attr=lfs.attributes(entry)
coroutine.yield(entry,attr)
if attr.mode == "directory" then
yieldtree(entry)
end
end
end
end
return coroutine.wrap(function() yieldtree(dir) end)
end
dir = script_path()
f=io.open(dir.."config.lua", "w")
f:write("merge(overwrite_graphics,{\n")
for filename, attr in dirtree(dir) do
if filename:sub(-4) == ".png" then
f:write(" [\""..filename:gsub(dir:gsub("%-","%%-"),"").."\"]=replace{},\n")
end
end
f:write("})")
Code: Select all
require("texturepack_toolkit")
prequire("config")
patch()
Create a texture pack
There is 3 things to know about factorio and the toolkit :
Simply put textures inside the mod like that :
Original file :__base__/graphics/icons/iron-plate.png
Your file :__yourmod__/__base__/graphics/icons/iron-plate.png
Then start update.lua
You can't resize textures by this way, you need to go to hard version if you want to resize textures ...
Hard version :
Additionnaly to the easy version, you need to look at the code of factorio to add some important lines after prequire("config") and before patch(), Here an example for the textures of the stone-furnace on the graphic wiki :
- Factorio keep a cache that is related to textures named crop-cache.dat, if something is wrong, remove it and restart the game.
- Factorio don't let scripts listing folders, so this toolkit add a lua file named update.lua that list the mod folder and save the result in config.lua.
- Factorio consider texturepack mods (only texture modification, nothing else) as mods that need synchronisation, if you use it on a server, all other players need to use it.
Simply put textures inside the mod like that :
Original file :__base__/graphics/icons/iron-plate.png
Your file :__yourmod__/__base__/graphics/icons/iron-plate.png
Then start update.lua
You can't resize textures by this way, you need to go to hard version if you want to resize textures ...
Hard version :
Additionnaly to the easy version, you need to look at the code of factorio to add some important lines after prequire("config") and before patch(), Here an example for the textures of the stone-furnace on the graphic wiki :
Code: Select all
merge(overwrite_graphics,{
["__base__/graphics/entity/stone-furnace/stone-furnace.png"]=replace{width=91,height=69},
["__base__/graphics/entity/stone-furnace/stone-furnace-fire.png"]=replace{width = 25,height = 24},
})
Use a texture pack
Any texture pack is in fact a mod, so simply put the zip in the mod folder.
If you update a mod, it should be needed to remove crop-cache.dat ...
If you update a mod, it should be needed to remove crop-cache.dat ...