add an API for other mods to add new entries with
This commit is contained in:
parent
acf796e9b8
commit
0fe47ebaad
32
init.lua
32
init.lua
@ -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
|
12
readme.md
12
readme.md
@ -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.
|
Loading…
x
Reference in New Issue
Block a user