mirror of
https://github.com/AntumMT/mod-wdata.git
synced 2024-07-04 15:05:19 +02:00
Rename to "wdata"
This commit is contained in:
parent
d7ef85ca61
commit
aaa408bcf5
12
README.md
12
README.md
@ -1,10 +1,10 @@
|
||||
## World Config mod for Minetest
|
||||
## World Data Manager library for Minetest
|
||||
|
||||
### Description:
|
||||
|
||||
A [Minetest][] library for managing data files in the world directory.
|
||||
|
||||
It takes a little work to read from & write to data in the world directory. wconfig aims to make that easier by utilizing just two simple methods.
|
||||
It takes a little work to read from & write to data in the world directory. `wdata` aims to make that easier by utilizing just two simple methods.
|
||||
|
||||
### Licensing:
|
||||
|
||||
@ -15,10 +15,10 @@ It takes a little work to read from & write to data in the world directory. wcon
|
||||
There are two methods:
|
||||
|
||||
```
|
||||
- wconfig.read(fname)
|
||||
- wdata.read(fname)
|
||||
- reads json data from file in world directory & converts to a table.
|
||||
- fname: File basename without suffix (e.g. "my_config" or "my_mod/my_config").
|
||||
- wconfig.write(fname, data[, styled])
|
||||
- wdata.write(fname, data[, styled])
|
||||
- converts table to json data & writes to file in world directory.
|
||||
- fname: File basename without suffix (e.g. "my_config" or "my_mod/my_config").
|
||||
- data: Table containing data to be exported.
|
||||
@ -35,8 +35,8 @@ Optional depends: none
|
||||
### Links
|
||||
|
||||
- [Forum](https://forum.minetest.net/viewtopic.php?t=26804)
|
||||
- [Git repo](https://github.com/AntumMT/mod-wconfig)
|
||||
- [API](https://antummt.github.io/mod-wconfig/docs/api.html)
|
||||
- [Git repo](https://github.com/AntumMT/mod-wdata)
|
||||
- [API](https://antummt.github.io/mod-wdata/docs/api.html)
|
||||
- [Changelog](changelog.txt)
|
||||
- [TODO](TODO.txt)
|
||||
|
||||
|
26
api.lua
26
api.lua
@ -1,5 +1,5 @@
|
||||
|
||||
--- wconfig API
|
||||
--- World Data Manager API
|
||||
--
|
||||
-- @module api.lua
|
||||
|
||||
@ -29,16 +29,16 @@ end
|
||||
|
||||
--- Reads config file from world directory.
|
||||
--
|
||||
-- @function wconfig.read
|
||||
-- @function wdata.read
|
||||
-- @tparam string fname Base filename with optional directory structure (e.g. "my_mod/my_config")
|
||||
-- @treturn table Table with contents read from json file or `nil`.
|
||||
function wconfig.read(fname)
|
||||
function wdata.read(fname)
|
||||
local fpath = world_path .. "/" .. fname .. ".json"
|
||||
|
||||
-- check if file exists
|
||||
local fopen = io.open(fpath, "r")
|
||||
if not fopen then
|
||||
wconfig.log("error", "file not found: " .. fpath)
|
||||
wdata.log("error", "file not found: " .. fpath)
|
||||
return
|
||||
end
|
||||
|
||||
@ -46,7 +46,7 @@ function wconfig.read(fname)
|
||||
io.close(fopen)
|
||||
|
||||
if not table_data then
|
||||
wconfig.log("error", "cannot read json data from file: " .. fpath)
|
||||
wdata.log("error", "cannot read json data from file: " .. fpath)
|
||||
return
|
||||
end
|
||||
|
||||
@ -56,17 +56,17 @@ end
|
||||
|
||||
--- Writes to config file in world directory.
|
||||
--
|
||||
-- @function wconfig.write
|
||||
-- @function wdata.write
|
||||
-- @tparam string fname Base filename with optional directory structure (e.g. "my_mod/my_config").
|
||||
-- @tparam table data Table data to be written to config file.
|
||||
-- @tparam[opt] bool styled Outputs in a human-readable format if this is set (default: `true`).
|
||||
-- @treturn bool `true` if succeeded, `false` if not.
|
||||
function wconfig.write(fname, data, styled)
|
||||
function wdata.write(fname, data, styled)
|
||||
styled = styled ~= false
|
||||
|
||||
local json_data = core.write_json(data, styled)
|
||||
if not json_data then
|
||||
wconfig.log("error", "cannot convert data to json format")
|
||||
wdata.log("error", "cannot convert data to json format")
|
||||
return false
|
||||
end
|
||||
|
||||
@ -76,7 +76,7 @@ function wconfig.write(fname, data, styled)
|
||||
local dirname = get_dir(fpath)
|
||||
if dirname ~= world_path then
|
||||
if not core.mkdir(dirname) then
|
||||
wconfig.log("error", "cannot create directory: " .. dirname)
|
||||
wdata.log("error", "cannot create directory: " .. dirname)
|
||||
return false
|
||||
end
|
||||
end
|
||||
@ -89,16 +89,16 @@ end
|
||||
--
|
||||
-- @section aliases
|
||||
|
||||
--- Alias of `wconfig.read`.
|
||||
--- Alias of `wdata.read`.
|
||||
--
|
||||
-- @falias minetest.read_world_config
|
||||
if not core.read_world_config then
|
||||
core.read_world_config = wconfig.read
|
||||
core.read_world_config = wdata.read
|
||||
end
|
||||
|
||||
--- Alias of `wconfig.write`.
|
||||
--- Alias of `wdata.write`.
|
||||
--
|
||||
-- @falias minetest.write_world_config
|
||||
if not core.write_world_config then
|
||||
core.write_world_config = wconfig.write
|
||||
core.write_world_config = wdata.write
|
||||
end
|
||||
|
@ -3,7 +3,7 @@
|
||||
<html>
|
||||
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
|
||||
<head>
|
||||
<title>World Config</title>
|
||||
<title>World Data Manager</title>
|
||||
<link rel="stylesheet" href="ldoc.css" type="text/css" />
|
||||
</head>
|
||||
<body>
|
||||
@ -24,7 +24,7 @@
|
||||
|
||||
<div id="navigation">
|
||||
<br/>
|
||||
<h1>wconfig</h1>
|
||||
<h1>wdata</h1>
|
||||
|
||||
|
||||
|
||||
@ -45,7 +45,7 @@
|
||||
<div id="content">
|
||||
|
||||
<h1>Module <code>api.lua</code></h1>
|
||||
<p>wconfig API</p>
|
||||
<p>World Data Manager API</p>
|
||||
<p>
|
||||
|
||||
</p>
|
||||
@ -54,11 +54,11 @@
|
||||
<h2><a href="#Functions">Functions</a></h2>
|
||||
<table class="function_list">
|
||||
<tr>
|
||||
<td class="name" nowrap><a href="#wconfig.read">wconfig.read (fname)</a></td>
|
||||
<td class="name" nowrap><a href="#wdata.read">wdata.read (fname)</a></td>
|
||||
<td class="summary">Reads config file from world directory.</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td class="name" nowrap><a href="#wconfig.write">wconfig.write (fname, data[, styled])</a></td>
|
||||
<td class="name" nowrap><a href="#wdata.write">wdata.write (fname, data[, styled])</a></td>
|
||||
<td class="summary">Writes to config file in world directory.</td>
|
||||
</tr>
|
||||
</table>
|
||||
@ -66,11 +66,11 @@
|
||||
<table class="function_list">
|
||||
<tr>
|
||||
<td class="name" nowrap><a href="#minetest.read_world_config">minetest.read_world_config</a></td>
|
||||
<td class="summary">Alias of <a href="api.html#wconfig.read">wconfig.read</a>.</td>
|
||||
<td class="summary">Alias of <a href="api.html#wdata.read">wdata.read</a>.</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td class="name" nowrap><a href="#minetest.write_world_config">minetest.write_world_config</a></td>
|
||||
<td class="summary">Alias of <a href="api.html#wconfig.write">wconfig.write</a>.</td>
|
||||
<td class="summary">Alias of <a href="api.html#wdata.write">wdata.write</a>.</td>
|
||||
</tr>
|
||||
</table>
|
||||
|
||||
@ -82,8 +82,8 @@
|
||||
|
||||
<dl class="function">
|
||||
<dt>
|
||||
<a name = "wconfig.read"></a>
|
||||
<strong>wconfig.read (fname)</strong>
|
||||
<a name = "wdata.read"></a>
|
||||
<strong>wdata.read (fname)</strong>
|
||||
</dt>
|
||||
<dd>
|
||||
Reads config file from world directory.
|
||||
@ -109,8 +109,8 @@
|
||||
|
||||
</dd>
|
||||
<dt>
|
||||
<a name = "wconfig.write"></a>
|
||||
<strong>wconfig.write (fname, data[, styled])</strong>
|
||||
<a name = "wdata.write"></a>
|
||||
<strong>wdata.write (fname, data[, styled])</strong>
|
||||
</dt>
|
||||
<dd>
|
||||
Writes to config file in world directory.
|
||||
@ -153,7 +153,7 @@
|
||||
<strong>minetest.read_world_config</strong>
|
||||
</dt>
|
||||
<dd>
|
||||
Alias of <a href="api.html#wconfig.read">wconfig.read</a>.
|
||||
Alias of <a href="api.html#wdata.read">wdata.read</a>.
|
||||
|
||||
|
||||
|
||||
@ -167,7 +167,7 @@
|
||||
<strong>minetest.write_world_config</strong>
|
||||
</dt>
|
||||
<dd>
|
||||
Alias of <a href="api.html#wconfig.write">wconfig.write</a>.
|
||||
Alias of <a href="api.html#wdata.write">wdata.write</a>.
|
||||
|
||||
|
||||
|
||||
@ -183,7 +183,7 @@
|
||||
</div> <!-- id="main" -->
|
||||
<div id="about">
|
||||
<i>generated by <a href="http://github.com/stevedonovan/LDoc">LDoc 1.4.6</a></i>
|
||||
<i style="float:right;">Last updated 2021-05-27 23:43:31 </i>
|
||||
<i style="float:right;">Last updated 2021-05-28 00:24:34 </i>
|
||||
</div> <!-- id="about" -->
|
||||
</div> <!-- id="container" -->
|
||||
</body>
|
||||
|
@ -1,5 +1,5 @@
|
||||
project = "wconfig"
|
||||
title = "World Config"
|
||||
project = "wdata"
|
||||
title = "World Data Manager"
|
||||
format = "markdown"
|
||||
not_luadoc = true
|
||||
boilerplate = false
|
||||
|
12
init.lua
12
init.lua
@ -1,15 +1,15 @@
|
||||
|
||||
wconfig = {}
|
||||
wconfig.modname = core.get_current_modname()
|
||||
wconfig.modpath = core.get_modpath(wconfig.modname)
|
||||
wdata = {}
|
||||
wdata.modname = core.get_current_modname()
|
||||
wdata.modpath = core.get_modpath(wdata.modname)
|
||||
|
||||
function wconfig.log(lvl, msg)
|
||||
function wdata.log(lvl, msg)
|
||||
if not msg then
|
||||
msg = lvl
|
||||
lvl = nil
|
||||
end
|
||||
|
||||
msg = "[" .. wconfig.modname .. "] " .. msg
|
||||
msg = "[" .. wdata.modname .. "] " .. msg
|
||||
if not lvl then
|
||||
core.log(msg)
|
||||
else
|
||||
@ -18,4 +18,4 @@ function wconfig.log(lvl, msg)
|
||||
end
|
||||
|
||||
|
||||
dofile(wconfig.modpath .. "/api.lua")
|
||||
dofile(wdata.modpath .. "/api.lua")
|
||||
|
6
mod.conf
6
mod.conf
@ -1,6 +1,6 @@
|
||||
name = wconfig
|
||||
title = World Config
|
||||
description = Bridging world configuration files & mods.
|
||||
name = wdata
|
||||
title = World Data Manager
|
||||
description = A library for managing data files in the world directory.
|
||||
version = 1.0
|
||||
license = MIT
|
||||
author = Jordan Irwin (AntumDeluge)
|
||||
|
Loading…
Reference in New Issue
Block a user