Hint refactors, chat alert upon completion.
The new chat stream message is an experimental feature; it MAY be too intrusive for some players, so may have to be disabled by default or removed.
This commit is contained in:
parent
17a105d658
commit
ce1200e135
31
mods/nc_guide/alerts.lua
Normal file
31
mods/nc_guide/alerts.lua
Normal file
@ -0,0 +1,31 @@
|
||||
-- LUALOCALS < ---------------------------------------------------------
|
||||
local minetest, nodecore, pairs
|
||||
= minetest, nodecore, pairs
|
||||
-- LUALOCALS > ---------------------------------------------------------
|
||||
|
||||
local donecache = {}
|
||||
|
||||
local msg = "hint complete - @1"
|
||||
nodecore.translate_inform(msg)
|
||||
|
||||
minetest.register_on_joinplayer(function(player)
|
||||
local pname = player:get_player_name()
|
||||
local _, done = nodecore.hint_state(pname)
|
||||
local t = {}
|
||||
for _, v in pairs(done) do t[v.text] = true end
|
||||
donecache[pname] = t
|
||||
end)
|
||||
|
||||
nodecore.register_on_player_discover(function(player)
|
||||
local pname = player:get_player_name()
|
||||
local t = donecache[pname]
|
||||
if not t then return end
|
||||
local _, done = nodecore.hint_state(pname)
|
||||
for _, v in pairs(done) do
|
||||
if not t[v.text] then
|
||||
t[v.text] = true
|
||||
minetest.chat_send_player(pname, minetest.colorize("#e0ff80",
|
||||
nodecore.translate(msg, v.text)))
|
||||
end
|
||||
end
|
||||
end)
|
@ -1,6 +1,6 @@
|
||||
-- LUALOCALS < ---------------------------------------------------------
|
||||
local nodecore, type
|
||||
= nodecore, type
|
||||
local ipairs, minetest, nodecore, pairs, type
|
||||
= ipairs, minetest, nodecore, pairs, type
|
||||
-- LUALOCALS > ---------------------------------------------------------
|
||||
|
||||
nodecore.hints = {}
|
||||
@ -33,11 +33,49 @@ function nodecore.addhint(text, goal, reqs)
|
||||
local hints = nodecore.hints
|
||||
local t = nodecore.translate(text)
|
||||
local h = {
|
||||
text = nodecore.translate("- @1", t),
|
||||
done = nodecore.translate("- DONE: @1", t),
|
||||
text = t,
|
||||
goal = conv(goal),
|
||||
reqs = conv(reqs)
|
||||
}
|
||||
hints[#hints + 1] = h
|
||||
return h
|
||||
end
|
||||
|
||||
function nodecore.hint_state(player)
|
||||
local rawdb = nodecore.statsdb[type(player) == "string"
|
||||
and player or player:get_player_name()] or {}
|
||||
|
||||
local db = {}
|
||||
for _, r in ipairs({"inv", "punch", "dig", "place", "craft", "witness"}) do
|
||||
for k, v in pairs(rawdb[r] or {}) do
|
||||
db[k] = v
|
||||
db[r .. ":" .. k] = v
|
||||
end
|
||||
end
|
||||
for k, v in pairs(minetest.registered_items) do
|
||||
if db[k] then
|
||||
if v.tool_capabilities and v.tool_capabilities.groupcaps then
|
||||
for gn, gv in pairs(v.tool_capabilities.groupcaps) do
|
||||
for gt in pairs(gv.times or {}) do
|
||||
db["toolcap:" .. gn .. ":" .. gt] = true
|
||||
end
|
||||
end
|
||||
end
|
||||
for gn, gv in pairs(v.groups or {}) do
|
||||
db["group:" .. gn] = gv
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
local done = {}
|
||||
local found = {}
|
||||
for _, hint in ipairs(nodecore.hints) do
|
||||
if hint.goal(db) then
|
||||
done[#done + 1] = hint
|
||||
elseif hint.reqs(db) then
|
||||
found[#found + 1] = hint
|
||||
end
|
||||
end
|
||||
|
||||
return found, done
|
||||
end
|
||||
|
@ -8,3 +8,4 @@ nodecore.amcoremod()
|
||||
include("api")
|
||||
include("hints")
|
||||
include("invtab")
|
||||
include("alerts")
|
||||
|
@ -1,6 +1,6 @@
|
||||
-- LUALOCALS < ---------------------------------------------------------
|
||||
local ipairs, math, minetest, nodecore, pairs, table
|
||||
= ipairs, math, minetest, nodecore, pairs, table
|
||||
local math, minetest, nodecore, pairs, table
|
||||
= math, minetest, nodecore, pairs, table
|
||||
local math_floor, math_random, table_remove, table_sort
|
||||
= math.floor, math.random, table.remove, table.sort
|
||||
-- LUALOCALS > ---------------------------------------------------------
|
||||
@ -11,7 +11,9 @@ local strings = {
|
||||
onemore = "(and 1 more hint)",
|
||||
fewmore = "(and @1 more hints)",
|
||||
progress = "Progress: @1 complete, @2 current, @3 future",
|
||||
explore = "Not all game content is covered by hints. Explore!"
|
||||
explore = "Not all game content is covered by hints. Explore!",
|
||||
hint = "- @1",
|
||||
done = "- DONE: @1"
|
||||
}
|
||||
|
||||
for k, v in pairs(strings) do
|
||||
@ -26,38 +28,10 @@ local function gethint(player)
|
||||
local cached = pcache[pname]
|
||||
if cached and cached.time == now then return cached.found end
|
||||
|
||||
local rawdb = nodecore.statsdb[pname] or {}
|
||||
local db = {}
|
||||
for _, r in ipairs({"inv", "punch", "dig", "place", "craft", "witness"}) do
|
||||
for k, v in pairs(rawdb[r] or {}) do
|
||||
db[k] = v
|
||||
db[r .. ":" .. k] = v
|
||||
end
|
||||
end
|
||||
for k, v in pairs(minetest.registered_items) do
|
||||
if db[k] then
|
||||
if v.tool_capabilities and v.tool_capabilities.groupcaps then
|
||||
for gn, gv in pairs(v.tool_capabilities.groupcaps) do
|
||||
for gt in pairs(gv.times or {}) do
|
||||
db["toolcap:" .. gn .. ":" .. gt] = true
|
||||
end
|
||||
end
|
||||
end
|
||||
for gn, gv in pairs(v.groups or {}) do
|
||||
db["group:" .. gn] = gv
|
||||
end
|
||||
end
|
||||
end
|
||||
local found, done = nodecore.hint_state(pname)
|
||||
for k, v in pairs(found) do found[k] = strings.hint(v.text) end
|
||||
for k, v in pairs(done) do done[k] = strings.done(v.text) end
|
||||
|
||||
local done = {}
|
||||
local found = {}
|
||||
for _, hint in ipairs(nodecore.hints) do
|
||||
if hint.goal(db) then
|
||||
done[#done + 1] = hint.done
|
||||
elseif hint.reqs(db) then
|
||||
found[#found + 1] = hint.text
|
||||
end
|
||||
end
|
||||
local prog = #found
|
||||
local left = #(nodecore.hints) - prog - #done
|
||||
|
||||
|
@ -12,6 +12,10 @@ nodecore.amcoremod()
|
||||
local modname = minetest.get_current_modname()
|
||||
local modstore = minetest.get_mod_storage()
|
||||
|
||||
nodecore.register_on_player_discover,
|
||||
nodecore.registered_on_player_discovers
|
||||
= nodecore.mkreg()
|
||||
|
||||
------------------------------------------------------------------------
|
||||
-- DATABASE SETUP
|
||||
|
||||
@ -73,6 +77,9 @@ local function playeradd(qty, player, ...)
|
||||
local t = {...}
|
||||
minetest.log(string_format("player %q discovered %q",
|
||||
pname, table_concat(t, ":")))
|
||||
for _, v in pairs(nodecore.registered_on_player_discovers) do
|
||||
v(player, t)
|
||||
end
|
||||
end
|
||||
if not statsdb[pname].firstseen then
|
||||
statsdb[pname].firstseen = os_date("!*t")
|
||||
|
Loading…
x
Reference in New Issue
Block a user