1
0
mirror of https://github.com/TeTpaAka/quests.git synced 2025-01-22 07:50:49 +01:00

Replace references to deprecated "minetest" global with "core"

This commit is contained in:
Jordan Irwin 2025-01-17 22:51:54 -08:00 committed by TeTpaAka
parent 094057447d
commit 3baf31ea1a
6 changed files with 47 additions and 47 deletions

View File

@ -1,9 +1,9 @@
if (cmsg) then if (cmsg) then
function quests.show_message(t, playername, text) function quests.show_message(t, playername, text)
if (quests.hud[playername].central_message_enabled) then if (quests.hud[playername].central_message_enabled) then
local player = minetest.get_player_by_name(playername) local player = core.get_player_by_name(playername)
cmsg.push_message_player(player, text, quests.colors[t]) cmsg.push_message_player(player, text, quests.colors[t])
minetest.sound_play("quests_" .. t, {to_player = playername}) core.sound_play("quests_" .. t, {to_player = playername})
end end
end end
else else

View File

@ -1,6 +1,6 @@
-- Boilerplate to support localized strings if intllib mod is installed. -- Boilerplate to support localized strings if intllib mod is installed.
local S local S
if minetest.get_modpath("intllib") then if core.get_modpath("intllib") then
S = intllib.Getter() S = intllib.Getter()
else else
-- If you don't use insertions (@1, @2, etc) you can use this: -- If you don't use insertions (@1, @2, etc) you can use this:
@ -117,12 +117,12 @@ function quests.accept_quest(playername, questname)
quests.active_quests[playername][questname].finished = true quests.active_quests[playername][questname].finished = true
for _,quest in ipairs(quests.hud[playername].list) do for _,quest in ipairs(quests.hud[playername].list) do
if (quest.name == questname) then if (quest.name == questname) then
local player = minetest.get_player_by_name(playername) local player = core.get_player_by_name(playername)
player:hud_change(quest.id, "number", quests.colors.success) player:hud_change(quest.id, "number", quests.colors.success)
end end
end end
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) core.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)
end, playername, questname) end, playername, questname)
@ -155,12 +155,12 @@ function quests.abort_quest(playername, questname)
quests.active_quests[playername][questname].finished = true quests.active_quests[playername][questname].finished = true
for _,quest in ipairs(quests.hud[playername].list) do for _,quest in ipairs(quests.hud[playername].list) do
if (quest.name == questname) then if (quest.name == questname) then
local player = minetest.get_player_by_name(playername) local player = core.get_player_by_name(playername)
player:hud_change(quest.id, "number", quests.colors.failed) player:hud_change(quest.id, "number", quests.colors.failed)
end end
end end
quests.show_message("failed", playername, S("Quest failed:") .. " " .. quests.registered_quests[questname].title) quests.show_message("failed", playername, S("Quest failed:") .. " " .. quests.registered_quests[questname].title)
minetest.after(3, function(playername, questname) core.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)
end, playername, questname) end, playername, questname)

View File

