Imported from trollstream "ContentDB"
commit
b0827204f3
|
@ -0,0 +1,7 @@
|
|||
ISC Licence
|
||||
|
||||
Copyright 2022 olive (GoodClover) <oliversimmo@gmail.com>
|
||||
|
||||
Permission to use, copy, modify, and/or distribute this software for any purpose with or without fee is hereby granted, provided that the above copyright notice and this permission notice appear in all copies.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
|
@ -0,0 +1,29 @@
|
|||
# Text Text.
|
||||
|
||||
Replaces textures of all nodes with their names.
|
||||
|
||||
## Cache
|
||||
|
||||
Toggle `texttext_cache_enabled`, cache is diabled by default.
|
||||
Cache requires an insecure environment.
|
||||
Textures are cached in the mod's folder.
|
||||
|
||||
To clear the texture cache run `/texttext_clear`.
|
||||
This requires the `server` priv (operator).
|
||||
|
||||
If you plan to run Text Text on a server, it is reccomended to enable cache.
|
||||
Without it `[png` is used, which has a larger network impact.
|
||||
|
||||
## Config
|
||||
|
||||
To change the name format see option `texttext_name_format`.
|
||||
You may use:
|
||||
|
||||
- The full techical name.
|
||||
- The techincal name, excluding modname.
|
||||
- The short description / user-facing name. [BROKEN]
|
||||
- The full description. [BROKEN]
|
||||
|
||||
##
|
||||
|
||||
© 2022 olive (GoodClover) - ISC Licence
|
|
@ -0,0 +1,326 @@
|
|||
|
||||
local back = "\255\255\255\255"
|
||||
local front = "\000\000\000\255"
|
||||
|
||||
|
||||
|
||||
local function f(str)
|
||||
local split_str = {}
|
||||
for line in str:gmatch("([^\n]+)\n?") do
|
||||
split_str[#split_str+1] = line
|
||||
:gsub("\n", "")
|
||||
:gsub("%s", back)
|
||||
:gsub("X", front)
|
||||
end
|
||||
return split_str
|
||||
end
|
||||
|
||||
return {
|
||||
|
||||
--- Meta ---
|
||||
|
||||
back = back,
|
||||
front = front,
|
||||
|
||||
width = 4,
|
||||
height = 4,
|
||||
|
||||
|
||||
|
||||
--- Characters ---
|
||||
|
||||
-- the last column is used for spacing.
|
||||
-- the width and height needs to exactly match, including trailing whitespace!
|
||||
-- turn on visible whitespace in your editor.
|
||||
|
||||
notdef = ("\255\000\255\255"):rep(4*4),
|
||||
|
||||
|
||||
|
||||
-- Letters --
|
||||
|
||||
a = f[[
|
||||
|
||||
X
|
||||
X X
|
||||
XX
|
||||
]],
|
||||
|
||||
b = f[[
|
||||
X
|
||||
XX
|
||||
X X
|
||||
XX
|
||||
]],
|
||||
|
||||
c = f[[
|
||||
|
||||
XX
|
||||
X
|
||||
XX
|
||||
]],
|
||||
|
||||
d = f[[
|
||||
X
|
||||
XX
|
||||
X X
|
||||
XX
|
||||
]],
|
||||
|
||||
e = f[[
|
||||
X
|
||||
X X
|
||||
XX
|
||||
XX
|
||||
]],
|
||||
|
||||
f = f[[
|
||||
X
|
||||
X
|
||||
XXX
|
||||
X
|
||||
]],
|
||||
|
||||
g = f[[
|
||||
XX
|
||||
X X
|
||||
XX
|
||||
XX
|
||||
]],
|
||||
|
||||
h = f[[
|
||||
X
|
||||
X
|
||||
XXX
|
||||
X X
|
||||
]],
|
||||
|
||||
i = f[[
|
||||
X
|
||||
|
||||
X
|
||||
X
|
||||
]],
|
||||
|
||||
j = f[[
|
||||
X
|
||||
|
||||
X
|
||||
XX
|
||||
]],
|
||||
|
||||
k = f[[
|
||||
X
|
||||
X X
|
||||
XX
|
||||
X X
|
||||
]],
|
||||
|
||||
l = f[[
|
||||
X
|
||||
X
|
||||
X
|
||||
XX
|
||||
]],
|
||||
|
||||
m = f[[
|
||||
|
||||
XX
|
||||
XXX
|
||||
X X
|
||||
]],
|
||||
|
||||
n = f[[
|
||||
|
||||
XX
|
||||
X X
|
||||
X X
|
||||
]],
|
||||
|
||||
o = f[[
|
||||
|
||||
XXX
|
||||
X X
|
||||
XXX
|
||||
]],
|
||||
|
||||
p = f[[
|
||||
XX
|
||||
X X
|
||||
XX
|
||||
X
|
||||
]],
|
||||
|
||||
q = f[[
|
||||
XX
|
||||
X X
|
||||
XX
|
||||
X
|
||||
]],
|
||||
|
||||
r = f[[
|
||||
|
||||
XXX
|
||||
X
|
||||
X
|
||||
]],
|
||||
|
||||
s = f[[
|
||||
XX
|
||||
X
|
||||
X
|
||||
XX
|
||||
]],
|
||||
|
||||
t = f[[
|
||||
X
|
||||
XXX
|
||||
X
|
||||
X
|
||||
]],
|
||||
|
||||
u = f[[
|
||||
|
||||
X X
|
||||
X X
|
||||
XX
|
||||
]],
|
||||
|
||||
v = f[[
|
||||
|
||||
X X
|
||||
X X
|
||||
X
|
||||
]],
|
||||
|
||||
w = f[[
|
||||
|
||||
X X
|
||||
XXX
|
||||
XX
|
||||
]],
|
||||
|
||||
x = f[[
|
||||
|
||||
X X
|
||||
X
|
||||
X X
|
||||
]],
|
||||
|
||||
y = f[[
|
||||
X X
|
||||
XXX
|
||||
X
|
||||
XX
|
||||
]],
|
||||
|
||||
z = f[[
|
||||
XXX
|
||||
X
|
||||
X
|
||||
XXX
|
||||
]],
|
||||
|
||||
|
||||
|
||||
-- Numbers --
|
||||
|
||||
['0'] = f[[
|
||||
X
|
||||
X X
|
||||
X X
|
||||
X
|
||||
]],
|
||||
|
||||
['1'] = f[[
|
||||
XX
|
||||
X
|
||||
X
|
||||
X
|
||||
]],
|
||||
|
||||
['2'] = f[[
|
||||
XX
|
||||
X
|
||||
X
|
||||
XXX
|
||||
]],
|
||||
|
||||
['3'] = f[[
|
||||
XX
|
||||
X
|
||||
XXX
|
||||
XX
|
||||
]],
|
||||
|
||||
['4'] = f[[
|
||||
X
|
||||
XX
|
||||
XXX
|
||||
X
|
||||
]],
|
||||
|
||||
['5'] = f[[
|
||||
XXX
|
||||
XX
|
||||
X
|
||||
XXX
|
||||
]],
|
||||
|
||||
['6'] = f[[
|
||||
XXX
|
||||
XX
|
||||
X X
|
||||
XXX
|
||||
]],
|
||||
|
||||
['7'] = f[[
|
||||
XXX
|
||||
X
|
||||
X
|
||||
X
|
||||
]],
|
||||
|
||||
-- you really have to squint for this one ^^
|
||||
['8'] = f[[
|
||||
XXX
|
||||
XXX
|
||||
X X
|
||||
XXX
|
||||
]],
|
||||
|
||||
['9'] = f[[
|
||||
XXX
|
||||
X X
|
||||
XX
|
||||
XXX
|
||||
]],
|
||||
|
||||
|
||||
|
||||
-- Misc --
|
||||
|
||||
['_'] = f[[
|
||||
|
||||
|
||||
|
||||
XXX
|
||||
]],
|
||||
|
||||
[':'] = f[[
|
||||
|
||||
X
|
||||
|
||||
X
|
||||
]],
|
||||
|
||||
[' '] = f[[
|
||||
|
||||
|
||||
|
||||
|
||||
]],
|
||||
|
||||
-- End --
|
||||
|
||||
}
|
|
@ -0,0 +1,73 @@
|
|||
|
||||
local modname = minetest.get_current_modname()
|
||||
local modpath = minetest.get_modpath(modname)
|
||||
|
||||
local texgen = assert(loadfile(modpath.."/texgen.lua"))()
|
||||
|
||||
local name_format = minetest.settings:get("texttext_name_format") or "name_item"
|
||||
local name_format_choices = { "name_full", "name_item", "desc_full", "desc_short", }
|
||||
|
||||
local cache_enabled = (minetest.settings:get("texttext_cache_enabled") or "false") == "true"
|
||||
|
||||
local insecure = nil
|
||||
local existing_textures = {}
|
||||
if cache_enabled then
|
||||
insecure = minetest.request_insecure_environment()
|
||||
if not insecure then
|
||||
error("Text Text requires an insecure env for texture caching."
|
||||
.." Either disable cache or add texttext to trusted mods.", 0)
|
||||
end
|
||||
|
||||
for i, format in ipairs(name_format_choices) do
|
||||
local path = modpath.."/textures/"..format
|
||||
minetest.mkdir(path)
|
||||
for j, filename in ipairs(minetest.get_dir_list(path, false)) do
|
||||
existing_textures[filename] = true
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
minetest.register_on_mods_loaded(function()
|
||||
if cache_enabled then
|
||||
for name, def in pairs(minetest.registered_nodes) do
|
||||
local filename = "texttext__"..name_format.."__"..name:gsub(":", "8")..".png"
|
||||
minetest.override_item(name, { tiles={filename} })
|
||||
|
||||
if not existing_textures[filename] then
|
||||
existing_textures[filename] = true
|
||||
local png = texgen(name, def)
|
||||
local filepath = modpath.."/textures/"..name_format.."/"..filename
|
||||
-- would be nice if mintest.safe_file_write worked in an insecure env
|
||||
local file = insecure.io.open(filepath, "wb")
|
||||
file:write(png)
|
||||
file:close()
|
||||
end
|
||||
end
|
||||
else
|
||||
for name, def in pairs(minetest.registered_nodes) do
|
||||
minetest.override_item(name, {
|
||||
tiles = { "^[png:"..minetest.encode_base64(texgen(name, def)) },
|
||||
})
|
||||
end
|
||||
end
|
||||
end)
|
||||
|
||||
minetest.register_chatcommand("texttext_clear", {
|
||||
params = "",
|
||||
description = "Clear the Text Text image cache."
|
||||
.. "\nWill cause textures to be re-generated next load.",
|
||||
privs = { server=true, },
|
||||
func = function(name, param)
|
||||
if not cache_enabled then
|
||||
return false, "Cache is disabled. Nothing changed."
|
||||
end
|
||||
-- would be nice if minetest.rmdir worked in an insecure env
|
||||
for i, format in ipairs(name_format_choices) do
|
||||
local path = modpath.."/textures/"..format.."/"
|
||||
for j, filename in pairs(minetest.get_dir_list(path, false)) do
|
||||
insecure.os.remove(path..filename)
|
||||
existing_textures[filename] = nil
|
||||
end
|
||||
end
|
||||
end,
|
||||
})
|
|
@ -0,0 +1,6 @@
|
|||
name = texttext
|
||||
min_minetest_version = 5.5
|
||||
|
||||
title = Text Text.
|
||||
author = olive (GoodClover)
|
||||
description = Replace node's textures with their name.
|
|
@ -0,0 +1,13 @@
|
|||
|
||||
# What text should be used for the item name?
|
||||
# All text is unicase.
|
||||
#
|
||||
# - name_full: technical name ("pets:hungry_dog")
|
||||
# - name_item: techincal name, excluding modname ("hungry_dog")
|
||||
# - desc_full: full item desc. (multi-line) [BROKEN]
|
||||
# - desc_short: short item desc. / user-facing name (single-line) [BROKEN]
|
||||
texttext_name_format (Name Format) enum name_item name_full,name_item,desc_full,desc_short
|
||||
|
||||
# Use texture cache?
|
||||
# Disabling allows not using an insecure environment.
|
||||
texttext_cache_enabled (Cache) bool false
|
|
@ -0,0 +1,68 @@
|
|||
|
||||
local modname = minetest.get_current_modname()
|
||||
local modpath = minetest.get_modpath(modname)
|
||||
|
||||
local chars = assert(loadfile(modpath .. "/chars.lua"))()
|
||||
|
||||
local name_format = minetest.settings:get("texttext_name_format") or "name_item"
|
||||
local name_functions = {
|
||||
name_full = function(name, def) -- technical name
|
||||
return name
|
||||
end,
|
||||
name_item = function(name, def) -- technical name, minus modname
|
||||
return name:match("^.-:(.+)$") or name
|
||||
end,
|
||||
desc_full = function(name, def) -- description
|
||||
local s = def.description or def.short_description or name
|
||||
return minetest.get_translated_string(s, "en") or s
|
||||
end,
|
||||
desc_short = function(name, def) -- short description
|
||||
s = ItemStack(name):get_short_description()
|
||||
return minetest.get_translated_string(s, "en") or s
|
||||
end,
|
||||
}
|
||||
local name_fn = name_functions[name_format]
|
||||
|
||||
return function(name, def)
|
||||
local sname = name_fn(name, def):lower()
|
||||
|
||||
local h = chars.height
|
||||
local w = chars.width * #sname + 1
|
||||
-- +1 for left-padding (right-padding is built-in to font)
|
||||
|
||||
local tex = {}
|
||||
for row = 1, h do
|
||||
-- initial pixel for left padding
|
||||
tex[row] = { chars.back }
|
||||
end
|
||||
|
||||
for i = 1, #sname do
|
||||
local c = sname:sub(i,i)
|
||||
local char = chars[c] or chars.notdef
|
||||
for row = 1, h do
|
||||
tex[row][#tex[row]+1] = char[row]
|
||||
end
|
||||
end
|
||||
|
||||
if h < w then
|
||||
local blank_row = { string.rep(chars.back, w) }
|
||||
|
||||
local new_tex = {}
|
||||
for i = 1, math.floor((w-h)/2) do
|
||||
new_tex[#new_tex+1] = blank_row
|
||||
end
|
||||
for i = 1, h do
|
||||
new_tex[#new_tex+1] = tex[i]
|
||||
end
|
||||
for i = 1, math.ceil((w-h)/2) do
|
||||
new_tex[#new_tex+1] = blank_row
|
||||
end
|
||||
h = w
|
||||
tex = new_tex
|
||||
end
|
||||
|
||||
for row = 1, h do
|
||||
tex[row] = table.concat(tex[row])
|
||||
end
|
||||
return minetest.encode_png(w, h, table.concat(tex))
|
||||
end
|
Loading…
Reference in New Issue