Merge branch 'main' into release-0.25
This commit is contained in:
commit
7d89fb86bd
@ -8,8 +8,17 @@ hud.open_inventory()
|
|||||||
hud.close_inventory()
|
hud.close_inventory()
|
||||||
|
|
||||||
-- Open UI and inventory.
|
-- Open UI and inventory.
|
||||||
-- Throws an exception if has no UI layout.
|
-- Throws an exception if has UI layout does not exists.
|
||||||
hud.open(invid: int, layoutid: str)
|
-- If invid is not specified, a virtual (temporary) inventory is created.
|
||||||
|
-- Returns the invid or id of the virtual inventory.
|
||||||
|
hud.open(
|
||||||
|
-- UI layout name
|
||||||
|
layoutid: str,
|
||||||
|
-- Don't open player inventory
|
||||||
|
[optional] disablePlayerInventory: bool,
|
||||||
|
-- Inventory that UI layout will be bound to
|
||||||
|
[optional] invid: int
|
||||||
|
) -> int
|
||||||
|
|
||||||
-- Open block UI and inventory.
|
-- Open block UI and inventory.
|
||||||
-- Throws an exception if block has no UI layout.
|
-- Throws an exception if block has no UI layout.
|
||||||
|
|||||||
@ -8,8 +8,18 @@ hud.open_inventory()
|
|||||||
hud.close_inventory()
|
hud.close_inventory()
|
||||||
|
|
||||||
-- Открывает инвентарь и UI.
|
-- Открывает инвентарь и UI.
|
||||||
-- Если не имеет макета UI - бросается исключение.
|
-- Если макет UI не существует - бросается исключение.
|
||||||
hud.open(invid: int, layoutid: str)
|
-- Если invid не указан, создаётся виртуальный (временный) инвентарь.
|
||||||
|
-- Возвращает invid или id виртуального инвентаря.
|
||||||
|
hud.open(
|
||||||
|
-- Макет UI
|
||||||
|
layoutid: str,
|
||||||
|
-- Не открывать инвентарь игрока
|
||||||
|
[опционально] disablePlayerInventory: bool,
|
||||||
|
-- Инвентарь, к которому будет привязан UI макет
|
||||||
|
[опционально] invid: int
|
||||||
|
) -> int
|
||||||
|
|
||||||
|
|
||||||
-- Открывает инвентарь и UI блока.
|
-- Открывает инвентарь и UI блока.
|
||||||
-- Если блок не имеет макета UI - бросается исключение.
|
-- Если блок не имеет макета UI - бросается исключение.
|
||||||
|
|||||||
@ -132,14 +132,14 @@ static VoxelStructureMeta load_structure_meta(
|
|||||||
}
|
}
|
||||||
|
|
||||||
static std::vector<std::unique_ptr<VoxelStructure>> load_structures(
|
static std::vector<std::unique_ptr<VoxelStructure>> load_structures(
|
||||||
const fs::path& structuresFile
|
const dv::value& map, const fs::path& filesFolder, const ResPaths& paths
|
||||||
) {
|
) {
|
||||||
auto structuresDir = structuresFile.parent_path() / fs::path("fragments");
|
auto structuresDir = filesFolder / fs::path("fragments");
|
||||||
auto map = files::read_object(structuresFile);
|
|
||||||
|
|
||||||
std::vector<std::unique_ptr<VoxelStructure>> structures;
|
std::vector<std::unique_ptr<VoxelStructure>> structures;
|
||||||
for (auto& [name, config] : map.asObject()) {
|
for (auto& [name, config] : map.asObject()) {
|
||||||
auto structFile = structuresDir / fs::u8path(name + ".vox");
|
auto structFile = structuresDir / fs::u8path(name + ".vox");
|
||||||
|
structFile = paths.find(structFile.u8string());
|
||||||
logger.debug() << "loading voxel fragment " << structFile.u8string();
|
logger.debug() << "loading voxel fragment " << structFile.u8string();
|
||||||
if (!fs::exists(structFile)) {
|
if (!fs::exists(structFile)) {
|
||||||
throw std::runtime_error("structure file does not exist (" +
|
throw std::runtime_error("structure file does not exist (" +
|
||||||
@ -159,8 +159,13 @@ static std::vector<std::unique_ptr<VoxelStructure>> load_structures(
|
|||||||
return structures;
|
return structures;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void load_structures(GeneratorDef& def, const fs::path& structuresFile) {
|
static void load_structures(
|
||||||
auto rawStructures = load_structures(structuresFile);
|
GeneratorDef& def,
|
||||||
|
const dv::value& map,
|
||||||
|
const fs::path& filesFolder,
|
||||||
|
const ResPaths& paths
|
||||||
|
) {
|
||||||
|
auto rawStructures = load_structures(map, filesFolder, paths);
|
||||||
def.structures.resize(rawStructures.size());
|
def.structures.resize(rawStructures.size());
|
||||||
|
|
||||||
for (int i = 0; i < rawStructures.size(); i++) {
|
for (int i = 0; i < rawStructures.size(); i++) {
|
||||||
@ -231,10 +236,9 @@ void ContentLoader::loadGenerator(
|
|||||||
auto folder = generatorsDir / fs::u8path(name + ".files");
|
auto folder = generatorsDir / fs::u8path(name + ".files");
|
||||||
auto scriptFile = folder / fs::u8path("script.lua");
|
auto scriptFile = folder / fs::u8path("script.lua");
|
||||||
|
|
||||||
auto structuresFile = folder / STRUCTURES_FILE;
|
auto structuresFile = GENERATORS_DIR / fs::u8path(name + ".files") / STRUCTURES_FILE;
|
||||||
if (fs::exists(structuresFile)) {
|
auto structuresMap = paths.readCombinedObject(structuresFile.u8string());
|
||||||
load_structures(def, structuresFile);
|
load_structures(def, structuresMap, structuresFile.parent_path(), paths);
|
||||||
}
|
|
||||||
|
|
||||||
auto biomesFile = GENERATORS_DIR / fs::u8path(name + ".files") / BIOMES_FILE;
|
auto biomesFile = GENERATORS_DIR / fs::u8path(name + ".files") / BIOMES_FILE;
|
||||||
auto biomesMap = paths.readCombinedObject(biomesFile.u8string());
|
auto biomesMap = paths.readCombinedObject(biomesFile.u8string());
|
||||||
|
|||||||
@ -382,16 +382,11 @@ void Hud::openInventory() {
|
|||||||
add(HudElement(hud_element_mode::inventory_bound, nullptr, exchangeSlot, false));
|
add(HudElement(hud_element_mode::inventory_bound, nullptr, exchangeSlot, false));
|
||||||
}
|
}
|
||||||
|
|
||||||
void Hud::openInventory(
|
std::shared_ptr<Inventory> Hud::openInventory(
|
||||||
UiDocument* doc,
|
UiDocument* doc,
|
||||||
std::shared_ptr<Inventory> inv,
|
std::shared_ptr<Inventory> inv,
|
||||||
bool playerInventory
|
bool playerInventory
|
||||||
) {
|
) {
|
||||||
if (inv == nullptr) {
|
|
||||||
// why try to open nox-existent inventory??
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (isInventoryOpen()) {
|
if (isInventoryOpen()) {
|
||||||
closeInventory();
|
closeInventory();
|
||||||
}
|
}
|
||||||
@ -413,6 +408,7 @@ void Hud::openInventory(
|
|||||||
}
|
}
|
||||||
secondInvView->bind(inv, content);
|
secondInvView->bind(inv, content);
|
||||||
add(HudElement(hud_element_mode::inventory_bound, doc, secondUI, false));
|
add(HudElement(hud_element_mode::inventory_bound, doc, secondUI, false));
|
||||||
|
return inv;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Hud::openInventory(
|
void Hud::openInventory(
|
||||||
|
|||||||
@ -153,7 +153,7 @@ public:
|
|||||||
/// @param doc ui layout
|
/// @param doc ui layout
|
||||||
/// @param inv inventory
|
/// @param inv inventory
|
||||||
/// @param playerInventory show player inventory too
|
/// @param playerInventory show player inventory too
|
||||||
void openInventory(
|
std::shared_ptr<Inventory> openInventory(
|
||||||
UiDocument* doc,
|
UiDocument* doc,
|
||||||
std::shared_ptr<Inventory> inv,
|
std::shared_ptr<Inventory> inv,
|
||||||
bool playerInventory
|
bool playerInventory
|
||||||
|
|||||||
@ -37,23 +37,20 @@ static int l_close_inventory(lua::State*) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
static int l_open(lua::State* L) {
|
static int l_open(lua::State* L) {
|
||||||
auto invid = lua::tointeger(L, 1);
|
auto layoutid = lua::require_string(L, 1);
|
||||||
auto layoutid = lua::require_string(L, 2);
|
bool playerInventory = !lua::toboolean(L, 2);
|
||||||
bool playerInventory = !lua::toboolean(L, 3);
|
auto invid = lua::tointeger(L, 3);
|
||||||
|
|
||||||
auto assets = engine->getAssets();
|
auto assets = engine->getAssets();
|
||||||
auto layout = assets->get<UiDocument>(layoutid);
|
auto layout = assets->get<UiDocument>(layoutid);
|
||||||
if (layout == nullptr) {
|
if (layout == nullptr) {
|
||||||
throw std::runtime_error("there is no ui layout " + util::quote(layoutid));
|
throw std::runtime_error("there is no ui layout " + util::quote(layoutid));
|
||||||
}
|
}
|
||||||
|
return lua::pushinteger(L, hud->openInventory(
|
||||||
hud->openInventory(
|
|
||||||
layout,
|
layout,
|
||||||
level->inventories->get(invid),
|
level->inventories->get(invid),
|
||||||
playerInventory
|
playerInventory
|
||||||
);
|
)->getId());
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static int l_open_block(lua::State* L) {
|
static int l_open_block(lua::State* L) {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user