diff --git a/init.lua b/init.lua index b29f860..18a7c30 100644 --- a/init.lua +++ b/init.lua @@ -1,134 +1,76 @@ --[[ - Mod Musket para Minetest - Copyright (C) 2018 BrunoMine (https://github.com/BrunoMine) + Musket mod for Minetest + Copyright (C) 2019 BrunoMine (https://github.com/BrunoMine) - Recebeste uma cópia da GNU Lesser General - Public License junto com esse software, - se não, veja em . - - Arma Mosquete + You should have received a copy of the GNU General Public License + along with this program. If not, see . ]] + --- Tabela Global +-- Global Table musket = {} local modpath = minetest.get_modpath("musket") -dofile(modpath.."/tradutor.lua") +-- Make translation files +dofile(modpath.."/translation_file_maker.lua") -local S = musket.S +-- Translate strings +local S = minetest.get_translator("musket") --- Arma descarregada -minetest.register_craftitem("musket:ammo_mosquete_descarregado", { - description = "Mosquete Descarregado", - inventory_image = "musket_mosquete_descarregado.png", - - on_drop = function(itemstack, dropper, pos) - -- Prints a random number and removes one item from the stack - minetest.chat_send_all(math.random()) - itemstack:take_item() - return itemstack - end, -}) - --- Munição de Mosquete -minetest.register_craftitem("musket:ammo_mosquete", { - description = S("Munição para Mosquete"), - inventory_image = "musket_ammo_mosquete.png", - wield_image = "musket_ammo_mosquete_na_mao.png", +-- Musket Ammo +minetest.register_craftitem("musket:musket_ammo", { + description = S("Musket Ammo"), + inventory_image = "musket_ammo_inv.png", + wield_image = "musket_ammo_wielded.png", stack_max = 15, }) --- Mosquete -shooter:register_weapon("musket:mosquete", { - description = S("Mosquete"), - inventory_image = "musket_mosquete.png", - rounds = 1.1, - ammo = "musket:ammo_mosquete", +-- Register Musket shooter +shooter.register_weapon("musket:musket", { + description = S("Musket (Loaded)"), + inventory_image = "musket_loaded.png", + reload_item = "musket:musket_ammo", + unloaded_item = { + description = S("Musket"), + inventory_image = "musket.png", + }, + spec = { + rounds = 1.1, range = 20, step = 30, tool_caps = {full_punch_interval=1.2, damage_groups={fleshy=6}}, - groups = {snappy=3, crumbly=3, choppy=3, fleshy=2, oddly_breakable_by_hand=2}, - sound = "musket_mosquete", + sound = "musket_shot", particle = "shooter_bullet.png", }, }) --- Mosquete Descarregado -shooter:register_weapon("musket:mosquete_descarregado", { - description = S("Mosquete"), - inventory_image = "musket_mosquete_descarregado.png", - rounds = 1.1, - ammo = "musket:ammo_mosquete", - spec = { - range = 20, - step = 30, - tool_caps = {full_punch_interval=1.2, damage_groups={fleshy=6}}, - groups = {snappy=3, crumbly=3, choppy=3, fleshy=2, oddly_breakable_by_hand=2}, - sound = "musket_mosquete", - particle = "shooter_bullet.png", - }, -}) - - --- Ajustes -local old_on_use1 = minetest.registered_tools["musket:mosquete_descarregado"].on_use +-- Exchange mesket to unloaded after a shot +local old_on_use = minetest.registered_tools["musket:musket_loaded"].on_use do - -- Copiar tabela de definições + -- Copy table def local def = {} - for n,d in pairs(minetest.registered_tools["musket:mosquete_descarregado"]) do + for n,d in pairs(minetest.registered_tools["musket:musket_loaded"]) do def[n] = d end - -- Mantem a tabela groups separada + + -- Separate groups def.groups = minetest.deserialize(minetest.serialize(def.groups)) or {} - -- Altera alguns paremetros - def.groups.not_in_creative_inventory = 1 - - -- Troca o mosquete + -- New 'on_use' callback def.on_use = function(itemstack, user, pointed_thing) - if old_on_use1 then - itemstack = old_on_use1(itemstack, user, pointed_thing) + if old_on_use then + itemstack = old_on_use(itemstack, user, pointed_thing) end - -- Verifica se descarregou - if itemstack:get_wear() < 500 then - itemstack:set_name("musket:mosquete") - end + -- Exchange mesket + itemstack:set_name("musket:musket") return itemstack end - -- Registra o novo node - minetest.override_item("musket:mosquete_descarregado", {groups=def.groups, on_use=def.on_use}) + -- Override item + minetest.override_item("musket:musket_loaded", {groups=def.groups, on_use=def.on_use}) end -local old_on_use2 = minetest.registered_tools["musket:mosquete"].on_use -do - -- Copiar tabela de definições - local def = {} - for n,d in pairs(minetest.registered_tools["musket:mosquete"]) do - def[n] = d - end - -- Mantem a tabela groups separada - def.groups = minetest.deserialize(minetest.serialize(def.groups)) or {} - - -- Altera alguns paremetros - -- Troca o mosquete - def.on_use = function(itemstack, user, pointed_thing) - if old_on_use2 then - itemstack = old_on_use2(itemstack, user, pointed_thing) - end - - -- Verifica se descarregou - if itemstack:get_wear() > 50000 then - itemstack:set_name("musket:mosquete_descarregado") - end - - return itemstack - end - - -- Registra o novo node - minetest.override_item("musket:mosquete", {groups=def.groups, on_use=def.on_use}) -end diff --git a/lib/intllib.lua b/lib/intllib.lua deleted file mode 100644 index 6669d72..0000000 --- a/lib/intllib.lua +++ /dev/null @@ -1,45 +0,0 @@ - --- Fallback functions for when `intllib` is not installed. --- Code released under Unlicense . - --- Get the latest version of this file at: --- https://raw.githubusercontent.com/minetest-mods/intllib/master/lib/intllib.lua - -local function format(str, ...) - local args = { ... } - local function repl(escape, open, num, close) - if escape == "" then - local replacement = tostring(args[tonumber(num)]) - if open == "" then - replacement = replacement..close - end - return replacement - else - return "@"..open..num..close - end - end - return (str:gsub("(@?)@(%(?)(%d+)(%)?)", repl)) -end - -local gettext, ngettext -if minetest.get_modpath("intllib") then - if intllib.make_gettext_pair then - -- New method using gettext. - gettext, ngettext = intllib.make_gettext_pair() - else - -- Old method using text files. - gettext = intllib.Getter() - end -end - --- Fill in missing functions. - -gettext = gettext or function(msgid, ...) - return format(msgid, ...) -end - -ngettext = ngettext or function(msgid, msgid_plural, n, ...) - return format(n==1 and msgid or msgid_plural, ...) -end - -return gettext, ngettext diff --git a/locale/Arquivos para traduzir.txt b/locale/Arquivos para traduzir.txt deleted file mode 100644 index dd23724..0000000 --- a/locale/Arquivos para traduzir.txt +++ /dev/null @@ -1 +0,0 @@ -init.lua diff --git a/locale/en.mo b/locale/en.mo deleted file mode 100644 index cc6244e..0000000 Binary files a/locale/en.mo and /dev/null differ diff --git a/locale/en.po b/locale/en.po deleted file mode 100644 index cb59995..0000000 --- a/locale/en.po +++ /dev/null @@ -1,27 +0,0 @@ -# SOME DESCRIPTIVE TITLE. -# Copyright (C) YEAR THE PACKAGE'S COPYRIGHT HOLDER -# This file is distributed under the same license as the PACKAGE package. -# FIRST AUTHOR , YEAR. -# -msgid "" -msgstr "" -"Project-Id-Version: \n" -"Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2018-08-18 22:50-0300\n" -"PO-Revision-Date: 2018-08-18 22:52-0300\n" -"Language-Team: \n" -"MIME-Version: 1.0\n" -"Content-Type: text/plain; charset=UTF-8\n" -"Content-Transfer-Encoding: 8bit\n" -"X-Generator: Poedit 2.0.6\n" -"Last-Translator: \n" -"Plural-Forms: nplurals=2; plural=(n != 1);\n" -"Language: en\n" - -#: init.lua -msgid "Munição para Mosquete" -msgstr "Musket Ammo" - -#: init.lua -msgid "Mosquete" -msgstr "Musket" diff --git a/locale/es.mo b/locale/es.mo new file mode 100644 index 0000000..1deb297 Binary files /dev/null and b/locale/es.mo differ diff --git a/locale/es.po b/locale/es.po new file mode 100644 index 0000000..b3d40b2 --- /dev/null +++ b/locale/es.po @@ -0,0 +1,31 @@ +# Musket mod for Minetest. +# Copyright (C) 2019 +# This file is distributed under the same license as the Musket package. +# BrunoMine , 2019. +# +msgid "" +msgstr "" +"Project-Id-Version: 0.6.0\n" +"Report-Msgid-Bugs-To: \n" +"POT-Creation-Date: 2019-03-24 01:03-0300\n" +"PO-Revision-Date: 2019-03-24 01:40-0300\n" +"Language-Team: TEMPLATE\n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: 8bit\n" +"X-Generator: Poedit 2.0.6\n" +"Last-Translator: \n" +"Plural-Forms: nplurals=2; plural=(n != 1);\n" +"Language: es\n" + +#: init.lua +msgid "Musket Ammo" +msgstr "Munición de Mosquete" + +#: init.lua +msgid "Musket (Loaded)" +msgstr "Mosquete (Cargado)" + +#: init.lua +msgid "Musket" +msgstr "Mosquete" diff --git a/locale/musket.en.tr b/locale/musket.en.tr deleted file mode 100644 index a2513ab..0000000 --- a/locale/musket.en.tr +++ /dev/null @@ -1,4 +0,0 @@ -### Arquivo gerado por musket apartir de en.po -# textdomain: musket -Musket Ammo=Musket Ammo -Musket=Musket diff --git a/locale/musket.es.tr b/locale/musket.es.tr new file mode 100644 index 0000000..8bd12f3 --- /dev/null +++ b/locale/musket.es.tr @@ -0,0 +1,5 @@ +### File generated by musket from es.po +# textdomain: musket +Musket (Loaded)=Mosquete (Cargado) +Musket=Mosquete +Musket Ammo=Munición de Mosquete diff --git a/locale/musket.pt.tr b/locale/musket.pt.tr index 6770911..8330110 100644 --- a/locale/musket.pt.tr +++ b/locale/musket.pt.tr @@ -1,4 +1,5 @@ -### Arquivo gerado por musket apartir de pt.po +### File generated by musket from pt.po # textdomain: musket -Musket Ammo=Munição para Mosquete +Musket (Loaded)=Mosquete (Carregado) Musket=Mosquete +Musket Ammo=Munição de Mosquete diff --git a/locale/pt.mo b/locale/pt.mo index 228e6a2..dfabd02 100644 Binary files a/locale/pt.mo and b/locale/pt.mo differ diff --git a/locale/pt.po b/locale/pt.po index d51d4e3..6fed5a0 100644 --- a/locale/pt.po +++ b/locale/pt.po @@ -1,15 +1,15 @@ -# SOME DESCRIPTIVE TITLE. -# Copyright (C) YEAR THE PACKAGE'S COPYRIGHT HOLDER -# This file is distributed under the same license as the PACKAGE package. -# FIRST AUTHOR , YEAR. +# Musket mod for Minetest. +# Copyright (C) 2019 +# This file is distributed under the same license as the Musket package. +# BrunoMine , 2019. # msgid "" msgstr "" -"Project-Id-Version: \n" +"Project-Id-Version: 0.6.0\n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2018-08-18 22:50-0300\n" -"PO-Revision-Date: 2018-08-18 22:53-0300\n" -"Language-Team: \n" +"POT-Creation-Date: 2019-03-24 01:03-0300\n" +"PO-Revision-Date: 2019-03-24 01:38-0300\n" +"Language-Team: TEMPLATE\n" "MIME-Version: 1.0\n" "Content-Type: text/plain; charset=UTF-8\n" "Content-Transfer-Encoding: 8bit\n" @@ -19,9 +19,13 @@ msgstr "" "Language: pt\n" #: init.lua -msgid "Munição para Mosquete" -msgstr "Munição para Mosquete" +msgid "Musket Ammo" +msgstr "Munição de Mosquete" #: init.lua -msgid "Mosquete" +msgid "Musket (Loaded)" +msgstr "Mosquete (Carregado)" + +#: init.lua +msgid "Musket" msgstr "Mosquete" diff --git a/locale/template.pot b/locale/template.pot index 0e221e3..067b7e6 100644 --- a/locale/template.pot +++ b/locale/template.pot @@ -1,26 +1,30 @@ -# SOME DESCRIPTIVE TITLE. -# Copyright (C) YEAR THE PACKAGE'S COPYRIGHT HOLDER -# This file is distributed under the same license as the PACKAGE package. -# FIRST AUTHOR , YEAR. +# Musket mod for Minetest. +# Copyright (C) 2019 +# This file is distributed under the same license as the Musket package. +# BrunoMine , 2019. # #, fuzzy msgid "" msgstr "" -"Project-Id-Version: PACKAGE VERSION\n" +"Project-Id-Version: 0.6.0\n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2018-08-18 22:50-0300\n" -"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" -"Last-Translator: FULL NAME \n" -"Language-Team: LANGUAGE \n" +"POT-Creation-Date: 2019-03-24 01:03-0300\n" +"PO-Revision-Date: 2019-03-24 01:29+‎UTC−3\n" +"Last-Translator: BrunoMine \n" +"Language-Team: TEMPLATE\n" "Language: \n" "MIME-Version: 1.0\n" "Content-Type: text/plain; charset=UTF-8\n" "Content-Transfer-Encoding: 8bit\n" #: init.lua -msgid "Munição para Mosquete" +msgid "Musket Ammo" msgstr "" #: init.lua -msgid "Mosquete" +msgid "Musket (Loaded)" +msgstr "" + +#: init.lua +msgid "Musket" msgstr "" diff --git a/sounds/musket_mosquete.1.ogg b/sounds/musket_shot.1.ogg similarity index 100% rename from sounds/musket_mosquete.1.ogg rename to sounds/musket_shot.1.ogg diff --git a/sounds/musket_mosquete.2.ogg b/sounds/musket_shot.2.ogg similarity index 100% rename from sounds/musket_mosquete.2.ogg rename to sounds/musket_shot.2.ogg diff --git a/sounds/musket_mosquete.ogg b/sounds/musket_shot.ogg similarity index 100% rename from sounds/musket_mosquete.ogg rename to sounds/musket_shot.ogg diff --git a/textures/musket_mosquete_descarregado.png b/textures/musket.png similarity index 100% rename from textures/musket_mosquete_descarregado.png rename to textures/musket.png diff --git a/textures/musket_ammo_mosquete.png b/textures/musket_ammo_inv.png similarity index 100% rename from textures/musket_ammo_mosquete.png rename to textures/musket_ammo_inv.png diff --git a/textures/musket_ammo_mosquete_na_mao.png b/textures/musket_ammo_wielded.png similarity index 100% rename from textures/musket_ammo_mosquete_na_mao.png rename to textures/musket_ammo_wielded.png diff --git a/textures/musket_mosquete.png b/textures/musket_loaded.png similarity index 100% rename from textures/musket_mosquete.png rename to textures/musket_loaded.png diff --git a/tradutor.lua b/tradutor.lua deleted file mode 100644 index 4ac4e4e..0000000 --- a/tradutor.lua +++ /dev/null @@ -1,177 +0,0 @@ ---[[ - Mod musket para Minetest - Copyright (C) 2018 BrunoMine (https://github.com/BrunoMine) - - Recebeste uma cópia da GNU Lesser General - Public License junto com esse software, - se não, veja em . - - Sistema de tradução - ]] - --- Modpath -local modpath = minetest.get_modpath("musket") - --- Tradução intllib -musket.intllib = {} -musket.intllib.S, musket.intllib.NS = dofile(modpath.."/lib/intllib.lua") - --- Configura tradutor opicional -musket.S = musket.intllib.S -musket.NS = musket.intllib.NS - --- --- Ajustes devido ao bug de tradutor ler apenas traduzir do ingles --- - --- Strings para repassar textos em ingles -local pt_to_en = {} - --- Gera arquivos de tradução musket.*.tr -do - local file_to_tb = function(file) - local msgid = nil - local msgstr = nil - local tb = {} - for line in io.lines(file) do - - -- Iniciando 'msgid' - if string.sub(line, 1, 5) == "msgid" then - - -- Escrever no catalogo a anterior - if msgid ~= nil and msgstr ~= nil then - if msgid ~= "" then - tb[msgid] = msgstr - end - msgid = nil - msgstr = nil - end - - if line == "msgid \"\"" then - msgid = "" - else - msgid = string.sub(line, 8, (string.len(line)-1)) - end - - -- Continuando 'msgid' - elseif string.sub(line, 1, 1) == "\"" and msgstr == nil and msgid ~= nil then - msgid = msgid .. string.sub(line, 2, (string.len(line)-1)) - - -- Iniciando 'msgstr' - elseif string.sub(line, 1, 6) == "msgstr" then - - if line == "msgstr \"\"" then - msgstr = "" - else - msgstr = string.sub(line, 9, (string.len(line)-1)) - end - - -- Continuando 'msgstr' - elseif string.sub(line, 1, 1) == "\"" and msgstr ~= nil then - msgstr = msgstr .. string.sub(line, 2, (string.len(line)-1)) - - end - - - end - - -- Escrever ultima - if msgid ~= nil and msgstr ~= nil then - if msgid ~= "" then - tb[msgid] = msgstr - end - msgid = nil - msgstr = nil - end - - return tb - end - - -- Pegar strings principais en-pt para realizar as trocas - pt_to_en = file_to_tb(modpath.."/locale/en.po") - - --minetest.log("error", "pt_to_en = "..dump(pt_to_en)) - - local list = minetest.get_dir_list(modpath.."/locale") - for _,file in ipairs(list) do - - if string.match(file, "~") == nil then - - -- Traduções ".po" - if string.match(file, ".pot") == nil and string.match(file, ".po") then - - local lang_code = string.gsub(file, ".po", "") - - local pt_to_lang = file_to_tb(modpath.."/locale/"..file) - - -- tabela desejada - local en_to_lang = {} - for pt,en in pairs(pt_to_en) do - en_to_lang[en] = pt_to_lang[pt] - end - - -- Novo arquivo - local new_file = "### Arquivo gerado por musket apartir de "..file.."\n# textdomain: musket\n" - for en,lang in pairs(en_to_lang) do - new_file = new_file .. en .. "=" .. lang .. "\n" - end - -- Escrever arquivo - local saida = io.open(modpath.."/locale/musket."..lang_code..".tr", "w") - saida:write(new_file) - io.close(saida) - end - end - end -end - --- Ajuste para repassar termos em ingles -local s -if minetest.get_translator ~= nil then - s = minetest.get_translator("musket") -else - s = musket.intllib.S -end - -musket.s = function(...) - local args = { ... } - if pt_to_en[args[1]] ~= nil then - return s(pt_to_en[args[1]], unpack(args, 2)) - end - minetest.log("error", "[musket] String "..dump(args[1]).." nao catalogada") - return s(...) -end - --- Não troca string caso esteja trabalhando com intllib -if minetest.get_modpath("intllib") ~= nil - and minetest.get_translator == nil -then - musket.s = s -end - -musket.S = function(...) - local args = { ... } - if type(args[1]) == "table" then - local r = {} - for n,a in ipairs(args[1]) do - if n ~= 1 then -- Não traduz o primeiro - table.insert(r, musket.S(a)) - else - table.insert(r, a) - end - end - - return musket.s(unpack(r)) - - elseif type(args[1]) == "string" then - -- Não traduz caso faltem argumentos (devido strings ilustrativas) - return musket.s(...) - - else - return args[1] - end -end - --- Função que retorna a string inalterada para passar pela checagem -musket.Sfake = function(s) return s end - - diff --git a/translation_file_maker.lua b/translation_file_maker.lua new file mode 100644 index 0000000..c92d1d9 --- /dev/null +++ b/translation_file_maker.lua @@ -0,0 +1,108 @@ +--[[ + Musket mod for Minetest + Copyright (C) 2019 BrunoMine (https://github.com/BrunoMine) + + You should have received a copy of the GNU General Public License + along with this program. If not, see . + + Make translation files + ]] + +-- Modpath +local modpath = minetest.get_modpath("musket") + +-- Make translation files musket.*.tr +do + local file_to_tb = function(file) + local msgid = nil + local msgstr = nil + local tb = {} + for line in io.lines(file) do + + -- Iniciando 'msgid' + -- Starting 'msgid' + if string.sub(line, 1, 5) == "msgid" then + + -- Escrever no catalogo a anterior + -- Write in the catalog the previous + if msgid ~= nil and msgstr ~= nil then + if msgid ~= "" then + tb[msgid] = msgstr + end + msgid = nil + msgstr = nil + end + + if line == "msgid \"\"" then + msgid = "" + else + msgid = string.sub(line, 8, (string.len(line)-1)) + end + + -- Continuando 'msgid' + -- Continuing 'msgid' + elseif string.sub(line, 1, 1) == "\"" and msgstr == nil and msgid ~= nil then + msgid = msgid .. string.sub(line, 2, (string.len(line)-1)) + + -- Iniciando 'msgstr' + -- Starting 'msgstr' + elseif string.sub(line, 1, 6) == "msgstr" then + + if line == "msgstr \"\"" then + msgstr = "" + else + msgstr = string.sub(line, 9, (string.len(line)-1)) + end + + -- Continuando 'msgstr' + -- Continuing 'msgstr' + elseif string.sub(line, 1, 1) == "\"" and msgstr ~= nil then + msgstr = msgstr .. string.sub(line, 2, (string.len(line)-1)) + + end + + + end + + -- Escrever ultima + -- Write last + if msgid ~= nil and msgstr ~= nil then + if msgid ~= "" then + tb[msgid] = msgstr + end + msgid = nil + msgstr = nil + end + + return tb + end + + local list = minetest.get_dir_list(modpath.."/locale") + for _,file in ipairs(list) do + + if string.match(file, "~") == nil then + + -- Traduções ".po" + -- Translations ".po" + if string.match(file, ".pot") == nil and string.match(file, ".po") then + + local lang_code = string.gsub(file, ".po", "") + + local en_to_lang = file_to_tb(modpath.."/locale/"..file) + + -- Novo arquivo + -- New file + local new_file = "### File generated by musket from "..file.."\n# textdomain: musket\n" + for en,lang in pairs(en_to_lang) do + new_file = new_file .. en .. "=" .. lang .. "\n" + end + -- Escrever arquivo + -- Write file + local saida = io.open(modpath.."/locale/musket."..lang_code..".tr", "w") + saida:write(new_file) + io.close(saida) + end + end + end +end +