- refactor/reformat code
- add UTF-8 support - add cyrillic characters - add character texture generator - rerender all characters as 32x32 texturesmaster
|
@ -0,0 +1,75 @@
|
|||
var page = require('webpage').create();
|
||||
var w = 32;
|
||||
var h = 32;
|
||||
var con = console;
|
||||
|
||||
//viewportSize being the actual size of the headless browser
|
||||
page.viewportSize = { width: w, height: h };
|
||||
|
||||
//the clipRect is the portion of the page you are taking a screenshot of
|
||||
page.clipRect = { top: 0, left: 0, width: w, height: h };
|
||||
|
||||
page.content = '<html><body><div id="character"></div></body></html>';
|
||||
|
||||
var chars = [
|
||||
// numbers
|
||||
"1", "2", "3", "4", "5", "6", "7", "8", "9", "0",
|
||||
// latin
|
||||
"A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O",
|
||||
"P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z",
|
||||
// special chars
|
||||
"!", "#", "$", "%", "&", "(", ")", "*", "+", ",", "-", ".", "/", ":", ";",
|
||||
"<", "=", ">", "?", "@", '"', "'",
|
||||
// cyrillic
|
||||
"А", "Б", "В", "Г", "Д", "Е", "Ё", "Ж", "З", "И", "Й", "К", "Л", "М", "Н",
|
||||
"О", "П", "Р", "С", "Т", "У", "Ф", "Х", "Ц", "Ч", "Ш", "Щ", "Ъ", "Ы", "Ь",
|
||||
"Э", "Ю", "Я"
|
||||
];
|
||||
|
||||
function encode_utf8(s) {
|
||||
return unescape(encodeURIComponent(s));
|
||||
}
|
||||
|
||||
function decode_utf8(s) {
|
||||
return decodeURIComponent(escape(s));
|
||||
}
|
||||
|
||||
function pad(n, width, z) {
|
||||
z = z || '0';
|
||||
n = n + '';
|
||||
return n.length >= width ? n : new Array(width - n.length + 1).join(z) + n;
|
||||
}
|
||||
|
||||
page.evaluate(function () {
|
||||
var chEl = document.getElementById('character');
|
||||
|
||||
document.body.style.backgroundColor = 'white';
|
||||
document.body.style.margin = '0px';
|
||||
chEl.style.fontSize = '24px';
|
||||
chEl.style.fontWeight = 'bold';
|
||||
chEl.style.marginTop = '2px';
|
||||
chEl.style.textAlign = 'center';
|
||||
});
|
||||
|
||||
page.render('textures/ehlphabet_000.png');
|
||||
|
||||
chars.forEach(function (ch) {
|
||||
var file;
|
||||
page.evaluate(function (ch) {
|
||||
var chEl = document.getElementById('character');
|
||||
chEl.innerText = ch;
|
||||
}, ch);
|
||||
|
||||
ch = encode_utf8(ch);
|
||||
if (ch.length > 1) {
|
||||
file = pad(ch.charCodeAt(0), 3) + '_' + pad(ch.charCodeAt(1), 3);
|
||||
} else {
|
||||
file = pad(ch.charCodeAt(0), 3);
|
||||
}
|
||||
|
||||
page.render('textures/ehlphabet_' + file + '.png');
|
||||
});
|
||||
|
||||
console.log('done');
|
||||
|
||||
phantom.exit();
|
279
init.lua
|
@ -1,124 +1,189 @@
|
|||
local characters = {"A","B","C","D","E","F","G","H","I","J","K","L","M","N","O","P","Q","R","S","T","U","V","W","X","Y","Z","1","2","3","4","5","6","7","8","9","0","!","#","$","%","&","(",")","*","+",",","-",".","/",":",";","<","=",">","?","@"}
|
||||
local digits = {"1", "2", "3", "4", "5", "6", "7", "8", "9", "0"}
|
||||
local base_chars = {
|
||||
"A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O",
|
||||
"P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z"
|
||||
}
|
||||
local special_chars = {
|
||||
"!", "#", "$", "%", "&", "(", ")", "*", "+", ",", "-", ".", "/", ":", ";",
|
||||
"<", "=", ">", "?", "@", "'", '"'
|
||||
}
|
||||
local cyrillic_chars = {
|
||||
"А", "Б", "В", "Г", "Д", "Е", "Ё", "Ж", "З", "И", "Й", "К", "Л", "М", "Н",
|
||||
"О", "П", "Р", "С", "Т", "У", "Ф", "Х", "Ц", "Ч", "Ш", "Щ", "Ъ", "Ы", "Ь",
|
||||
"Э", "Ю", "Я"
|
||||
}
|
||||
local characters = {}
|
||||
|
||||
-- Alias (Och_Noe 20180124)
|
||||
local compat_characters = {"A","B","C","D","E","F","G","H","I","J","K","L","M","N","O","P","Q","R","S","T","U","V","W","X","Y","Z","1","2","3","4","5","6","7","8","9","0"} -- for reference, unused
|
||||
--
|
||||
|
||||
-- Alias (Och_Noe 20180124)
|
||||
create_alias = true
|
||||
--
|
||||
ehlphabet = {}
|
||||
ehlphabet.path = minetest.get_modpath(minetest.get_current_modname())
|
||||
|
||||
for _, name in ipairs(characters) do --do this for all characters in the list
|
||||
local byte = string.byte(name)
|
||||
if byte < 10 then file = "00"..byte end
|
||||
if byte > 10 and byte < 100 then file = "0"..byte end
|
||||
if byte > 100 then file = tostring(byte) end
|
||||
local desc = "The \'"..name.."\' Character"
|
||||
|
||||
minetest.register_node("ehlphabet:"..byte, {
|
||||
description = "Ehlphabet Block \'"..name.."\'",
|
||||
tiles = {"ehlphabet_"..file..".png"},
|
||||
groups = {cracky=3,not_in_creative_inventory=1,not_in_crafting_guide=1}
|
||||
})
|
||||
minetest.register_craft ({ type="shapeless", output = "ehlphabet:block", recipe = {"ehlphabet:"..byte} })
|
||||
if name == "!" then create_alias = false end
|
||||
|
||||
-- Alias (Och_Noe 20180124)
|
||||
if create_alias then
|
||||
minetest.register_alias("abjphabet:"..name:lower(),"ehlphabet:"..byte)
|
||||
end
|
||||
--
|
||||
|
||||
local function table_merge(t1, t2)
|
||||
for k, v in ipairs(t2) do
|
||||
table.insert(t1, v)
|
||||
end
|
||||
return t1
|
||||
end
|
||||
|
||||
|
||||
minetest.register_node("ehlphabet:machine", {
|
||||
description = "Letter Machine",
|
||||
tiles = {"ehlphabet_machine_top.png", "ehlphabet_machine_bottom.png", "ehlphabet_machine_side.png",
|
||||
"ehlphabet_machine_side.png", "ehlphabet_machine_back.png", "ehlphabet_machine_front.png"},
|
||||
paramtype = "light",
|
||||
paramtype2 = "facedir",
|
||||
groups = {cracky=2},
|
||||
|
||||
can_dig = function(pos, player) -- "Can you dig it?" -Cyrus
|
||||
local meta = minetest.env:get_meta(pos)
|
||||
local inv = meta:get_inventory()
|
||||
if not inv:is_empty("input") or not inv:is_empty("output") then
|
||||
if player then
|
||||
minetest.chat_send_player(player:get_player_name(), "You cannot dig the Letter Machine with blocks inside")
|
||||
end -- end if player
|
||||
return false
|
||||
end -- end if not empty
|
||||
return true
|
||||
end, -- end can_dig function
|
||||
|
||||
after_place_node = function(pos, placer)
|
||||
local meta = minetest.env:get_meta(pos)
|
||||
end,
|
||||
local function is_multibyte(ch)
|
||||
local byte = ch:byte()
|
||||
return (208 == byte) or (209 == byte)
|
||||
end
|
||||
|
||||
on_construct = function(pos)
|
||||
local meta = minetest.env:get_meta(pos)
|
||||
meta:set_string("formspec", "invsize[8,6;]"..
|
||||
"field[3.8,.5;1,1;lettername;Letter;]"..
|
||||
"list[current_name;input;2.5,0.2;1,1;]"..
|
||||
"list[current_name;output;4.5,0.2;1,1;]"..
|
||||
"list[current_player;main;0,2;8,4;]"..
|
||||
"button[2.54,-0.25;3,4;name;Blank -> Letter]")
|
||||
local inv = meta:get_inventory()
|
||||
inv:set_size("input", 1)
|
||||
inv:set_size("output", 1)
|
||||
end,
|
||||
table_merge(characters, base_chars)
|
||||
table_merge(characters, digits)
|
||||
table_merge(characters, special_chars)
|
||||
table_merge(characters, cyrillic_chars)
|
||||
|
||||
on_receive_fields = function(pos, formname, fields, sender)
|
||||
local meta = minetest.env:get_meta(pos)
|
||||
local inv = meta:get_inventory()
|
||||
local inputstack = inv:get_stack("input", 1)
|
||||
if fields.lettername ~= nil and inputstack:get_name()=="ehlphabet:block" then
|
||||
for _,v in pairs(characters) do
|
||||
if v == fields.lettername then
|
||||
local give = {}
|
||||
give[1] = inv:add_item("output","ehlphabet:"..string.byte(fields.lettername))
|
||||
inputstack:take_item()
|
||||
inv:set_stack("input",1,inputstack)
|
||||
break
|
||||
local create_alias = true
|
||||
|
||||
-- generate all available blocks
|
||||
for _, name in ipairs(characters) do
|
||||
local desc = "The '" .. name .. "' Character"
|
||||
local byte = name:byte()
|
||||
local mb = is_multibyte(name)
|
||||
local file, key
|
||||
|
||||
if mb then
|
||||
mb = byte
|
||||
byte = name:byte(2)
|
||||
key = "ehlphabet:" .. mb .. byte
|
||||
file = ("%03d_%03d"):format(mb, byte)
|
||||
else
|
||||
key = "ehlphabet:" .. byte
|
||||
file = ("%03d"):format(byte)
|
||||
end
|
||||
|
||||
minetest.register_node(
|
||||
key,
|
||||
{
|
||||
description = "Ehlphabet Block '" .. name .. "'",
|
||||
tiles = {"ehlphabet_" .. file .. ".png"},
|
||||
groups = {cracky = 3, not_in_creative_inventory = 1, not_in_crafting_guide = 1}
|
||||
}
|
||||
)
|
||||
minetest.register_craft({type = "shapeless", output = "ehlphabet:block", recipe = {key}})
|
||||
|
||||
if create_alias then
|
||||
minetest.register_alias("abjphabet:" .. name, key)
|
||||
end
|
||||
|
||||
-- deactivate alias creation on last latin character
|
||||
if name == "Z" then
|
||||
create_alias = false
|
||||
end
|
||||
end
|
||||
|
||||
minetest.register_node(
|
||||
"ehlphabet:machine",
|
||||
{
|
||||
description = "Letter Machine",
|
||||
tiles = {
|
||||
"ehlphabet_machine_top.png",
|
||||
"ehlphabet_machine_bottom.png",
|
||||
"ehlphabet_machine_side.png",
|
||||
"ehlphabet_machine_side.png",
|
||||
"ehlphabet_machine_back.png",
|
||||
"ehlphabet_machine_front.png"
|
||||
},
|
||||
paramtype = "light",
|
||||
paramtype2 = "facedir",
|
||||
groups = {cracky = 2},
|
||||
|
||||
-- "Can you dig it?" -Cyrus
|
||||
can_dig = function(pos, player)
|
||||
local meta = minetest.env:get_meta(pos)
|
||||
local inv = meta:get_inventory()
|
||||
if not inv:is_empty("input") or not inv:is_empty("output") then
|
||||
if player then
|
||||
minetest.chat_send_player(
|
||||
player:get_player_name(),
|
||||
"You cannot dig the Letter Machine with blocks inside"
|
||||
)
|
||||
end -- end if player
|
||||
return false
|
||||
end -- end if not empty
|
||||
return true
|
||||
end, -- end can_dig function
|
||||
|
||||
after_place_node = function(pos, placer)
|
||||
local meta = minetest.env:get_meta(pos)
|
||||
end,
|
||||
|
||||
on_construct = function(pos)
|
||||
local meta = minetest.env:get_meta(pos)
|
||||
meta:set_string(
|
||||
"formspec",
|
||||
"invsize[8,6;]" ..
|
||||
"field[3.8,.5;1,1;lettername;Letter;]" ..
|
||||
"list[current_name;input;2.5,0.2;1,1;]" ..
|
||||
"list[current_name;output;4.5,0.2;1,1;]" ..
|
||||
"list[current_player;main;0,2;8,4;]" ..
|
||||
"button[2.54,-0.25;3,4;name;Blank -> Letter]"
|
||||
)
|
||||
local inv = meta:get_inventory()
|
||||
inv:set_size("input", 1)
|
||||
inv:set_size("output", 1)
|
||||
end,
|
||||
|
||||
on_receive_fields = function(pos, formname, fields, sender)
|
||||
local meta = minetest.env:get_meta(pos)
|
||||
local inv = meta:get_inventory()
|
||||
local inputstack = inv:get_stack("input", 1)
|
||||
local ch = fields.lettername
|
||||
|
||||
if ch ~= nil and inputstack:get_name() == "ehlphabet:block" then
|
||||
local mb = is_multibyte(ch)
|
||||
local key = mb and (ch:byte(1) .. ch:byte(2)) or ch:byte()
|
||||
for _, v in pairs(characters) do
|
||||
if v == fields.lettername then
|
||||
local give = {}
|
||||
give[1] = inv:add_item("output", "ehlphabet:" .. key)
|
||||
inputstack:take_item()
|
||||
inv:set_stack("input", 1, inputstack)
|
||||
break
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
})
|
||||
end
|
||||
}
|
||||
)
|
||||
|
||||
|
||||
-- Alias (Och_Noe 20180124)
|
||||
minetest.register_alias("abjphabet:machine","ehlphabet:machine")
|
||||
--
|
||||
|
||||
minetest.register_node("ehlphabet:block", {
|
||||
description = "Ehlphabet Block (blank)",
|
||||
tiles = {"ehlphabet_000.png"},
|
||||
groups = {cracky=3},
|
||||
})
|
||||
-- Alias (Och_Noe 20180124)
|
||||
minetest.register_alias("abjphabet:machine", "ehlphabet:machine")
|
||||
--
|
||||
|
||||
minetest.register_node(
|
||||
"ehlphabet:block",
|
||||
{
|
||||
description = "Ehlphabet Block (blank)",
|
||||
tiles = {"ehlphabet_000.png"},
|
||||
groups = {cracky = 3}
|
||||
}
|
||||
)
|
||||
|
||||
--RECIPE: blank blocks
|
||||
minetest.register_craft({ output = "ehlphabet:block 8",
|
||||
recipe = {
|
||||
{'default:paper', 'default:paper', 'default:paper'},
|
||||
{'default:paper', '', 'default:paper'},
|
||||
{'default:paper', 'default:paper', 'default:paper'},
|
||||
}
|
||||
minetest.register_craft({
|
||||
output = "ehlphabet:block 8",
|
||||
recipe = {
|
||||
{"default:paper", "default:paper", "default:paper"},
|
||||
{"default:paper", "", "default:paper"},
|
||||
{"default:paper", "default:paper", "default:paper"}
|
||||
}
|
||||
})
|
||||
|
||||
--RECIPE: build the machine!
|
||||
minetest.register_craft({ output = "ehlphabet:machine",
|
||||
recipe = {
|
||||
{'default:stick', 'default:coal_lump', 'default:stick'},
|
||||
{'default:coal_lump', 'ehlphabet:block', 'default:coal_lump'},
|
||||
{'default:stick', 'default:coal_lump', 'default:stick'},
|
||||
}
|
||||
minetest.register_craft({
|
||||
output = "ehlphabet:machine",
|
||||
recipe = {
|
||||
{"default:stick", "default:coal_lump", "default:stick"},
|
||||
{"default:coal_lump", "ehlphabet:block", "default:coal_lump"},
|
||||
{"default:stick", "default:coal_lump", "default:stick"}
|
||||
}
|
||||
})
|
||||
|
||||
--RECIPE: craft unused blocks back into paper
|
||||
minetest.register_craft ({ output = "default:paper",
|
||||
recipe = {"ehlphabet:block"},
|
||||
type = "shapeless"
|
||||
minetest.register_craft({
|
||||
output = "default:paper",
|
||||
recipe = {"ehlphabet:block"},
|
||||
type = "shapeless"
|
||||
})
|
||||
|
|
Before Width: | Height: | Size: 412 B After Width: | Height: | Size: 125 B |
Before Width: | Height: | Size: 1.2 KiB After Width: | Height: | Size: 280 B |
Before Width: | Height: | Size: 1.2 KiB After Width: | Height: | Size: 205 B |
Before Width: | Height: | Size: 1.6 KiB After Width: | Height: | Size: 459 B |
Before Width: | Height: | Size: 1.7 KiB After Width: | Height: | Size: 571 B |
Before Width: | Height: | Size: 2.4 KiB After Width: | Height: | Size: 742 B |
Before Width: | Height: | Size: 2.2 KiB After Width: | Height: | Size: 668 B |
Before Width: | Height: | Size: 917 B After Width: | Height: | Size: 197 B |
Before Width: | Height: | Size: 1.4 KiB After Width: | Height: | Size: 419 B |
Before Width: | Height: | Size: 1.4 KiB After Width: | Height: | Size: 411 B |
Before Width: | Height: | Size: 1.4 KiB After Width: | Height: | Size: 414 B |
Before Width: | Height: | Size: 516 B After Width: | Height: | Size: 214 B |
Before Width: | Height: | Size: 912 B After Width: | Height: | Size: 267 B |
Before Width: | Height: | Size: 488 B After Width: | Height: | Size: 156 B |
Before Width: | Height: | Size: 723 B After Width: | Height: | Size: 193 B |
Before Width: | Height: | Size: 1.3 KiB After Width: | Height: | Size: 346 B |
Before Width: | Height: | Size: 1.8 KiB After Width: | Height: | Size: 466 B |
Before Width: | Height: | Size: 872 B After Width: | Height: | Size: 278 B |
Before Width: | Height: | Size: 1.5 KiB After Width: | Height: | Size: 427 B |
Before Width: | Height: | Size: 1.6 KiB After Width: | Height: | Size: 531 B |
Before Width: | Height: | Size: 1.2 KiB After Width: | Height: | Size: 338 B |
Before Width: | Height: | Size: 1.5 KiB After Width: | Height: | Size: 418 B |
Before Width: | Height: | Size: 1.8 KiB After Width: | Height: | Size: 526 B |
Before Width: | Height: | Size: 1.3 KiB After Width: | Height: | Size: 405 B |
Before Width: | Height: | Size: 1.9 KiB After Width: | Height: | Size: 534 B |
Before Width: | Height: | Size: 1.8 KiB After Width: | Height: | Size: 551 B |
Before Width: | Height: | Size: 954 B After Width: | Height: | Size: 248 B |
Before Width: | Height: | Size: 1.1 KiB After Width: | Height: | Size: 331 B |
Before Width: | Height: | Size: 1.2 KiB After Width: | Height: | Size: 379 B |
Before Width: | Height: | Size: 494 B After Width: | Height: | Size: 197 B |
Before Width: | Height: | Size: 1.2 KiB After Width: | Height: | Size: 404 B |
Before Width: | Height: | Size: 1.4 KiB After Width: | Height: | Size: 454 B |
Before Width: | Height: | Size: 2.8 KiB After Width: | Height: | Size: 1.0 KiB |
Before Width: | Height: | Size: 1.7 KiB After Width: | Height: | Size: 498 B |
Before Width: | Height: | Size: 1.6 KiB After Width: | Height: | Size: 508 B |
Before Width: | Height: | Size: 1.7 KiB After Width: | Height: | Size: 553 B |
Before Width: | Height: | Size: 1.5 KiB After Width: | Height: | Size: 456 B |
Before Width: | Height: | Size: 1.2 KiB After Width: | Height: | Size: 430 B |
Before Width: | Height: | Size: 1.1 KiB After Width: | Height: | Size: 375 B |
Before Width: | Height: | Size: 1.8 KiB After Width: | Height: | Size: 558 B |
Before Width: | Height: | Size: 1.2 KiB After Width: | Height: | Size: 353 B |
Before Width: | Height: | Size: 791 B After Width: | Height: | Size: 232 B |
Before Width: | Height: | Size: 1010 B After Width: | Height: | Size: 300 B |
Before Width: | Height: | Size: 1.6 KiB After Width: | Height: | Size: 525 B |
Before Width: | Height: | Size: 988 B After Width: | Height: | Size: 280 B |
Before Width: | Height: | Size: 2.4 KiB After Width: | Height: | Size: 590 B |
Before Width: | Height: | Size: 1.4 KiB After Width: | Height: | Size: 449 B |
Before Width: | Height: | Size: 1.9 KiB After Width: | Height: | Size: 576 B |
Before Width: | Height: | Size: 1.3 KiB After Width: | Height: | Size: 409 B |
Before Width: | Height: | Size: 2.1 KiB After Width: | Height: | Size: 681 B |
Before Width: | Height: | Size: 1.5 KiB After Width: | Height: | Size: 513 B |
Before Width: | Height: | Size: 1.7 KiB After Width: | Height: | Size: 535 B |
Before Width: | Height: | Size: 971 B After Width: | Height: | Size: 341 B |
Before Width: | Height: | Size: 1.5 KiB After Width: | Height: | Size: 381 B |
Before Width: | Height: | Size: 1.7 KiB After Width: | Height: | Size: 507 B |
Before Width: | Height: | Size: 2.1 KiB After Width: | Height: | Size: 656 B |
Before Width: | Height: | Size: 1.8 KiB After Width: | Height: | Size: 536 B |
Before Width: | Height: | Size: 1.4 KiB After Width: | Height: | Size: 436 B |
Before Width: | Height: | Size: 1.5 KiB After Width: | Height: | Size: 478 B |
After Width: | Height: | Size: 504 B |
After Width: | Height: | Size: 498 B |
After Width: | Height: | Size: 469 B |
After Width: | Height: | Size: 508 B |
After Width: | Height: | Size: 303 B |
After Width: | Height: | Size: 519 B |
After Width: | Height: | Size: 430 B |
After Width: | Height: | Size: 668 B |
After Width: | Height: | Size: 525 B |
After Width: | Height: | Size: 481 B |
After Width: | Height: | Size: 595 B |
After Width: | Height: | Size: 503 B |
After Width: | Height: | Size: 437 B |
After Width: | Height: | Size: 590 B |
After Width: | Height: | Size: 353 B |
After Width: | Height: | Size: 576 B |
After Width: | Height: | Size: 276 B |
After Width: | Height: | Size: 409 B |
After Width: | Height: | Size: 553 B |
After Width: | Height: | Size: 341 B |
After Width: | Height: | Size: 489 B |
After Width: | Height: | Size: 592 B |
After Width: | Height: | Size: 536 B |
After Width: | Height: | Size: 353 B |
After Width: | Height: | Size: 412 B |
After Width: | Height: | Size: 324 B |
After Width: | Height: | Size: 400 B |
After Width: | Height: | Size: 446 B |
After Width: | Height: | Size: 466 B |
After Width: | Height: | Size: 391 B |
After Width: | Height: | Size: 576 B |
After Width: | Height: | Size: 701 B |
After Width: | Height: | Size: 478 B |