mirror of
https://github.com/appgurueu/modlib.git
synced 2024-08-20 05:14:10 +02:00
https://github.com/minetest/minetest/pull/10100 has introduced a few inconsistencies with the formats of previous texture modifiers: `[fill` is the first texture modifier to have a modifying and a generating variant. Thus `texmod` "constructors" and `texmod` "modifiers" / methods had to be separated; `texmod.fill` is not the same as `tm.fill` where `tm` is `texmod` instance. It is rather dirty that the generating variant would ignore extraneous parameters of the modifying variant, so this is not replicated by the parser. `[hsl`, `[colorizehsl`, `[contrast` and `[screen` are pretty standard texture modifiers as far as the DSL is concerned. `[hsl` and `[colorizehsl` are very similar. `[hardlight` is the first texture modifier to exist just for swapping the base and parameter. `a^[overlay:b` and `b^[hardlight:a` are both normalized to `b:[hardlight:a` by the DSL. `[overlay` (called "overlay blend" in the docs) creates a naming conflict with literal overlaying (`^`). This is resolved by renaming `:overlay` to `:blit`.
30 lines
859 B
Lua
30 lines
859 B
Lua
-- 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"
|
|
local methods = metatable.__index
|
|
methods.write = component"write"
|
|
texmod.read = component("read", texmod)
|
|
methods.calc_dims = component("calc_dims", texmod)
|
|
|
|
function metatable:__tostring()
|
|
local rope = {}
|
|
self:write(function(str) rope[#rope+1] = str end)
|
|
return table.concat(rope)
|
|
end
|
|
|
|
function texmod.read_string(str)
|
|
local i = 0
|
|
return texmod.read(function()
|
|
i = i + 1
|
|
if i > #str then return end
|
|
return str:sub(i, i)
|
|
end)
|
|
end
|
|
|
|
return texmod
|