Merge branch 'main' into heightmaps
This commit is contained in:
commit
1eb95705f5
@ -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
|
||||
```
|
||||
|
||||
@ -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
|
||||
|
||||
@ -19,7 +19,9 @@
|
||||
|
||||
### Данные контент-паков
|
||||
|
||||
Настройки, состояние, которое нужно сохранять в мире, должны находиться в `world:data/id_пака/`. Путь следует получать через специальную функцию:
|
||||
#### Данные в мире
|
||||
|
||||
Состояние, которое нужно сохранять в мире, должны находиться в `world:data/id_пака/`. Путь следует получать через специальную функцию:
|
||||
```lua
|
||||
local path = pack.data_file(PACK_ID, "имя_файла")
|
||||
file.write(path, данные)
|
||||
@ -27,4 +29,15 @@ file.write(path, данные)
|
||||
```
|
||||
Здесь PACK_ID является доступной константой, т.е не нужно вписывать имя пака самостоятельно.
|
||||
|
||||
Папка `world:data/PACK_ID` будет создана при вызове `pack.data_file`.
|
||||
Папка `world:data/PACK_ID` будет создана при вызове `pack.data_file`.
|
||||
|
||||
#### Общие данные
|
||||
|
||||
Настройки и иные данные, что должны быть доступны из всех миров, где используется пак, должны находиться в
|
||||
`config:id_пака/`. Можно использовать специальную функцию:
|
||||
|
||||
```lua
|
||||
local path = pack.shared_file(PACK_ID, "имя_файла")
|
||||
file.write(path, данные)
|
||||
-- запишет данные в файл config:PACK_ID/имя_файла
|
||||
```
|
||||
|
||||
@ -44,20 +44,32 @@ pack.is_installed(packid: str) -> bool
|
||||
|
||||
Проверяет наличие установленного пака в мире
|
||||
|
||||
```python
|
||||
```lua
|
||||
pack.data_file(packid: str, filename: str) -> str
|
||||
-- и
|
||||
pack.shared_file(packid: str, filename: str) -> str
|
||||
```
|
||||
|
||||
Возвращает путь к файлу данных по типу: `world:data/packid/filename`
|
||||
Возвращает путь к файлу данных
|
||||
и создает недостающие директории в пути.
|
||||
|
||||
Используйте эту функцию при сохранении настроек пака или иных данных в мире.
|
||||
- Первый вариант возвращает: `world:data/packid/filename`
|
||||
- Второй вариант возвращает: `config:packid/filename`
|
||||
|
||||
Пример:
|
||||
Примеры:
|
||||
```lua
|
||||
file.write(pack.data_file(PACK_ID, "example.txt"), text)
|
||||
```
|
||||
Для пака *containermod* запишет текст в файл `world:data/containermod/example.txt`
|
||||
Для пака *containermod* запишет текст в файл `world:data/containermod/example.txt`.
|
||||
|
||||
Используйте для хранения данных в мире.
|
||||
|
||||
```lua
|
||||
file.write(pack.shared_file(PACK_ID, "example.txt"), text)
|
||||
```
|
||||
Для пака *containermod* запишет текст в файл `config:containermod/example.txt`
|
||||
|
||||
Используйте для хранения данныхm общих для всех миров.
|
||||
|
||||
```python
|
||||
pack.get_folder(packid: str) -> str
|
||||
|
||||
@ -101,6 +101,11 @@ function pack.data_file(packid, name)
|
||||
return "world:data/"..packid.."/"..name
|
||||
end
|
||||
|
||||
function pack.shared_file(packid, name)
|
||||
file.mkdirs("config:"..packid)
|
||||
return "config:"..packid.."/"..name
|
||||
end
|
||||
|
||||
-- events
|
||||
events = {
|
||||
handlers = {}
|
||||
|
||||
@ -14,23 +14,12 @@
|
||||
|
||||
static debug::Logger logger("engine-paths");
|
||||
|
||||
|
||||
/// @brief ENUM for accessing folder and file names
|
||||
enum F_F_NAME {
|
||||
SCREENSHOTS_FOLDER,
|
||||
CONTENT_FOLDER,
|
||||
CONTROLS_FILE,
|
||||
SETTINGS_FILE,
|
||||
|
||||
COUNT
|
||||
};
|
||||
|
||||
/// @brief array for get file or folder name by enum `F_F_NAME`
|
||||
///
|
||||
/// example:
|
||||
/// `std::filesystem::path settings = f_f_names[SETTINGS_FILE];`
|
||||
static std::array<std::string, F_F_NAME::COUNT> f_f_names {
|
||||
"screenshots", "content", "controls.toml", "settings.toml"};
|
||||
static inline auto SCREENSHOTS_FOLDER = std::filesystem::u8path("screenshots");
|
||||
static inline auto CONTENT_FOLDER = std::filesystem::u8path("content");
|
||||
static inline auto WORLDS_FOLDER = std::filesystem::u8path("worlds");
|
||||
static inline auto CONFIG_FOLDER = std::filesystem::u8path("config");
|
||||
static inline auto CONTROLS_FILE = std::filesystem::u8path("controls.toml");
|
||||
static inline auto SETTINGS_FILE = std::filesystem::u8path("settings.toml");
|
||||
|
||||
static std::filesystem::path toCanonic(std::filesystem::path path) {
|
||||
std::stack<std::string> parts;
|
||||
@ -58,8 +47,7 @@ static std::filesystem::path toCanonic(std::filesystem::path path) {
|
||||
}
|
||||
|
||||
void EnginePaths::prepare() {
|
||||
auto contentFolder =
|
||||
userFilesFolder / std::filesystem::path(f_f_names[CONTENT_FOLDER]);
|
||||
auto contentFolder = userFilesFolder / CONTENT_FOLDER;
|
||||
if (!fs::is_directory(contentFolder)) {
|
||||
fs::create_directories(contentFolder);
|
||||
}
|
||||
@ -74,8 +62,7 @@ std::filesystem::path EnginePaths::getResourcesFolder() const {
|
||||
}
|
||||
|
||||
std::filesystem::path EnginePaths::getNewScreenshotFile(const std::string& ext) {
|
||||
auto folder =
|
||||
userFilesFolder / std::filesystem::path(f_f_names[SCREENSHOTS_FOLDER]);
|
||||
auto folder = userFilesFolder / SCREENSHOTS_FOLDER;
|
||||
if (!fs::is_directory(folder)) {
|
||||
fs::create_directory(folder);
|
||||
}
|
||||
@ -100,8 +87,12 @@ std::filesystem::path EnginePaths::getNewScreenshotFile(const std::string& ext)
|
||||
return filename;
|
||||
}
|
||||
|
||||
std::filesystem::path EnginePaths::getWorldsFolder() {
|
||||
return userFilesFolder / std::filesystem::path("worlds");
|
||||
std::filesystem::path EnginePaths::getWorldsFolder() const {
|
||||
return userFilesFolder / WORLDS_FOLDER;
|
||||
}
|
||||
|
||||
std::filesystem::path EnginePaths::getConfigFolder() const {
|
||||
return userFilesFolder / CONFIG_FOLDER;
|
||||
}
|
||||
|
||||
std::filesystem::path EnginePaths::getCurrentWorldFolder() {
|
||||
@ -112,12 +103,12 @@ std::filesystem::path EnginePaths::getWorldFolderByName(const std::string& name)
|
||||
return getWorldsFolder() / std::filesystem::path(name);
|
||||
}
|
||||
|
||||
std::filesystem::path EnginePaths::getControlsFile() {
|
||||
return userFilesFolder / std::filesystem::path(f_f_names[CONTROLS_FILE]);
|
||||
std::filesystem::path EnginePaths::getControlsFile() const {
|
||||
return userFilesFolder / CONTROLS_FILE;
|
||||
}
|
||||
|
||||
std::filesystem::path EnginePaths::getSettingsFile() {
|
||||
return userFilesFolder / std::filesystem::path(f_f_names[SETTINGS_FILE]);
|
||||
std::filesystem::path EnginePaths::getSettingsFile() const {
|
||||
return userFilesFolder / SETTINGS_FILE;
|
||||
}
|
||||
|
||||
std::vector<std::filesystem::path> EnginePaths::scanForWorlds() {
|
||||
@ -190,6 +181,9 @@ std::filesystem::path EnginePaths::resolve(
|
||||
if (prefix == "user") {
|
||||
return userFilesFolder / fs::u8path(filename);
|
||||
}
|
||||
if (prefix == "config") {
|
||||
return getConfigFolder() / fs::u8path(filename);
|
||||
}
|
||||
if (prefix == "world") {
|
||||
return currentWorldFolder / fs::u8path(filename);
|
||||
}
|
||||
|
||||
@ -26,15 +26,16 @@ public:
|
||||
void setResourcesFolder(std::filesystem::path folder);
|
||||
std::filesystem::path getResourcesFolder() const;
|
||||
|
||||
std::filesystem::path getWorldsFolder();
|
||||
std::filesystem::path getWorldFolderByName(const std::string& name);
|
||||
std::filesystem::path getWorldsFolder() const;
|
||||
std::filesystem::path getConfigFolder() const;
|
||||
|
||||
void setCurrentWorldFolder(std::filesystem::path folder);
|
||||
std::filesystem::path getCurrentWorldFolder();
|
||||
|
||||
std::filesystem::path getNewScreenshotFile(const std::string& ext);
|
||||
std::filesystem::path getControlsFile();
|
||||
std::filesystem::path getSettingsFile();
|
||||
std::filesystem::path getControlsFile() const;
|
||||
std::filesystem::path getSettingsFile() const;
|
||||
|
||||
void setContentPacks(std::vector<ContentPack>* contentPacks);
|
||||
|
||||
|
||||
@ -70,7 +70,11 @@ void ModelBatch::draw(const model::Mesh& mesh, const glm::mat4& matrix,
|
||||
const glm::mat3& rotation, glm::vec3 tint,
|
||||
const texture_names_map* varTextures) {
|
||||
glm::vec3 gpos = matrix * glm::vec4(0.0f, 0.0f, 0.0f, 1.0f);
|
||||
light_t light = chunks->getLight(floor(gpos.x), floor(gpos.y), floor(gpos.z));
|
||||
light_t light = chunks->getLight(
|
||||
std::floor(gpos.x),
|
||||
std::floor(std::min(CHUNK_H-1.0f, gpos.y)),
|
||||
std::floor(gpos.z));
|
||||
|
||||
glm::vec4 lights (
|
||||
Lightmap::extract(light, 0) / 15.0f,
|
||||
Lightmap::extract(light, 1) / 15.0f,
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user