add 'config' entry point, pack.shared_file(...) & refactor engine_paths.cpp

This commit is contained in:
MihailRis
2024-10-04 22:40:05 +03:00
parent 85bea6f17d
commit 15342c2df2
7 changed files with 102 additions and 42 deletions
+12 -1
View File
@@ -19,7 +19,8 @@ Content pack identifier requirements:
### Content packs data
Settings and other state that supposed to be saved with a world, must be stored in `world:data/pack_id/`. The path should be retrieved by calling a function:
State that supposed to be saved with a world, must be stored in `world:data/pack_id/`. The path should be retrieved by calling a function:
```lua
local path = pack.data_file(PACK_ID, "file_name")
file.write(path, some_data)
@@ -29,3 +30,13 @@ PACK_ID is an existing variable containing current content-pack name.
Directory `world:data/PACK_ID` will be created on call `pack.data_file(...)`.
#### Shared data
Settings and other data that should be accessible from all worlds where the pack is used should be in
`config:pack_id/`. You can use a special function:
```lua
local path = pack.shared_file(PACK_ID, "file_name")
file.write(path, data)
-- writes data to the file config:PACK_ID/file_name
```
+28 -4
View File
@@ -47,14 +47,38 @@ pack.is_installed(packid: str) -> bool
Check if specified pack is installed in the world
```python
```lua
pack.data_file(packid: str, filename: str) -> str
-- and
pack.shared_file(packid: str, filename: str) -> str
```
Returns data file path like `world:data/packid/filename`
and creates missing directories.
Returns the path to the data file
and creates missing directories in the path.
Use this function when saving pack settings or other data to the world.
- The first option returns: `world:data/packid/filename`
- The second option returns: `config:packid/filename`
Examples:
```lua
file.write(pack.data_file(PACK_ID, "example.txt"), text)
```
For a *containermod* pack, write text to `world:data/containermod/example.txt`.
Use this to store in-world data.
```lua
file.write(pack.shared_file(PACK_ID, "example.txt"), text)
```
For a *containermod* pack, write text to `config:containermod/example.txt`
Use this to store shared data for all worlds.
```python
pack.get_folder(packid: str) -> str
```
Returns the path to the folder of the installed content pack.
Example:
```lua