2023-05-24 19:39:20 +02:00
|
|
|
-- Texture Modifier representation for building, parsing and stringifying texture modifiers according to
|
|
|
|
-- https://github.com/minetest/minetest_docs/blob/master/doc/texture_modifiers.adoc
|
|
|
|
|
|
|
|
local function component(component_name, ...)
|
|
|
|
return assert(loadfile(modlib.mod.get_resource(modlib.modname, "minetest", "texmod", component_name .. ".lua")))(...)
|
|
|
|
end
|
|
|
|
|
|
|
|
local texmod, metatable = component"dsl"
|
2023-05-31 20:01:34 +02:00
|
|
|
local methods = metatable.__index
|
|
|
|
methods.write = component"write"
|
2023-05-24 19:39:20 +02:00
|
|
|
texmod.read = component("read", texmod)
|
2023-06-10 14:56:07 +02:00
|
|
|
methods.calc_dims = component"calc_dims"
|
|
|
|
methods.gen_tex = component"gen_tex"
|
2023-05-24 19:39:20 +02:00
|
|
|
|
|
|
|
function metatable:__tostring()
|
|
|
|
local rope = {}
|
|
|
|
self:write(function(str) rope[#rope+1] = str end)
|
|
|
|
return table.concat(rope)
|
|
|
|
end
|
|
|
|
|
2023-06-02 16:19:56 +02:00
|
|
|
function texmod.read_string(str, warn --[[function(warn_str)]])
|
2023-05-24 19:39:20 +02:00
|
|
|
local i = 0
|
|
|
|
return texmod.read(function()
|
|
|
|
i = i + 1
|
|
|
|
if i > #str then return end
|
|
|
|
return str:sub(i, i)
|
2023-06-02 16:19:56 +02:00
|
|
|
end, warn)
|
2023-05-24 19:39:20 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
return texmod
|