add an API for other mods to add new entries with

This commit is contained in:
FaceDeer 2020-11-27 22:38:27 -07:00
parent acf796e9b8
commit 0fe47ebaad
2 changed files with 43 additions and 1 deletions

View File

@ -1,3 +1,5 @@
personal_log = {}
local modname = minetest.get_current_modname() local modname = minetest.get_current_modname()
local modpath = minetest.get_modpath(modname) local modpath = minetest.get_modpath(modname)
@ -785,3 +787,33 @@ minetest.register_chatcommand("log", {
end end
---------------------------------------------------------------------------------------------------------
-- API
local add_entry_for_player = function(player_name, category, content, topic_content)
local state = get_state(player_name)
entry_index = state.entry_counts[category] + 1
state.entry_counts[category] = entry_index
state.entry_selected[category] = entry_index
save_entry(player_name, category, entry_index, content, topic_content)
save_state(player_name, state)
end
personal_log.add_location_entry = function(player_name, content, pos)
if pos == nil then
local player = minetest.get_player_by_name(player_name)
pos = player:get_pos()
end
add_entry_for_player(player_name, LOCATION_CATEGORY, content, minetest.pos_to_string(pos))
end
personal_log.add_event_entry = function(player_name, content, event_date)
if event_date == nil then
event_date = os.date("%Y-%m-%d")
end
add_entry_for_player(player_name, EVENT_CATEGORY, content, event_date)
end
personal_log.add_general_entry = function(player_name, content, general_topic)
add_entry_for_player(player_name, GENERAL_CATEGORY, content, general_topic)
end

View File

@ -24,4 +24,14 @@ There's no limit to how many logs a player can write.
Chat command access is disabled by default. If ``personal_log_chat_command`` is set to ``true`` then the ``/log`` chat command can be used to open the personal log. Chat command access is disabled by default. If ``personal_log_chat_command`` is set to ``true`` then the ``/log`` chat command can be used to open the personal log.
If you want to enable this for administrators but require players to craft an item, setting ``personal_log_chat_command_priviledge`` to ``true`` will create the ``personal_log`` privilege to control use of that chat command. Admins will have this privilege it by default. If you want to enable this for administrators but require players to craft an item, setting ``personal_log_chat_command_priviledge`` to ``true`` will create the ``personal_log`` privilege to control use of that chat command. Admins will have this privilege it by default.
# API
Other mods can automatically add log entries to players' personal logs using the following functions:
``personal_log.add_location_entry(player_name, content, pos)`` -- Content is a string. If pos is not provided it defaults to the player's position.
``personal_log.add_event_entry(player_name, content, event_date)`` -- Content is a string. Date should be in the format "%Y-%m-%d", if it is not provided it will default to the current date.
``personal_log.add_general_entry(player_name, content, general_topic)`` -- Both content and general_topic are strings.