diff options
author | Wuzzy <almikes@aol.com> | 2016-08-30 23:00:50 +0200 |
---|---|---|
committer | Wuzzy <almikes@aol.com> | 2016-08-30 23:00:50 +0200 |
commit | 4aa4b7d8e7b6df3499ffbe6c1f54a2256d53aa97 (patch) | |
tree | 90080f6e7687a86efacfd7ef7223d88d98432780 /init.lua | |
parent | c5573d1d267a8c67b77f6d6ae18f3f2bb1df6684 (diff) |
Allow to reveal hidden entries
Diffstat (limited to 'init.lua')
-rw-r--r-- | init.lua | 53 |
1 files changed, 50 insertions, 3 deletions
@@ -43,7 +43,8 @@ function doc.new_entry(category_id, entry_id, def) end end --- Marks a particular entry as viewed by a certain player +-- Marks a particular entry as viewed by a certain player, which also +-- automatically reveals it function doc.mark_entry_as_viewed(playername, category_id, entry_id) if doc.data.players[playername].stored_data.viewed[category_id] == nil then doc.data.players[playername].stored_data.viewed[category_id] = {} @@ -55,6 +56,21 @@ function doc.mark_entry_as_viewed(playername, category_id, entry_id) -- Needed because viewed entries get a different color doc.data.players[playername].entry_textlist_needs_updating = true end + doc.mark_entry_as_revealed(playername, category_id, entry_id) +end + +-- Marks a particular entry as revealed/unhidden by a certain player +function doc.mark_entry_as_revealed(playername, category_id, entry_id) + if doc.data.players[playername].stored_data.revealed[category_id] == nil then + doc.data.players[playername].stored_data.revealed[category_id] = {} + doc.data.players[playername].stored_data.revealed_count[category_id] = 0 + end + if doc.entry_exists(category_id, entry_id) and doc.data.players[playername].stored_data.revealed[category_id][entry_id] ~= true then + doc.data.players[playername].stored_data.revealed[category_id][entry_id] = true + doc.data.players[playername].stored_data.revealed_count[category_id] = doc.data.players[playername].stored_data.revealed_count[category_id] + 1 + -- Needed because a new entry is added to the list of visible entries + doc.data.players[playername].entry_textlist_needs_updating = true + end end -- Returns true if the specified entry has been viewed by the player @@ -66,6 +82,20 @@ function doc.entry_viewed(playername, category_id, entry_id) end end +-- Returns true if the specified entry is hidden from the player +function doc.entry_revealed(playername, category_id, entry_id) + local hidden = doc.data.categories[category_id].entries[entry_id].hidden + if doc.data.players[playername].stored_data.revealed[category_id] == nil then + return not hidden + else + if hidden then + return doc.data.players[playername].stored_data.revealed[category_id][entry_id] == true + else + return true + end + end +end + -- Returns category definition function doc.get_category_definition(category_id) if doc.data.categories[category_id] == nil then @@ -174,6 +204,19 @@ function doc.get_viewed_count(playername, category_id) end end +-- Returns how many entries have been revealed by the player +function doc.get_revealed_count(playername, category_id) + if doc.data.players[playername] == nil then + return nil + end + local count = doc.data.players[playername].stored_data.revealed_count[category_id] + if count == nil then + return 0 + else + return count + end +end + -- Template function templates, to be used for build_formspec in doc.new_category doc.entry_builders = {} @@ -290,8 +333,8 @@ function doc.generate_entry_list(cid, playername) doc.data.players[playername].entry_ids = {} local entries = doc.get_sorted_entry_names(cid) for i=1, #entries do - if not entries[i].hidden then - local eid = entries[i].eid + local eid = entries[i].eid + if doc.entry_revealed(playername, cid, eid) then table.insert(doc.data.players[playername].entry_ids, eid) -- Colorize entries based on viewed status -- Not viewed: Cyan @@ -569,6 +612,10 @@ minetest.register_on_joinplayer(function(player) doc.data.players[playername].stored_data.viewed = {} -- Count viewed entries doc.data.players[playername].stored_data.viewed_count = {} + -- Contains revealed/unhidden entries + doc.data.players[playername].stored_data.revealed = {} + -- Count revealed entries + doc.data.players[playername].stored_data.revealed_count = {} end end) |