Initial commit

This commit is contained in:
AliasAlreadyTaken 2024-05-12 09:37:39 +00:00
commit b6a3a9a752
17 changed files with 327 additions and 0 deletions

19
.luacheckrc Normal file
View File

@ -0,0 +1,19 @@
unused_args = false
allow_defined_top = true
globals = {
"minetest",
"core"
}
read_globals = {
string = {fields = {"split"}},
table = {fields = {"copy", "getn"}},
-- Builtin
"vector", "ItemStack",
"dump", "DIR_DELIM", "VoxelArea", "Settings",
-- MTG
"default", "sfinv", "creative",
}

62
README.md Normal file
View File

@ -0,0 +1,62 @@
# 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. Remove the components you do not want and expand on those you want.
## Download
Get it from https://gitea.your-land.de/your-land/yl_template
## Installation
1. Copy the "yl_template" folder to your mod directory.
2. Enable the mod in your world.mt file.
## Configuration
```
yl_template.debug = false
```
Set to true to enable debug mode
```
yl_template.save_path
```
Set this to where in the worldfolder you want the JSON files stored.
## Usage
This mod targets $[servers|singleplayer|...], but should work in $[[servers|singleplayer|...], too. It comes with no direct content but exposes functions you can use in your mod.
### Chatcommands
### Modmakers
Use the following public functions to $[achieve your goals]
## Limitations
## Alternatives
## Supported versions
If you use yl_template, but something is wrong, please [file a bug](https://gitea.your-land.de/your-land/yl_template/issues/new). PRs also welcome.
There is no reason to believe it doesn't work anywhere, but you never know.
## Allied projects
If you know a project that uses this mod tell us and we will add it to the list.
## Uninstall
Remove it from your mod folder or deactivate it in your world.mt
Mods that depend on it will cease to work, if the mod is removed without proper replacement.
## License
[Shorthand of your chosen license: MIT, LGPLv3+, GPLv3+, AGPL, ...]. Please chose one of the major license that is compatible with as much of the MT universe over some obscure and incompatible license.
## Thank you

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.settings.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")

10
config.lua Normal file
View File

@ -0,0 +1,10 @@
-- Setting a configuration, switch the order in which the settings shall take precedence. First valid one taken.
yl_template.settings = {}
yl_template.settings.external_value = "mod_default" or minetest.settings:get("yl_template.external_value") or "default"
yl_template.settings.save_path = "yl_template" or minetest.settings:get("yl_template.save_path") or "default"
yl_template.settings.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)

36
init.lua Normal file
View File

@ -0,0 +1,36 @@
-- 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 .. "initialize.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]")

7
initialize.lua Normal file
View File

@ -0,0 +1,7 @@
local function run_each_serverstart()
yl_template.data = {}
--minetest.after(0.0, yl_template.load_all_data)
--minetest.after(0.0, yl_template.check_privs)
end
run_each_serverstart()

49
internal.lua Normal file
View File

@ -0,0 +1,49 @@
-- 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 function say(text)
if yl_template.debug then
core.log("action", "[MOD] yl_template : " .. text)
end
end
local function get_savepath()
local savepath = yl_template.worldpath .. yl_template.settings.save_path
say("get_savepath : " .. dump(savepath))
return savepath
end
local function get_filepath(filename)
local path_to_file = get_savepath() .. DIR_DELIM .. filename .. ".json"
say("get_filepath : " .. dump(filename) .. ":" .. dump(path_to_file))
return path_to_file
end
local function save_json(filename, content)
if type(filename) ~= "string" or type(content) ~= "table" then
return false
end
local savepath = get_filepath(filename)
local savecontent = minetest.write_json(content)
return minetest.safe_file_write(savepath, savecontent)
end
local function load_json(path)
local file = io.open(path, "r")
if not file then return false, "Error opening file: " .. path end
local content = file:read("*all")
file:close()
if not content then return false, "Error reading file: " .. path end
return true, minetest.parse_json(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"

15
setup.lua Normal file
View File

@ -0,0 +1,15 @@
local mkdir = minetest.mkdir
local save_path = yl_template.settings.save_path
local function run_once()
local path = yl_template.worldpath .. DIR_DELIM .. save_path
local file = io.open(path, "r")
if not file then
mkdir(path)
else
file:close()
end
end
run_once()