mirror of
https://github.com/MinetestForFun/quests.git
synced 2025-01-25 01:20:17 +01:00
Code cleanup and quality updates (#1)
This commit is contained in:
parent
765e34bfe5
commit
78ab6d7bc0
@ -1,12 +0,0 @@
|
|||||||
if minetest.global_exists("cmsg") then
|
|
||||||
function quests.show_message(t, playername, text)
|
|
||||||
if (quests.hud[playername].central_message_enabled) then
|
|
||||||
local player = minetest.get_player_by_name(playername)
|
|
||||||
cmsg.push_message_player(player, text, quests.colors[t])
|
|
||||||
minetest.sound_play("quests_" .. t, {to_player = playername})
|
|
||||||
end
|
|
||||||
end
|
|
||||||
else
|
|
||||||
function quests.show_message(...)
|
|
||||||
end
|
|
||||||
end
|
|
14
core.lua
14
core.lua
@ -2,13 +2,7 @@
|
|||||||
-- @module core
|
-- @module core
|
||||||
|
|
||||||
-- Boilerplate to support localized strings if intllib mod is installed.
|
-- Boilerplate to support localized strings if intllib mod is installed.
|
||||||
local S
|
local S = minetest.get_translator("quests")
|
||||||
if minetest.get_modpath("intllib") then
|
|
||||||
S = intllib.Getter()
|
|
||||||
else
|
|
||||||
-- If you don't use insertions (@1, @2, etc) you can use this:
|
|
||||||
S = function(s) return s end
|
|
||||||
end
|
|
||||||
local empty_callback = function(...) end
|
local empty_callback = function(...) end
|
||||||
|
|
||||||
local function compute_tasks(playername, questname, nocallback)
|
local function compute_tasks(playername, questname, nocallback)
|
||||||
@ -230,7 +224,7 @@ function quests.start_quest(playername, questname, metadata)
|
|||||||
end
|
end
|
||||||
|
|
||||||
quests.update_hud(playername)
|
quests.update_hud(playername)
|
||||||
quests.show_message("new", playername, S("New quest:") .. " " .. quest.title)
|
quests.show_message("new", playername, S("New quest") .. ": " .. quest.title)
|
||||||
return true
|
return true
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -522,7 +516,7 @@ function quests.accept_quest(playername, questname)
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
handle_quest_end(playername, questname)
|
handle_quest_end(playername, questname)
|
||||||
quests.show_message("success", playername, S("Quest completed:") .. " " .. quests.registered_quests[questname].title)
|
quests.show_message("success", playername, S("Quest completed") .. ": " .. quests.registered_quests[questname].title)
|
||||||
minetest.after(3, function(playername, questname)
|
minetest.after(3, function(playername, questname)
|
||||||
quests.active_quests[playername][questname] = nil
|
quests.active_quests[playername][questname] = nil
|
||||||
quests.update_hud(playername)
|
quests.update_hud(playername)
|
||||||
@ -565,7 +559,7 @@ function quests.abort_quest(playername, questname)
|
|||||||
local quest = quests.registered_quests[questname]
|
local quest = quests.registered_quests[questname]
|
||||||
quest.abortcallback(playername, questname, quests.active_quests[playername][questname].metadata)
|
quest.abortcallback(playername, questname, quests.active_quests[playername][questname].metadata)
|
||||||
handle_quest_end(playername, questname)
|
handle_quest_end(playername, questname)
|
||||||
quests.show_message("failed", playername, S("Quest failed:") .. " " .. quest.title)
|
quests.show_message("failed", playername, S("Quest failed") .. ": " .. quest.title)
|
||||||
minetest.after(3, function(playername, questname)
|
minetest.after(3, function(playername, questname)
|
||||||
quests.active_quests[playername][questname] = nil
|
quests.active_quests[playername][questname] = nil
|
||||||
quests.update_hud(playername)
|
quests.update_hud(playername)
|
||||||
|
@ -1,11 +1,5 @@
|
|||||||
-- Boilerplate to support localized strings if intllib mod is installed.
|
-- Boilerplate to support localized strings if intllib mod is installed.
|
||||||
local S
|
local S = minetest.get_translator("quests")
|
||||||
if minetest.get_modpath("intllib") then
|
|
||||||
S = intllib.Getter()
|
|
||||||
else
|
|
||||||
-- If you don't use insertions (@1, @2, etc) you can use this:
|
|
||||||
S = function(s) return s end
|
|
||||||
end
|
|
||||||
|
|
||||||
-- construct the questlog
|
-- construct the questlog
|
||||||
function quests.create_formspec(playername, tab, integrated)
|
function quests.create_formspec(playername, tab, integrated)
|
||||||
@ -117,34 +111,6 @@ function quests.create_config(playername, integrated)
|
|||||||
return formspec
|
return formspec
|
||||||
end
|
end
|
||||||
|
|
||||||
local function wordwrap(text, linelength)
|
|
||||||
local lines = text:split("\n")
|
|
||||||
local ret = ""
|
|
||||||
for i = 1,#lines do
|
|
||||||
local line = lines[i]
|
|
||||||
while (#line > linelength) do
|
|
||||||
local split = false
|
|
||||||
local j = linelength
|
|
||||||
while (not split) do
|
|
||||||
if (string.sub(line, j, j) == " ") then
|
|
||||||
split = true
|
|
||||||
ret = ret .. string.sub(line, 1, j) .. "\n"
|
|
||||||
line = string.sub(line, j + 1)
|
|
||||||
end
|
|
||||||
if (j <= 1) then
|
|
||||||
break
|
|
||||||
end
|
|
||||||
j = j - 1
|
|
||||||
end
|
|
||||||
if (not split) then
|
|
||||||
ret = ret .. string.sub(line, 1, linelength) .. "\n"
|
|
||||||
line = string.sub(line, linelength);
|
|
||||||
end
|
|
||||||
end
|
|
||||||
ret = ret .. line .. "\n"
|
|
||||||
end
|
|
||||||
return ret
|
|
||||||
end
|
|
||||||
|
|
||||||
-- construct the info formspec
|
-- construct the info formspec
|
||||||
function quests.create_info(playername, questname, taskid, integrated)
|
function quests.create_info(playername, questname, taskid, integrated)
|
||||||
@ -165,7 +131,7 @@ function quests.create_info(playername, questname, taskid, integrated)
|
|||||||
end
|
end
|
||||||
|
|
||||||
if quest.simple then
|
if quest.simple then
|
||||||
formspec = formspec .. "textarea[.4,1;7.2,7;_;;" .. minetest.formspec_escape(quest.description) .. "]"
|
formspec = formspec .. "textarea[.4,1;7.2,7;;;" .. minetest.formspec_escape(quest.description) .. "]"
|
||||||
else
|
else
|
||||||
quests.formspec_lists[playername].taskid = nil
|
quests.formspec_lists[playername].taskid = nil
|
||||||
local taskidlist = {}
|
local taskidlist = {}
|
||||||
|
12
hud.lua
12
hud.lua
@ -2,13 +2,7 @@
|
|||||||
-- @module hud
|
-- @module hud
|
||||||
|
|
||||||
-- Boilerplate to support localized strings if intllib mod is installed.
|
-- Boilerplate to support localized strings if intllib mod is installed.
|
||||||
local S
|
local S = minetest.get_translator("quests")
|
||||||
if minetest.get_modpath("intllib") then
|
|
||||||
S = intllib.Getter()
|
|
||||||
else
|
|
||||||
-- If you don't use insertions (@1, @2, etc) you can use this:
|
|
||||||
S = function(s) return s end
|
|
||||||
end
|
|
||||||
|
|
||||||
local show_max = 10 -- the maximum visible quests.
|
local show_max = 10 -- the maximum visible quests.
|
||||||
|
|
||||||
@ -55,7 +49,7 @@ function quests.show_hud(playername, autohide)
|
|||||||
position = {x = hud_config.position.x, y = hud_config.position.y},
|
position = {x = hud_config.position.x, y = hud_config.position.y},
|
||||||
offset = {x = hud_config.offset.x, y = hud_config.offset.y - 20},
|
offset = {x = hud_config.offset.x, y = hud_config.offset.y - 20},
|
||||||
number = hud_config.number,
|
number = hud_config.number,
|
||||||
text = S("Quests:")
|
text = S("Quests") .. ":"
|
||||||
})
|
})
|
||||||
|
|
||||||
quests.hud[playername].list = {}
|
quests.hud[playername].list = {}
|
||||||
@ -190,7 +184,7 @@ function quests.update_hud(playername)
|
|||||||
player:hud_change(quests.hud[playername].header, "text", S("No more Quests"))
|
player:hud_change(quests.hud[playername].header, "text", S("No more Quests"))
|
||||||
minetest.after(3, function(playername)
|
minetest.after(3, function(playername)
|
||||||
if next(quests.active_quests[playername]) ~= nil then
|
if next(quests.active_quests[playername]) ~= nil then
|
||||||
player:hud_change(quests.hud[playername].header, "text", S("Quests:"))
|
player:hud_change(quests.hud[playername].header, "text", S("Quests")..":")
|
||||||
quests.update_hud(playername)
|
quests.update_hud(playername)
|
||||||
else
|
else
|
||||||
quests.hide_hud(playername)
|
quests.hide_hud(playername)
|
||||||
|
8
init.lua
8
init.lua
@ -46,17 +46,11 @@ function quests.sorted_pairs(t)
|
|||||||
return iter
|
return iter
|
||||||
end
|
end
|
||||||
|
|
||||||
dofile(MP .. "/central_message.lua")
|
|
||||||
dofile(MP .. "/core.lua")
|
dofile(MP .. "/core.lua")
|
||||||
dofile(MP .. "/hud.lua")
|
dofile(MP .. "/hud.lua")
|
||||||
dofile(MP .. "/formspecs.lua")
|
dofile(MP .. "/formspecs.lua")
|
||||||
|
dofile(MP .. "/mod_integrations/mod_integrations.lua")
|
||||||
|
|
||||||
-- support for unified_inventory
|
|
||||||
if (minetest.get_modpath("unified_inventory") ~= nil) then
|
|
||||||
dofile(minetest.get_modpath("quests") .. "/unified_inventory.lua")
|
|
||||||
elseif (minetest.get_modpath("inventory_plus") ~= nil) then
|
|
||||||
dofile(minetest.get_modpath("quests") .. "/inventory_plus.lua")
|
|
||||||
end
|
|
||||||
|
|
||||||
|
|
||||||
-- write the quests to file
|
-- write the quests to file
|
||||||
|
@ -1,20 +0,0 @@
|
|||||||
missing description = fehlende Beschreibung
|
|
||||||
missing title = fehlender Titel
|
|
||||||
Quests: = Quests:
|
|
||||||
No more Quests = Keine weiteren Quests
|
|
||||||
Abort quest = Quest abbrechen
|
|
||||||
Configure = Konfigurieren
|
|
||||||
Enable HUD = HUD einschalten
|
|
||||||
Autohide HUD = HUD automatisch verstecken
|
|
||||||
Exit = Verlassen
|
|
||||||
Failed quests = Gescheiterte Quests
|
|
||||||
Finished quests = Beendete Quests
|
|
||||||
Info = Info
|
|
||||||
No quest specified. = Keine Quest ausgewählt.
|
|
||||||
Open quests = Offene Quests
|
|
||||||
Return = Zurück
|
|
||||||
Show all open quests = Zeige alle offenen Quests
|
|
||||||
There are no quests in this category. = Es gibt keine Quests in dieser Kategorie.
|
|
||||||
New quest: = Neue Quest:
|
|
||||||
Quest completed: = Quest beendet:
|
|
||||||
Quest failed: = Quest gescheitert:
|
|
23
locale/quests.de.tr
Normal file
23
locale/quests.de.tr
Normal file
@ -0,0 +1,23 @@
|
|||||||
|
# textdomain: quests
|
||||||
|
missing description=fehlende Beschreibung
|
||||||
|
missing title=fehlender Titel
|
||||||
|
Quests=Quests
|
||||||
|
No more Quests=Keine weiteren Quests
|
||||||
|
Abort quest=Quest abbrechen
|
||||||
|
Configure=Konfigurieren
|
||||||
|
Enable HUD=HUD einschalten
|
||||||
|
Autohide HUD=HUD automatisch verstecken
|
||||||
|
Exit=Verlassen
|
||||||
|
Failed quests=Gescheiterte Quests
|
||||||
|
Finished quests=Beendete Quests
|
||||||
|
Info=Info
|
||||||
|
No quest specified.=Keine Quest ausgewählt.
|
||||||
|
Open quests=Offene Quests
|
||||||
|
Return=Zurück
|
||||||
|
Show all open quests=Zeige alle offenen Quests
|
||||||
|
There are no quests in this category.=Es gibt keine Quests in dieser Kategorie.
|
||||||
|
New quest=Neue Quest
|
||||||
|
Quest completed=Quest beendet
|
||||||
|
Quest failed=Quest gescheitert
|
||||||
|
Central messages=Zentrale nachrichten
|
||||||
|
|
22
locale/quests.template.tr
Normal file
22
locale/quests.template.tr
Normal file
@ -0,0 +1,22 @@
|
|||||||
|
# textdomain: quests
|
||||||
|
missing description=
|
||||||
|
missing title=
|
||||||
|
Quests=
|
||||||
|
No more Quests=
|
||||||
|
Abort quest=
|
||||||
|
Configure=
|
||||||
|
Enable HUD=
|
||||||
|
Autohide HUD=
|
||||||
|
Exit=
|
||||||
|
Failed quests=
|
||||||
|
Finished quests=
|
||||||
|
Info=
|
||||||
|
No quest specified.=
|
||||||
|
Open quests=
|
||||||
|
Return=
|
||||||
|
Show all open quests=
|
||||||
|
There are no quests in this category.=
|
||||||
|
New quest=
|
||||||
|
Quest completed=
|
||||||
|
Quest failed=
|
||||||
|
Central messages=
|
@ -1,20 +0,0 @@
|
|||||||
missing description =
|
|
||||||
missing title =
|
|
||||||
Quests: =
|
|
||||||
No more Quests =
|
|
||||||
Abort quest =
|
|
||||||
Configure =
|
|
||||||
Enable HUD =
|
|
||||||
Autohide HUD =
|
|
||||||
Exit =
|
|
||||||
Failed quests =
|
|
||||||
Finished quests =
|
|
||||||
Info =
|
|
||||||
No quest specified. =
|
|
||||||
Open quests =
|
|
||||||
Return =
|
|
||||||
Show all open quests =
|
|
||||||
There are no quests in this category. =
|
|
||||||
New quest: =
|
|
||||||
Quest completed: =
|
|
||||||
Quest failed: =
|
|
4
mod.conf
4
mod.conf
@ -1,3 +1,3 @@
|
|||||||
name = quests
|
name = quests
|
||||||
optional_depends = intllib, unified_inventory, inventory_plus, central_message
|
optional_depends = unified_inventory, inventory_plus, central_message, sfinv
|
||||||
description = Quest framework for Minetest.
|
description = Quest framework for Minetest.
|
||||||
|
9
mod_integrations/central_message.lua
Normal file
9
mod_integrations/central_message.lua
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
|
||||||
|
function quests.show_message(t, playername, text)
|
||||||
|
if (quests.hud[playername].central_message_enabled) then
|
||||||
|
local player = minetest.get_player_by_name(playername)
|
||||||
|
cmsg.push_message_player(player, text, quests.colors[t])
|
||||||
|
minetest.sound_play("quests_" .. t, {to_player = playername})
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
20
mod_integrations/mod_integrations.lua
Normal file
20
mod_integrations/mod_integrations.lua
Normal file
@ -0,0 +1,20 @@
|
|||||||
|
-- support for several inventory mods
|
||||||
|
if minetest.get_modpath("unified_inventory") then
|
||||||
|
dofile(minetest.get_modpath("quests") .. "/mod_integrations/unified_inventory.lua")
|
||||||
|
end
|
||||||
|
|
||||||
|
if minetest.get_modpath("inventory_plus") then
|
||||||
|
dofile(minetest.get_modpath("quests") .. "/mod_integrations/inventory_plus.lua")
|
||||||
|
end
|
||||||
|
|
||||||
|
if minetest.global_exists("sfinv") then
|
||||||
|
dofile(minetest.get_modpath("quests") .. "/mod_integrations/sfinv.lua")
|
||||||
|
end
|
||||||
|
|
||||||
|
-- mod that displays notifications in the screen's center
|
||||||
|
if minetest.get_modpath("central_message") then
|
||||||
|
dofile(minetest.get_modpath("quests") .. "/mod_integrations/central_message.lua")
|
||||||
|
|
||||||
|
else -- define blank function so we can still use this in the code later
|
||||||
|
function quests.show_message(...) end
|
||||||
|
end
|
19
mod_integrations/sfinv.lua
Normal file
19
mod_integrations/sfinv.lua
Normal file
@ -0,0 +1,19 @@
|
|||||||
|
assert(sfinv.enabled, "Please enable sfinv in order to use it.")
|
||||||
|
local old_func = sfinv.pages["sfinv:crafting"].get
|
||||||
|
sfinv.override_page("sfinv:crafting", {
|
||||||
|
get = function(self, player, context)
|
||||||
|
local fs = old_func(self, player, context)
|
||||||
|
return fs .. "image_button[0,0;1,1;inventory_plus_quests.png;quests;]"
|
||||||
|
end
|
||||||
|
})
|
||||||
|
|
||||||
|
minetest.register_on_player_receive_fields(function(player, formname, fields)
|
||||||
|
if fields.quests then
|
||||||
|
quests.show_formspec(player:get_player_name())
|
||||||
|
return true
|
||||||
|
elseif fields.quests_exit then
|
||||||
|
sfinv.set_page(player, "sfinv:crafting")
|
||||||
|
return true
|
||||||
|
end
|
||||||
|
return false
|
||||||
|
end)
|
Loading…
Reference in New Issue
Block a user