@ -1,6 +1,6 @@
-- Boilerplate to support localized strings if intllib mod is installed. -- Boilerplate to support localized strings if intllib mod is installed.
local S local S
if minetest.get_modpath("intllib") then if core.get_modpath("intllib") then
S = intllib.Getter() S = intllib.Getter()
else else
-- If you don't use insertions (@1, @2, etc) you can use this: -- If you don't use insertions (@1, @2, etc) you can use this:
@ -142,21 +142,21 @@ end
-- show the player playername his/her questlog -- show the player playername his/her questlog
function quests.show_formspec(playername) function quests.show_formspec(playername)
minetest.show_formspec(playername, "quests:questlog", quests.create_formspec(playername)) core.show_formspec(playername, "quests:questlog", quests.create_formspec(playername))
end end
-- chatcommand to see a full list of quests: -- chatcommand to see a full list of quests:
minetest.register_chatcommand("quests", { core.register_chatcommand("quests", {
params = "", params = "",
description = S("Show all open quests"), description = S("Show all open quests"),
func = function(name, param) func = function(name, param)
minetest.show_formspec(name, "quests:questlog", quests.create_formspec(name)) core.show_formspec(name, "quests:questlog", quests.create_formspec(name))
return true return true
end end
}) })
-- Handle the return fields of the questlog -- Handle the return fields of the questlog
minetest.register_on_player_receive_fields(function(player, formname, fields) core.register_on_player_receive_fields(function(player, formname, fields)
if (player == nil) then if (player == nil) then
return return
end end
@ -168,7 +168,7 @@ minetest.register_on_player_receive_fields(function(player, formname, fields)
-- questlog -- questlog
if (fields["quests_header"]) then if (fields["quests_header"]) then
if (formname == "quests:questlog") then if (formname == "quests:questlog") then
minetest.show_formspec(playername, "quests:questlog", quests.create_formspec(playername, fields["quests_header"])) core.show_formspec(playername, "quests:questlog", quests.create_formspec(playername, fields["quests_header"]))
else else
if (fields["quests_header"] == "1") then if (fields["quests_header"] == "1") then
unified_inventory.set_inventory_formspec(player, "quests") unified_inventory.set_inventory_formspec(player, "quests")
@ -183,7 +183,7 @@ minetest.register_on_player_receive_fields(function(player, formname, fields)
return return
end end
if (fields["quests_questlist"]) then if (fields["quests_questlist"]) then
local event = minetest.explode_textlist_event(fields["quests_questlist"]) local event = core.explode_textlist_event(fields["quests_questlist"])
if (event.type == "CHG") then if (event.type == "CHG") then
quests.formspec_lists[playername].id = event.index quests.formspec_lists[playername].id = event.index
end end
@ -194,21 +194,21 @@ minetest.register_on_player_receive_fields(function(player, formname, fields)
end end
quests.abort_quest(playername, quests.formspec_lists[playername]["list"][quests.formspec_lists[playername].id]) quests.abort_quest(playername, quests.formspec_lists[playername]["list"][quests.formspec_lists[playername].id])
if (formname == "quests:questlog") then if (formname == "quests:questlog") then
minetest.show_formspec(playername, "quests:questlog", quests.create_formspec(playername)) core.show_formspec(playername, "quests:questlog", quests.create_formspec(playername))
else else
unified_inventory.set_inventory_formspec(player, "quests") unified_inventory.set_inventory_formspec(player, "quests")
end end
end end
if (fields["quests_config"]) then if (fields["quests_config"]) then
if (formname == "quests:questlog") then if (formname == "quests:questlog") then
minetest.show_formspec(playername, "quests:config", quests.create_config(playername)) core.show_formspec(playername, "quests:config", quests.create_config(playername))
else else
unified_inventory.set_inventory_formspec(player, "quests_config") unified_inventory.set_inventory_formspec(player, "quests_config")
end end
end end
if (fields["quests_info"]) then if (fields["quests_info"]) then
if (formname == "quests:questlog") then if (formname == "quests:questlog") then
minetest.show_formspec(playername, "quests:info", quests.create_info(playername, quests.formspec_lists[playername].list[quests.formspec_lists[playername].id])) core.show_formspec(playername, "quests:info", quests.create_info(playername, quests.formspec_lists[playername].list[quests.formspec_lists[playername].id]))
else else
unified_inventory.set_inventory_formspec(player, "quests_info") unified_inventory.set_inventory_formspec(player, "quests_info")
end end
@ -223,7 +223,7 @@ minetest.register_on_player_receive_fields(function(player, formname, fields)
quests.hide_hud(playername) quests.hide_hud(playername)
end end
if (formname == "quests:config") then if (formname == "quests:config") then
minetest.show_formspec(playername, "quests:config", quests.create_config(playername)) core.show_formspec(playername, "quests:config", quests.create_config(playername))
else else
unified_inventory.set_inventory_formspec(player, "quests_config") unified_inventory.set_inventory_formspec(player, "quests_config")
end end
@ -236,7 +236,7 @@ minetest.register_on_player_receive_fields(function(player, formname, fields)
quests.hud[playername].autohide = false quests.hud[playername].autohide = false
end end
if (formname == "quests:config") then if (formname == "quests:config") then
minetest.show_formspec(playername, "quests:config", quests.create_config(playername)) core.show_formspec(playername, "quests:config", quests.create_config(playername))
else else
unified_inventory.set_inventory_formspec(player, "quests_config") unified_inventory.set_inventory_formspec(player, "quests_config")
end end
@ -248,7 +248,7 @@ minetest.register_on_player_receive_fields(function(player, formname, fields)
quests.hud[playername].central_message_enabled = false quests.hud[playername].central_message_enabled = false
end end
if (formname == "quests:config") then if (formname == "quests:config") then
minetest.show_formspec(playername, "quests:config", quests.create_config(playername)) core.show_formspec(playername, "quests:config", quests.create_config(playername))
else else
unified_inventory.set_inventory_formspec(player, "quests_config") unified_inventory.set_inventory_formspec(player, "quests_config")
end end
@ -256,7 +256,7 @@ minetest.register_on_player_receive_fields(function(player, formname, fields)
if (fields["quests_config_return"]) then if (fields["quests_config_return"]) then
if (formname == "quests:config") then if (formname == "quests:config") then
minetest.show_formspec(playername, "quests:questlog", quests.create_formspec(playername)) core.show_formspec(playername, "quests:questlog", quests.create_formspec(playername))
else else
unified_inventory.set_inventory_formspec(player, "quests") unified_inventory.set_inventory_formspec(player, "quests")
end end
@ -269,14 +269,14 @@ minetest.register_on_player_receive_fields(function(player, formname, fields)
end end
quests.abort_quest(playername, quests.formspec_lists[playername]["list"][quests.formspec_lists[playername].id]) quests.abort_quest(playername, quests.formspec_lists[playername]["list"][quests.formspec_lists[playername].id])
if (formname == "quests:info") then if (formname == "quests:info") then
minetest.show_formspec(playername, "quests:questlog", quests.create_formspec(playername)) core.show_formspec(playername, "quests:questlog", quests.create_formspec(playername))
else else
unified_inventory.set_inventory_formspec(player, "quests") unified_inventory.set_inventory_formspec(player, "quests")
end end
end end
if (fields["quests_info_return"]) then if (fields["quests_info_return"]) then
if (formname == "quests:info") then if (formname == "quests:info") then
minetest.show_formspec(playername, "quests:questlog", quests.create_formspec(playername)) core.show_formspec(playername, "quests:questlog", quests.create_formspec(playername))
else else
unified_inventory.set_inventory_formspec(player, "quests") unified_inventory.set_inventory_formspec(player, "quests")
end end

18
hud.lua
View File

@ -1,6 +1,6 @@
-- Boilerplate to support localized strings if intllib mod is installed. -- Boilerplate to support localized strings if intllib mod is installed.
local S local S
if minetest.get_modpath("intllib") then if core.get_modpath("intllib") then
S = intllib.Getter() S = intllib.Getter()
else else
-- If you don't use insertions (@1, @2, etc) you can use this: -- If you don't use insertions (@1, @2, etc) you can use this:
@ -32,18 +32,18 @@ function quests.show_hud(playername, autohide)
local player = minetest.get_player_by_name(playername) local player = core.get_player_by_name(playername)
if (player == nil) then if (player == nil) then
return false return false
end end
quests.hud[playername].list = {} quests.hud[playername].list = {}
table.insert(quests.hud[playername].list, { value=0, id=player:hud_add(hud) }) table.insert(quests.hud[playername].list, { value=0, id=player:hud_add(hud) })
minetest.after(0, quests.update_hud, playername) core.after(0, quests.update_hud, playername)
end end
-- call this method to hide the hud -- call this method to hide the hud
function quests.hide_hud(playername) function quests.hide_hud(playername)
local player = minetest.get_player_by_name(playername) local player = core.get_player_by_name(playername)
if (player == nil or quests.hud[playername] == nil or quests.hud[playername].list == nil) then if (player == nil or quests.hud[playername] == nil or quests.hud[playername].list == nil) then
return return
end end
@ -80,7 +80,7 @@ function quests.update_hud(playername)
end end
return return
end end
local player = minetest.get_player_by_name(playername) local player = core.get_player_by_name(playername)
if (player == nil) then if (player == nil) then
return return
end end
@ -181,7 +181,7 @@ function quests.update_hud(playername)
if (quests.hud[playername].autohide) then if (quests.hud[playername].autohide) then
if (next(quests.active_quests[playername]) == nil) then if (next(quests.active_quests[playername]) == nil) then
player:hud_change(quests.hud[playername].list[1].id, "text", S("No more Quests")) player:hud_change(quests.hud[playername].list[1].id, "text", S("No more Quests"))
minetest.after(3, function(playername) core.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].list[1].id, "text", S("Quests:")) player:hud_change(quests.hud[playername].list[1].id, "text", S("Quests:"))
else else
@ -198,14 +198,14 @@ end
--for playername,id in pairs(quests.hud) do --for playername,id in pairs(quests.hud) do
-- if (id ~= nil) then -- if (id ~= nil) then
-- quests.hud[playername] = nil -- quests.hud[playername] = nil
-- minetest.after(10, function(playername) -- core.after(10, function(playername)
-- quests.show_hud(playername) -- quests.show_hud(playername)
-- quests.update_hud(playername) -- quests.update_hud(playername)
-- end, playername) -- end, playername)
-- end -- end
--end --end
minetest.register_on_joinplayer(function(player) core.register_on_joinplayer(function(player)
local playername = player:get_player_name() local playername = player:get_player_name()
if (quests.hud[playername] ~= nil) then if (quests.hud[playername] ~= nil) then
if (not(quests.hud[playername].first)) then if (not(quests.hud[playername].first)) then
@ -219,7 +219,7 @@ minetest.register_on_joinplayer(function(player)
central_message_enabled = central_message_enabled central_message_enabled = central_message_enabled
} }
if (list ~= nil) then if (list ~= nil) then
minetest.after(1, function(playername) core.after(1, function(playername)
quests.show_hud(playername) quests.show_hud(playername)
end, playername) end, playername)
end end

View File

@ -1,8 +1,8 @@
-- reading previous quests -- reading previous quests
local file = io.open(minetest.get_worldpath().."/quests", "r") local file = io.open(core.get_worldpath().."/quests", "r")
if file then if file then
minetest.log("action", "Reading quests...") core.log("action", "Reading quests...")
quests = minetest.deserialize(file:read("*all")) quests = core.deserialize(file:read("*all"))
file:close() file:close()
end end
quests = quests or {} quests = quests or {}
@ -29,7 +29,7 @@ quests.colors = {
} }
local MP = minetest.get_modpath("quests") local MP = core.get_modpath("quests")
dofile(MP .. "/central_message.lua") dofile(MP .. "/central_message.lua")
dofile(MP .. "/core.lua") dofile(MP .. "/core.lua")
@ -37,16 +37,16 @@ dofile(MP .. "/hud.lua")
dofile(MP .. "/formspecs.lua") dofile(MP .. "/formspecs.lua")
-- support for unified_inventory -- support for unified_inventory
if (minetest.get_modpath("unified_inventory") ~= nil) then if (core.get_modpath("unified_inventory") ~= nil) then
dofile(minetest.get_modpath("quests") .. "/unified_inventory.lua") dofile(core.get_modpath("quests") .. "/unified_inventory.lua")
elseif (minetest.get_modpath("inventory_plus") ~= nil) then elseif (core.get_modpath("inventory_plus") ~= nil) then
dofile(minetest.get_modpath("quests") .. "/inventory_plus.lua") dofile(core.get_modpath("quests") .. "/inventory_plus.lua")
end end
-- write the quests to file -- write the quests to file
minetest.register_on_shutdown(function() core.register_on_shutdown(function()
minetest.log("action", "Writing quests to file") core.log("action", "Writing quests to file")
for playername, quest in pairs(quests.active_quests) do for playername, quest in pairs(quests.active_quests) do
for questname, questspecs in pairs(quest) do for questname, questspecs in pairs(quest) do
if (questspecs.finished) then if (questspecs.finished) then
@ -54,9 +54,9 @@ minetest.register_on_shutdown(function()
end end
end end
end end
local file = io.open(minetest.get_worldpath().."/quests", "w") local file = io.open(core.get_worldpath().."/quests", "w")
if (file) then if (file) then
file:write(minetest.serialize({ --registered_quests = quests.registered_quests, file:write(core.serialize({ --registered_quests = quests.registered_quests,
active_quests = quests.active_quests, active_quests = quests.active_quests,
successfull_quests = quests.successfull_quests, successfull_quests = quests.successfull_quests,
failed_quests = quests.failed_quests, failed_quests = quests.failed_quests,

View File

@ -1,8 +1,8 @@
minetest.register_on_joinplayer(function(player) core.register_on_joinplayer(function(player)
inventory_plus.register_button(player, "quests") inventory_plus.register_button(player, "quests")
end) end)
minetest.register_on_player_receive_fields(function(player, formname, fields) core.register_on_player_receive_fields(function(player, formname, fields)
if (fields.quests) then if (fields.quests) then
quests.show_formspec(player:get_player_name()) quests.show_formspec(player:get_player_name())
end end