Rename to "wdata"

This commit is contained in:
Jordan Irwin 2021-05-28 00:24:10 -07:00
parent d7ef85ca61
commit aaa408bcf5
6 changed files with 44 additions and 44 deletions

@ -1,10 +1,10 @@
## World Config mod for Minetest ## World Data Manager library for Minetest
### Description: ### Description:
A [Minetest][] library for managing data files in the world directory. 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: ### 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: There are two methods:
``` ```
- wconfig.read(fname) - wdata.read(fname)
- reads json data from file in world directory & converts to a table. - 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"). - 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. - 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"). - fname: File basename without suffix (e.g. "my_config" or "my_mod/my_config").
- data: Table containing data to be exported. - data: Table containing data to be exported.
@ -35,8 +35,8 @@ Optional depends: none
### Links ### Links
- [Forum](https://forum.minetest.net/viewtopic.php?t=26804) - [Forum](https://forum.minetest.net/viewtopic.php?t=26804)
- [Git repo](https://github.com/AntumMT/mod-wconfig) - [Git repo](https://github.com/AntumMT/mod-wdata)
- [API](https://antummt.github.io/mod-wconfig/docs/api.html) - [API](https://antummt.github.io/mod-wdata/docs/api.html)
- [Changelog](changelog.txt) - [Changelog](changelog.txt)
- [TODO](TODO.txt) - [TODO](TODO.txt)

26
api.lua

@ -1,5 +1,5 @@
--- wconfig API --- World Data Manager API
-- --
-- @module api.lua -- @module api.lua
@ -29,16 +29,16 @@ end
--- Reads config file from world directory. --- 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") -- @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`. -- @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" local fpath = world_path .. "/" .. fname .. ".json"
-- check if file exists -- check if file exists
local fopen = io.open(fpath, "r") local fopen = io.open(fpath, "r")
if not fopen then if not fopen then
wconfig.log("error", "file not found: " .. fpath) wdata.log("error", "file not found: " .. fpath)
return return
end end
@ -46,7 +46,7 @@ function wconfig.read(fname)
io.close(fopen) io.close(fopen)
if not table_data then 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 return
end end
@ -56,17 +56,17 @@ end
--- Writes to config file in world directory. --- 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 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 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`). -- @tparam[opt] bool styled Outputs in a human-readable format if this is set (default: `true`).
-- @treturn bool `true` if succeeded, `false` if not. -- @treturn bool `true` if succeeded, `false` if not.
function wconfig.write(fname, data, styled) function wdata.write(fname, data, styled)
styled = styled ~= false styled = styled ~= false
local json_data = core.write_json(data, styled) local json_data = core.write_json(data, styled)
if not json_data then 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 return false
end end
@ -76,7 +76,7 @@ function wconfig.write(fname, data, styled)
local dirname = get_dir(fpath) local dirname = get_dir(fpath)
if dirname ~= world_path then if dirname ~= world_path then
if not core.mkdir(dirname) then if not core.mkdir(dirname) then
wconfig.log("error", "cannot create directory: " .. dirname) wdata.log("error", "cannot create directory: " .. dirname)
return false return false
end end
end end
@ -89,16 +89,16 @@ end
-- --
-- @section aliases -- @section aliases
--- Alias of `wconfig.read`. --- Alias of `wdata.read`.
-- --
-- @falias minetest.read_world_config -- @falias minetest.read_world_config
if not core.read_world_config then if not core.read_world_config then
core.read_world_config = wconfig.read core.read_world_config = wdata.read
end end
--- Alias of `wconfig.write`. --- Alias of `wdata.write`.
-- --
-- @falias minetest.write_world_config -- @falias minetest.write_world_config
if not core.write_world_config then if not core.write_world_config then
core.write_world_config = wconfig.write core.write_world_config = wdata.write
end end

@ -3,7 +3,7 @@
<html> <html>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
<head> <head>
<title>World Config</title> <title>World Data Manager</title>
<link rel="stylesheet" href="ldoc.css" type="text/css" /> <link rel="stylesheet" href="ldoc.css" type="text/css" />
</head> </head>
<body> <body>
@ -24,7 +24,7 @@
<div id="navigation"> <div id="navigation">
<br/> <br/>
<h1>wconfig</h1> <h1>wdata</h1>
@ -45,7 +45,7 @@
<div id="content"> <div id="content">
<h1>Module <code>api.lua</code></h1> <h1>Module <code>api.lua</code></h1>
<p>wconfig API</p> <p>World Data Manager API</p>
<p> <p>
</p> </p>
@ -54,11 +54,11 @@
<h2><a href="#Functions">Functions</a></h2> <h2><a href="#Functions">Functions</a></h2>
<table class="function_list"> <table class="function_list">
<tr> <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> <td class="summary">Reads config file from world directory.</td>
</tr> </tr>
<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> <td class="summary">Writes to config file in world directory.</td>
</tr> </tr>
</table> </table>
@ -66,11 +66,11 @@
<table class="function_list"> <table class="function_list">
<tr> <tr>
<td class="name" nowrap><a href="#minetest.read_world_config">minetest.read_world_config</a></td> <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>
<tr> <tr>
<td class="name" nowrap><a href="#minetest.write_world_config">minetest.write_world_config</a></td> <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> </tr>
</table> </table>
@ -82,8 +82,8 @@
<dl class="function"> <dl class="function">
<dt> <dt>
<a name = "wconfig.read"></a> <a name = "wdata.read"></a>
<strong>wconfig.read (fname)</strong> <strong>wdata.read (fname)</strong>
</dt> </dt>
<dd> <dd>
Reads config file from world directory. Reads config file from world directory.
@ -109,8 +109,8 @@
</dd> </dd>
<dt> <dt>
<a name = "wconfig.write"></a> <a name = "wdata.write"></a>
<strong>wconfig.write (fname, data[, styled])</strong> <strong>wdata.write (fname, data[, styled])</strong>
</dt> </dt>
<dd> <dd>
Writes to config file in world directory. Writes to config file in world directory.
@ -153,7 +153,7 @@
<strong>minetest.read_world_config</strong> <strong>minetest.read_world_config</strong>
</dt> </dt>
<dd> <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> <strong>minetest.write_world_config</strong>
</dt> </dt>
<dd> <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="main" -->
<div id="about"> <div id="about">
<i>generated by <a href="http://github.com/stevedonovan/LDoc">LDoc 1.4.6</a></i> <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="about" -->
</div> <!-- id="container" --> </div> <!-- id="container" -->
</body> </body>

@ -1,5 +1,5 @@
project = "wconfig" project = "wdata"
title = "World Config" title = "World Data Manager"
format = "markdown" format = "markdown"
not_luadoc = true not_luadoc = true
boilerplate = false boilerplate = false

@ -1,15 +1,15 @@
wconfig = {} wdata = {}
wconfig.modname = core.get_current_modname() wdata.modname = core.get_current_modname()
wconfig.modpath = core.get_modpath(wconfig.modname) wdata.modpath = core.get_modpath(wdata.modname)
function wconfig.log(lvl, msg) function wdata.log(lvl, msg)
if not msg then if not msg then
msg = lvl msg = lvl
lvl = nil lvl = nil
end end
msg = "[" .. wconfig.modname .. "] " .. msg msg = "[" .. wdata.modname .. "] " .. msg
if not lvl then if not lvl then
core.log(msg) core.log(msg)
else else
@ -18,4 +18,4 @@ function wconfig.log(lvl, msg)
end end
dofile(wconfig.modpath .. "/api.lua") dofile(wdata.modpath .. "/api.lua")

@ -1,6 +1,6 @@
name = wconfig name = wdata
title = World Config title = World Data Manager
description = Bridging world configuration files & mods. description = A library for managing data files in the world directory.
version = 1.0 version = 1.0
license = MIT license = MIT
author = Jordan Irwin (AntumDeluge) author = Jordan Irwin (AntumDeluge)