Initial commit

This commit is contained in:
your-flight 2022-04-20 16:00:41 +02:00
commit b1f6ea57ef
15 changed files with 262 additions and 0 deletions

21
README.md Normal file
View File

@ -0,0 +1,21 @@
# yl_template
## Purpose
This mod is not meant to bring functionality by itself, but to serve as a template you can base your mod on.
## Download
Get it from https://gitea.your-land.de/your-land/yl_template
## Installation
Being a template, you shouldn't install the mod itself. Your mod could look like this:
## Usage
## Uninstall
## License

19
chatcommand_admin.lua Normal file
View File

@ -0,0 +1,19 @@
local chatcommand_cmd = "admin_example"
local chatcommand_definition = {
params = "<name> <privilege>", -- Short parameter description
description = "Example description", -- Full description
privs = {[yl_template.admin_priv] = true}, -- Require the "privs" privilege to run
func = function(name, param)
local success = true
if success then
return true, "Sucess message"
else
return false, "Fail message"
end
end
-- Called when command is run. Returns boolean success and text output.
-- Special case: The help message is shown to the player if `func`
-- returns false without a text output.
}
minetest.register_chatcommand(chatcommand_cmd, chatcommand_definition)

19
chatcommand_player.lua Normal file
View File

@ -0,0 +1,19 @@
local chatcommand_cmd = "player_example"
local chatcommand_definition = {
params = "<name> <privilege>", -- Short parameter description
description = "Example description", -- Full description
privs = {privs = true}, -- Require the "privs" privilege to run
func = function(name, param)
local success = true
if success then
return true, "Sucess message"
else
return false, "Fail message"
end
end
-- Called when command is run. Returns boolean success and text output.
-- Special case: The help message is shown to the player if `func`
-- returns false without a text output.
}
minetest.register_chatcommand(chatcommand_cmd, chatcommand_definition)

2
chatcommands.lua Normal file
View File

@ -0,0 +1,2 @@
dofile(yl_template.modpath .. "chatcommand_admin.lua")
dofile(yl_template.modpath .. "chatcommand_player.lua")

8
config.lua Normal file
View File

@ -0,0 +1,8 @@
-- Setting a configuration, switch the order in which the settings shall take precedence. First valid one taken.
yl_template.external_value = "mod_default" or minetest.settings:get("yl_template.external_value") or "default"
yl_template.save_path = "yl_template" or minetest.settings:get("yl_template.save_path") or "default"
yl_template.admin_priv = "admin_priv" or minetest.settings:get("yl_template.admin_priv") or "server"

4
dev/whatdowedo.txt Normal file
View File

@ -0,0 +1,4 @@
This file holds a couple of editors notes regarding the mod.
Todo's can be noted here, known issues, the path to ressources or general annotations.

13
globalsteps.lua Normal file
View File

@ -0,0 +1,13 @@
local timer = 0
local gs = function(dtime)
timer = timer + dtime
if timer <= yl_template.config.interval then
return
end
timer = 0
-- do stuff
end
minetest.register_globalstep(gs)

35
init.lua Normal file
View File

@ -0,0 +1,35 @@
-- Version 0.0.1
-- Author AliasAlreadyTaken
-- License MIT
-- Changelog
local mod_start_time = core.get_us_time()
core.log("action", "[MOD] yl_template loading")
yl_template = {}
yl_template.error = {}
yl_template.modstorage = core.get_mod_storage()
yl_template.modpath = core.get_modpath("yl_template") .. DIR_DELIM
yl_template.worldpath = core.get_worldpath() .. DIR_DELIM
yl_template.information = {}
yl_template.information.version = "0.0.1"
yl_template.information.author = "AliasAlreadyTaken"
yl_template.information.license = "MIT"
yl_template.information.name = "yl_template"
yl_template.information.source = "https://gitea.your-land.de/your-land/yl_template"
yl_template.information.additional = "Additional information"
dofile(yl_template.modpath .. "config.lua")
dofile(yl_template.modpath .. "setup.lua")
dofile(yl_template.modpath .. "privs.lua")
dofile(yl_template.modpath .. "internal.lua")
dofile(yl_template.modpath .. "api.lua")
dofile(yl_template.modpath .. "distinct_feature.lua")
dofile(yl_template.modpath .. "overwrite_feature.lua")
dofile(yl_template.modpath .. "globalsteps.lua")
dofile(yl_template.modpath .. "chatcommands.lua")
local mod_end_time = (core.get_us_time() - mod_start_time) / 1000000
core.log("action", "[MOD] yl_template loaded in [" .. mod_end_time .. "s]")

