update to core.

This commit is contained in:
MisterE 2024-12-23 12:01:21 -05:00
parent beb6cfa09d
commit 042dbc3d78
10 changed files with 89 additions and 89 deletions

View File

@ -1,11 +1,11 @@
local S = minetest.get_translator("quikbild")
local S = core.get_translator("quikbild")
minetest.register_chatcommand("qblang", {
core.register_chatcommand("qblang", {
params = "[<"..S("language code")..">]",
description = S("Set Quickbild language"),
func = function(name, param)
local player = minetest.get_player_by_name(name)
local player = core.get_player_by_name(name)
if not player or not player:is_player() then
return false, S("No player.")
end
@ -28,7 +28,7 @@ minetest.register_chatcommand("qblang", {
minetest.register_chatcommand("qblang_send", {
core.register_chatcommand("qblang_send", {
params = "<"..S("player")..">",
privs = { quikbild_admin = true },
description = S("Show a Quikbild language selection dialog to a player"),
@ -36,7 +36,7 @@ minetest.register_chatcommand("qblang_send", {
if param == "" then
return false
end
if minetest.get_player_by_name(param) then
if core.get_player_by_name(param) then
quikbild.send_lang_fs(param)
return true
else
@ -45,15 +45,15 @@ minetest.register_chatcommand("qblang_send", {
end,
})
minetest.register_on_mods_loaded( function()
table.insert(minetest.registered_on_chat_messages,1,function(name, message)
core.register_on_mods_loaded( function()
table.insert(core.registered_on_chat_messages,1,function(name, message)
local mod = arena_lib.get_mod_by_player(name)
if mod == "quikbild" then
local arena = arena_lib.get_arena_by_player(name)
if arena then
if arena.artist and arena.artist == name and arena.in_game and arena.in_celebration == false then
if message ~= "/quit" then
minetest.chat_send_player(name, minetest.colorize("#eea160","[!]" .. S("Chat is disabled while being the artist in quikbild. Don't cheat!")))
core.chat_send_player(name, core.colorize("#eea160","[!]" .. S("Chat is disabled while being the artist in quikbild. Don't cheat!")))
return true
end
end

View File

@ -1,4 +1,4 @@
local S = minetest.get_translator("quikbild")
local S = core.get_translator("quikbild")
-- Waypoints to show the positions
@ -12,7 +12,7 @@ local wp_icons = {
}
local function remove_waypoints(p_name, arena)
local player = minetest.get_player_by_name(p_name)
local player = core.get_player_by_name(p_name)
if player and waypoints[p_name] then
for _, waypoint_ID in pairs(waypoints[p_name]) do
player:hud_remove(waypoint_ID)
@ -28,7 +28,7 @@ local function show_waypoints(p_name, arena)
if not quikbild.check_positions(arena) then
return
end
local player = minetest.get_player_by_name(p_name)
local player = core.get_player_by_name(p_name)
if not player or not player:is_player() then
return
end
@ -101,7 +101,7 @@ local get_set_pos_function = function(property_name, round)
end
end
minetest.register_craftitem("quikbild:editor_build_area_set", {
core.register_craftitem("quikbild:editor_build_area_set", {
description = S("Build area (LMB: pos1, RMB: pos2)"),
inventory_image = "quikbild_editor_build_area_set.png",
wield_image = "quikbild_editor_build_area_set.png",
@ -114,7 +114,7 @@ minetest.register_craftitem("quikbild:editor_build_area_set", {
on_place = get_set_pos_function("build_area_pos_2", true),
})
minetest.register_craftitem("quikbild:editor_artist_spawn_pos_set", {
core.register_craftitem("quikbild:editor_artist_spawn_pos_set", {
description = S("Artist spawn position"),
inventory_image = "quikbild_editor_artist_spawn.png",
wield_image = "quikbild_editor_artist_spawn.png",

20
hud.lua
View File

@ -1,5 +1,5 @@
quikbild.huds = {}
local S = minetest.get_translator("quikbild")
local S = core.get_translator("quikbild")
-- Color for own score
local COLOR_SELF = 0xCFC6B8
@ -9,7 +9,7 @@ local COLOR_LEADER = 0xF4B41B
local COLOR_OTHER = 0xA0938E
function quikbild.create_hud(p_name)
local player = minetest.get_player_by_name(p_name)
local player = core.get_player_by_name(p_name)
quikbild.huds[p_name] = {}
quikbild.huds[p_name]["background"] = player:hud_add({
@ -66,25 +66,25 @@ end
function quikbild.update_hud(p_name, scoreboard, yourscore)
local hiscore = scoreboard[1].score
local player = minetest.get_player_by_name(p_name)
local player = core.get_player_by_name(p_name)
-- -- this line is erroring with "attempt to index nil value"
-- -- to find the culprit, we will add checks to find out what, exactly is nil.
-- if not player then
-- minetest.log("error","player is nil!")
-- core.log("error","player is nil!")
-- elseif not quikbild.huds then
-- minetest.log("error","quikbild.huds is nil")
-- core.log("error","quikbild.huds is nil")
-- elseif not p_name then
-- minetest.log("error","p_name is nil")
-- core.log("error","p_name is nil")
-- elseif not quikbild.huds[p_name] then
-- minetest.log("error","quikbild.huds[p_name] is nil")
-- core.log("error","quikbild.huds[p_name] is nil")
-- -- this seems to be the nil value. Not sure why. See https://gitlab.com/mistere123.coding/quikbild/-/issues/28
-- elseif not quikbild.huds[p_name]["yourscore"] then
-- minetest.log("error",'quikbild.huds[p_name]["yourscore"] is nil')
-- core.log("error",'quikbild.huds[p_name]["yourscore"] is nil')
-- elseif not yourscore then
-- minetest.log("error","yourscore is nil")
-- core.log("error","yourscore is nil")
-- end
if quikbild.huds[p_name] then
@ -113,7 +113,7 @@ end
function quikbild.remove_hud(p_name)
if not quikbild.huds[p_name] then return end
local player = minetest.get_player_by_name(p_name)
local player = core.get_player_by_name(p_name)
for name,id in pairs(quikbild.huds[p_name]) do
player:hud_remove(id)
end

View File

@ -1,4 +1,4 @@
local S = minetest.get_translator("quikbild")
local S = core.get_translator("quikbild")
-- local value settings
local player_speed = 2 -- when in the minigame
@ -6,7 +6,7 @@ local player_jump = 2 -- when in the minigame
quikbild = {} --global table
quikbild.version = "12.26.2022.0"
quikbild.storage = minetest.get_mod_storage()
quikbild.storage = core.get_mod_storage()
quikbild.celebration_time = 10
@ -62,14 +62,14 @@ quikbild.celebration_time = 10
})
quikbild.csv = dofile(minetest.get_modpath("quikbild") .. "/lua-csv/lua/csv.lua")
quikbild.csv = dofile(core.get_modpath("quikbild") .. "/lua-csv/lua/csv.lua")
dofile(minetest.get_modpath("quikbild") .. "/languages.lua")
dofile(minetest.get_modpath("quikbild") .. "/utils.lua")
dofile(minetest.get_modpath("quikbild") .. "/hud.lua")
dofile(minetest.get_modpath("quikbild") .. "/items.lua")
dofile(minetest.get_modpath("quikbild") .. "/commands.lua")
dofile(minetest.get_modpath("quikbild") .. "/nodes.lua")
dofile(minetest.get_modpath("quikbild") .. "/minigame_manager.lua")
dofile(minetest.get_modpath("quikbild") .. "/privs.lua")
dofile(minetest.get_modpath("quikbild") .. "/editor.lua")
dofile(core.get_modpath("quikbild") .. "/languages.lua")
dofile(core.get_modpath("quikbild") .. "/utils.lua")
dofile(core.get_modpath("quikbild") .. "/hud.lua")
dofile(core.get_modpath("quikbild") .. "/items.lua")
dofile(core.get_modpath("quikbild") .. "/commands.lua")
dofile(core.get_modpath("quikbild") .. "/nodes.lua")
dofile(core.get_modpath("quikbild") .. "/minigame_manager.lua")
dofile(core.get_modpath("quikbild") .. "/privs.lua")
dofile(core.get_modpath("quikbild") .. "/editor.lua")

View File

@ -1,7 +1,7 @@
local S = minetest.get_translator("quikbild")
local F = minetest.formspec_escape
local S = core.get_translator("quikbild")
local F = core.formspec_escape
minetest.register_tool("quikbild:lang", {
core.register_tool("quikbild:lang", {
description = S("Choose Language"),
inventory_image = "quikbild_langchoose.png",
@ -19,7 +19,7 @@ minetest.register_tool("quikbild:lang", {
minetest.register_tool("quikbild:help", {
core.register_tool("quikbild:help", {
description = S("Help"),
inventory_image = "arenalib_editor_info.png",
@ -29,7 +29,7 @@ minetest.register_tool("quikbild:help", {
on_use = function(itemstack, user, pointed_thing)
local p_name = user:get_player_name()
if p_name then
minetest.show_formspec(p_name, "qb_help", "formspec_version[5]"..
core.show_formspec(p_name, "qb_help", "formspec_version[5]"..
"size[10.5,5]"..
"background9[0,0;0,0;quikbild_gui_bg.png;true;5]"..
"textarea[0.8,0.7;8.8,3.5;;"..F(S("QuikBild Help"))..";"..F(S("Each player gets a turn to be Builder. Everyone else guesses what the Builder is building. To guess type your guess in chat. Use lowercase letters only. Answers can be 1 or 2 words. When it is your turn to be Builder you will be shown a word - build it. DO NOT build letters and do not try to tell other players what the word is. That ruins the game for everyone. No one will want to play this with you anymore. If you do not know the word use a search engine to look it up. You have time to do that!")).."]")

View File

@ -1,4 +1,4 @@
local S = minetest.get_translator("quikbild")
local S = core.get_translator("quikbild")
quikbild.languages = {
en = {
@ -43,10 +43,10 @@ function quikbild.set_language(player, language_number, send_chat)
arena.players[p_name].lang = language_number
end
if send_chat then
minetest.chat_send_player(p_name,minetest.colorize("#7D7071",">> "..S("Language setting confirmed!")))
core.chat_send_player(p_name,core.colorize("#7D7071",">> "..S("Language setting confirmed!")))
end
local lang_code = quikbild.languages_by_number[language_number].code
minetest.log("action", "[quikbild] Quikbild language of "..p_name.." set to '"..lang_code.."' ("..language_number..")")
core.log("action", "[quikbild] Quikbild language of "..p_name.." set to '"..lang_code.."' ("..language_number..")")
return true
end
@ -63,11 +63,11 @@ quikbild.send_lang_fs = function(p_name)
formstring = formstring .. "image_button["..x..",0.6;2.6,1.8;"..lang.icon..";lang_"..lang.code..";"..lang.code..";false;true]"
x = x + 3.2
end
minetest.show_formspec(p_name, "qb_lang", formstring)
core.show_formspec(p_name, "qb_lang", formstring)
end
-- React on Quikbild language selection formspec
minetest.register_on_player_receive_fields(function(player, formname, fields)
core.register_on_player_receive_fields(function(player, formname, fields)
if formname ~= "qb_lang" then return end
local p_name = player:get_player_name()
local arena = arena_lib.get_arena_by_player(p_name)
@ -78,7 +78,7 @@ minetest.register_on_player_receive_fields(function(player, formname, fields)
local lang = quikbild.languages_by_number[l]
if fields["lang_"..lang.code] then
setting = l
minetest.close_formspec(p_name, "qb_lang")
core.close_formspec(p_name, "qb_lang")
break
end
end

View File

@ -1,4 +1,4 @@
local S = minetest.get_translator("quikbild")
local S = core.get_translator("quikbild")
local storage = quikbild.storage
@ -18,13 +18,13 @@ arena_lib.on_enable("quikbild", function(arena, p_name)
if check_ok then
check_ok, error_message = quikbild.are_positions_in_arena_region(arena)
if not check_ok then
minetest.chat_send_player(p_name, error_message)
core.chat_send_player(p_name, error_message)
return false
else
return true
end
else
minetest.chat_send_player(p_name, error_message)
core.chat_send_player(p_name, error_message)
return false
end
end)
@ -33,9 +33,9 @@ arena_lib.on_load("quikbild", function(arena)
--randomize math.random
math.randomseed(os.time())
local f = quikbild.csv.open(minetest.get_modpath("quikbild")..arena.word_list_path)
local f = quikbild.csv.open(core.get_modpath("quikbild")..arena.word_list_path)
if not f then
f = quikbild.csv.open(minetest.get_worldpath()..arena.word_list_path)
f = quikbild.csv.open(core.get_worldpath()..arena.word_list_path)
end
if f then
@ -63,13 +63,13 @@ arena_lib.on_load("quikbild", function(arena)
local poss = {}
local ser_poss = storage:get_string("pos_"..arena.name)
if ser_poss then
poss = minetest.deserialize(ser_poss)
poss = core.deserialize(ser_poss)
if poss == nil then poss = {} end
end
if #poss > 0 then
minetest.bulk_set_node(poss, {name="quikbild:climb"})
core.bulk_set_node(poss, {name="quikbild:climb"})
end
storage:set_string("pos_"..arena.name,minetest.serialize({}))
storage:set_string("pos_"..arena.name,core.serialize({}))
end)
@ -138,7 +138,7 @@ arena_lib.on_time_tick('quikbild', function(arena)
arena_lib.HUD_send_msg("broadcast", pl_name, S('@1 is the artist.', arena.artist), 2 ,nil,0xFF0000)
-- give everyone except the artist helpful tools
local l_player = minetest.get_player_by_name(pl_name)
local l_player = core.get_player_by_name(pl_name)
l_player:hud_set_hotbar_itemcount(3)
l_player:hud_set_hotbar_image("quikbild_gui_hotbar3.png")
@ -151,12 +151,12 @@ arena_lib.on_time_tick('quikbild', function(arena)
l_player:get_inventory():set_stack("main", idx, item)
end
minetest.after(2, function(arena,pl_name)
core.after(2, function(arena,pl_name)
arena_lib.HUD_send_msg("hotbar", pl_name, S('Guess what they are building.'), 2 ,nil,0xFF0000)
end,arena,pl_name)
else
-- set the artist's hotbar larger
local player = minetest.get_player_by_name(pl_name)
local player = core.get_player_by_name(pl_name)
player:hud_set_hotbar_itemcount(15)
player:hud_set_hotbar_image("quikbild_gui_hotbar15.png")
@ -172,16 +172,16 @@ arena_lib.on_time_tick('quikbild', function(arena)
local poss = {}
local ser_poss = storage:get_string("pos_"..arena.name)
if ser_poss then
poss = minetest.deserialize(ser_poss)
poss = core.deserialize(ser_poss)
if poss == nil then poss = {} end
end
if #poss > 0 then
minetest.bulk_set_node(poss, {name="quikbild:climb"})
core.bulk_set_node(poss, {name="quikbild:climb"})
end
storage:set_string("pos_"..arena.name,minetest.serialize({}))
storage:set_string("pos_"..arena.name,core.serialize({}))
-- teleport the artist in to the building area.
local artist_pl = minetest.get_player_by_name(arena.artist)
local artist_pl = core.get_player_by_name(arena.artist)
artist_pl:move_to(arena.artist_spawn_pos)
end
@ -192,7 +192,7 @@ arena_lib.on_time_tick('quikbild', function(arena)
num_players = num_players + 1
local msg = S("Oops! The artist left the game.")
arena_lib.HUD_send_msg("title", pl_name, msg, 3, 'quikbild_elim',0xFFFFFF)
minetest.chat_send_player(pl_name,minetest.colorize("#7D7071",">> "..msg))
core.chat_send_player(pl_name,core.colorize("#7D7071",">> "..msg))
end
if num_players == 1 then
arena.state = 'game_over'
@ -223,7 +223,7 @@ arena_lib.on_time_tick('quikbild', function(arena)
--give the artist his tools, send start to everyone, change state
for pl_name, stats in pairs(arena.players) do
if pl_name == arena.artist then
local player = minetest.get_player_by_name(pl_name)
local player = core.get_player_by_name(pl_name)
for idx ,itemname in pairs(quikbild.items) do
local item = ItemStack(itemname)
player:get_inventory():set_stack("main", idx, item)
@ -258,7 +258,7 @@ arena_lib.on_time_tick('quikbild', function(arena)
for pl_name,stats in pairs(arena.players) do
local msg = S("Oops! The artist left the game. The word was @1", arena.word[stats.lang])
arena_lib.HUD_send_msg("title", pl_name, msg, 3, 'quikbild_elim',0xFFFFFF)
minetest.chat_send_player(pl_name,minetest.colorize("#7D7071",">> "..msg))
core.chat_send_player(pl_name,core.colorize("#7D7071",">> "..msg))
end
reset_arena_choose_artist(arena)
return
@ -272,7 +272,7 @@ arena_lib.on_time_tick('quikbild', function(arena)
for pl_name,stats in pairs(arena.players) do
local msg = S("TIME's UP! The word was: @1", arena.word[stats.lang])
arena_lib.HUD_send_msg("title", pl_name, msg, 3, 'quikbild_lose',0xFFFFFF)
minetest.chat_send_player(pl_name,minetest.colorize("#7D7071",">> "..msg))
core.chat_send_player(pl_name,core.colorize("#7D7071",">> "..msg))
end
reset_arena_choose_artist(arena)
return
@ -295,7 +295,7 @@ end)
table.insert(minetest.registered_on_chat_messages, 1, function(p_name, message) --thanks rubenwardy, for giving this code snippet that works around Arena_libs's chat prevention!
table.insert(core.registered_on_chat_messages, 1, function(p_name, message) --thanks rubenwardy, for giving this code snippet that works around Arena_libs's chat prevention!
if message:sub(1, 1) == "/" then
return false
end
@ -317,7 +317,7 @@ table.insert(minetest.registered_on_chat_messages, 1, function(p_name, message)
local list = {S('Correct!'), S('You got it!'),S('Way to go!'), S('Outstanding!'), S('Yay!')}
local msg = list[math.random(1,5)]..' '..S("+1 pt")
arena_lib.HUD_send_msg("title", pl_name, msg, 3 ,'quikbild_win',0x00FF00)
minetest.chat_send_player(pl_name,minetest.colorize("#7D7071",">> "..msg.." "..S("The word was: @1", arena.word[stats.lang])))
core.chat_send_player(pl_name,core.colorize("#7D7071",">> "..msg.." "..S("The word was: @1", arena.word[stats.lang])))
arena.players[p_name].score = arena.players[p_name].score + 1
elseif pl_name == arena.artist then
local msg = S('Yay!').. ' '.. S('@1 guessed your word.', p_name) ..' '..S("+1 pt")
@ -326,7 +326,7 @@ table.insert(minetest.registered_on_chat_messages, 1, function(p_name, message)
else
local msg = S('@1 guessed the word. Round over!', p_name)
arena_lib.HUD_send_msg("title", pl_name, msg, 3 ,'quikbild_elim',0x00FF00)
minetest.chat_send_player(pl_name,minetest.colorize("#7D7071",">> "..msg.." "..S("The word was: @1", arena.word[stats.lang])))
core.chat_send_player(pl_name,core.colorize("#7D7071",">> "..msg.." "..S("The word was: @1", arena.word[stats.lang])))
end
end
update_leaderboard(arena)
@ -356,7 +356,7 @@ end)
arena_lib.on_celebration('quikbild', function(arena, winner_name)
arena.artist = ""
for pl_name,stats in pairs(arena.players) do
minetest.close_formspec(pl_name, "qb_lang")
core.close_formspec(pl_name, "qb_lang")
end
end)
@ -368,7 +368,7 @@ end)
arena_lib.on_quit('quikbild', function(arena, p_name, is_forced)
minetest.close_formspec(p_name, "qb_lang")
core.close_formspec(p_name, "qb_lang")
quikbild.remove_hud(p_name)
update_leaderboard(arena)
end)
@ -405,7 +405,7 @@ end
-- clears inventory of quikbild items
clearinv = function(p_name)
local player = minetest.get_player_by_name(p_name)
local player = core.get_player_by_name(p_name)
local inv = player:get_inventory()
for idx ,itemname in pairs(quikbild.items) do
local stack = ItemStack(itemname)
@ -423,13 +423,13 @@ end
reset_arena_choose_artist = function(arena)
arena.stall = true --stop gameplay for 3 sec
minetest.after(3,function(arena)
core.after(3,function(arena)
if arena.in_game then
arena.stall = false
arena.state = 'choose_artist'
arena.state_time = 0
for pl_name,stats in pairs(arena.players) do
arena_lib.teleport_onto_spawner(minetest.get_player_by_name(pl_name), arena)
arena_lib.teleport_onto_spawner(core.get_player_by_name(pl_name), arena)
clearinv(pl_name)
end
@ -446,12 +446,12 @@ end
-- ##########################
minetest.register_on_joinplayer(function(player, last_login)
core.register_on_joinplayer(function(player, last_login)
local p_name = player:get_player_name()
clearinv(p_name)
-- set up language on first join. Players can change it at will later.
if last_login == nil then
local player_info = minetest.get_player_information(p_name)
local player_info = core.get_player_information(p_name)
local lang = player_info.lang_code
local setting = 1
if quikbild.languages[lang] then
@ -459,7 +459,7 @@ minetest.register_on_joinplayer(function(player, last_login)
end
local qb_lang = quikbild.languages_by_number[setting].code or "en"
minetest.log("action", "[quikbild] Initial Quikbild language of "..p_name.." set to '"..qb_lang.."' ("..setting..")")
core.log("action", "[quikbild] Initial Quikbild language of "..p_name.." set to '"..qb_lang.."' ("..setting..")")
storage:set_string("lang_"..p_name, tostring(setting))
end

View File

@ -1,7 +1,7 @@
local S = minetest.get_translator("quikbild")
local S = core.get_translator("quikbild")
minetest.register_node("quikbild:climb", {
core.register_node("quikbild:climb", {
description = S("Quikbild Climb-able Node"),
drawtype = "airlike",
tiles = {},
@ -45,7 +45,7 @@ for i = 1, 15 do
local desc = colors[i][2]
minetest.register_node("quikbild:" .. name, {
core.register_node("quikbild:" .. name, {
description = desc,
tiles = {"quikbild_wool_" .. name .. ".png"},
range = 10.0,
@ -57,17 +57,17 @@ for i = 1, 15 do
local p_name = placer:get_player_name()
if arena_lib.is_player_in_arena(p_name, "quikbild") then
local arena = arena_lib.get_arena_by_player(p_name)
--minetest.chat_send_all('ln17')
--core.chat_send_all('ln17')
local pos = pointed_thing.above
if pos and minetest.get_node(pos).name == 'air' or string.find(minetest.get_node(pos).name,'quikbild') then
minetest.set_node(pos, {name="quikbild:" .. name})
if pos and core.get_node(pos).name == 'air' or string.find(core.get_node(pos).name,'quikbild') then
core.set_node(pos, {name="quikbild:" .. name})
local poss = {}
local ser_poss = storage:get_string("pos_"..arena.name)
if ser_poss then
poss = minetest.deserialize(ser_poss)
poss = core.deserialize(ser_poss)
end
table.insert(poss,pos)
storage:set_string("pos_"..arena.name,minetest.serialize(poss))
storage:set_string("pos_"..arena.name,core.serialize(poss))
return ItemStack("quikbild:" .. name), pos
end
end
@ -79,9 +79,9 @@ for i = 1, 15 do
on_use = function(itemstack, user, pointed_thing)
if arena_lib.is_player_in_arena(user:get_player_name(), "quikbild") then
local pos = pointed_thing.under
if pos and string.find(minetest.get_node(pos).name,'quikbild') then
if pos and string.find(core.get_node(pos).name,'quikbild') then
minetest.set_node(pos, {name="quikbild:climb"})
core.set_node(pos, {name="quikbild:climb"})
end
end
return nil

View File

@ -1,5 +1,5 @@
local S = minetest.get_translator("quikbild")
local S = core.get_translator("quikbild")
minetest.register_privilege("quikbild_admin", {
core.register_privilege("quikbild_admin", {
description = S("With this you can use /quikbild create <arena_name>,/quikbild edit <arena_name>")
})

View File

@ -1,4 +1,4 @@
local S = minetest.get_translator("quikbild")
local S = core.get_translator("quikbild")
-- Utility functions