53
internal.lua Normal file
View File

@ -0,0 +1,53 @@
-- The functions and variables in this file are only for use in the mod itself. Those that do real work should be local and wrapped in public functions
local debug = true
local function say(text)
if yl_template.debug then
core.log("action", "[MOD] yl_template : " .. text)
end
end
local function save_path(file)
return yl_template.worldpath .. file .. ".json"
end
local function save_json(filename, content)
if type(filename) ~= "string" or type(content) ~= "table" then
return false
end
local savepath = save_path(filename)
local savecontent = minetest.write_json(content)
return minetest.safe_file_write(savepath, savecontent)
end
local function load_json(filename) -- returns the saved dialog
local savepath = save_path(filename)
local file, err = io.open(savepath, "r")
if err then
return {}
end
io.input(file)
local savecontent = io.read()
local content = minetest.parse_json(savecontent)
io.close(file)
if type(content) ~= "table" then
content = {}
end
return content
end
-- Public functions wrap the private ones, so they can be exchanged easily
function yl_template.load(filename, ...)
return load_json(filename, ...)
end
function yl_template.save(filename, content, ...)
return save_json(filename, content, ...)
end

7
mod.conf Normal file
View File

@ -0,0 +1,7 @@
name = yl_template
description = A template with best practices
depends = default
optional_depends = moreblocks
author = AliasAlreadyTaken
release = 202106161537
title = Template

58
priv_example.lua Normal file
View File

@ -0,0 +1,58 @@
local priv_name = "example"
local priv_definition = {
description = "Can do example task",
-- Privilege description
give_to_singleplayer = false,
-- Whether to grant the privilege to singleplayer.
give_to_admin = true,
-- Whether to grant the privilege to the server admin.
-- Uses value of 'give_to_singleplayer' by default.
on_grant = function(name, granter_name)
-- logging
if not granter_name then
granter_name = "MOD"
end
if not name then
name = "ERROR"
end
if not priv_name then
priv_name = "ERROR"
end
core.log(
"action",
"[MOD] yl_template: User " .. granter_name .. " granted user " .. name .. " priv " .. priv_name
)
end,
-- Called when given to player 'name' by 'granter_name'.
-- 'granter_name' will be nil if the priv was granted by a mod.
on_revoke = function(name, revoker_name)
-- logging
if not revoker_name then
revoker_name = "MOD"
end
if not name then
name = "ERROR"
end
if not priv_name then
priv_name = "ERROR"
end
core.log(
"action",
"[MOD] yl_template: User " .. revoker_name .. " revoked user " .. name .. " priv " .. priv_name
)
end
-- Called when taken from player 'name' by 'revoker_name'.
-- 'revoker_name' will be nil if the priv was revoked by a mod.
-- Note that the above two callbacks will be called twice if a player is
-- responsible, once with the player name, and then with a nil player
-- name.
-- Return true in the above callbacks to stop register_on_priv_grant or
-- revoke being called.
}
minetest.register_privilege(priv_name, priv_definition)

1
privs.lua Normal file
View File

@ -0,0 +1 @@
dofile(yl_template.modpath .. "priv_example.lua")

BIN
screenshot.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 19 KiB

6
settingtypes.txt Normal file
View File

@ -0,0 +1,6 @@
[category]
# First line: Name the settings
# Second line: Say what it does, how to use it, what it changes
# Third line: Is it optional? What's the default value? Does it expect a certain set of values?
yl_template.external_value (Description of the setting) string "default_value"

16
setup.lua Normal file
View File

@ -0,0 +1,16 @@
local function run_once()
local dl = minetest.get_dir_list(yl_template.worldpath, true)
local create = true
for _, v in ipairs(dl) do
if v == yl_template.save_path then
create = false
end
end
if create then
minetest.mkdir(yl_template.worldpath .. DIR_DELIM .. yl_template.save_path)
end
end
run_once()