Skip to content

Commit

Permalink
refactor(tesseratos): qof changes
Browse files Browse the repository at this point in the history
  • Loading branch information
Scarface1809 committed Oct 5, 2024
1 parent 0954d7a commit a9ed994
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 2 deletions.
18 changes: 18 additions & 0 deletions engine/include/cubos/engine/voxels/model.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,18 +27,36 @@ namespace cubos::engine
/// @brief Constructs an empty VoxelModel
VoxelModel() = default;

Check warning on line 28 in engine/include/cubos/engine/voxels/model.hpp

View check run for this annotation

Codecov / codecov/patch

engine/include/cubos/engine/voxels/model.hpp#L28

Added line #L28 was not covered by tests

/// @brief Returns the number of grids in the model.
/// @return Number of grids.
std::size_t gridCount() const;

/// @brief Returns the palette of the model.
/// @return Palette of the model.
const VoxelPalette& palette() const;

/// @brief Returns the palette of the model.
/// @return Palette of the model.
VoxelPalette& palette();

/// @brief Returns the grid at the given index.
/// @param index Index of the grid.
/// @return Grid at the given index.
const VoxelGrid& grid(std::size_t index) const;

/// @brief Returns the grid at the given index.
/// @param index Index of the grid.
/// @return Grid at the given index.
VoxelGrid& grid(std::size_t index);

/// @brief Returns the position of the grid at the given index.
/// @param index Index of the grid.
/// @return Position of the grid at the given index.
glm::ivec3 gridPosition(std::size_t index) const;

/// @brief Sets the position of the grid at the given index.
/// @param index Index of the grid.
/// @param position Position to set.
void gridPosition(std::size_t index, glm::ivec3 position);

/// @brief Loads the voxel model data from the given stream.
Expand Down
28 changes: 26 additions & 2 deletions tools/tesseratos/src/tesseratos/importer/plugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -137,12 +137,16 @@ static bool handleImport(Assets& assets, ImportState& state)
return false;
}

assets.writeMeta(state.currentAsset)->set("palette_id", uuids::to_string(paletteHandle.getId()));
assets.writeMeta(state.currentAsset)->set("paletteId", uuids::to_string(paletteHandle.getId()));

for (std::size_t i = 0; i < state.gridCount; ++i)
{
if (gridHandles[i].isNull())
{
continue;
}
assets.writeMeta(state.currentAsset)
->set("grid_id_" + std::to_string(i), uuids::to_string(gridHandles[i].getId()));
->set("grid" + std::to_string(i) + "Id", uuids::to_string(gridHandles[i].getId()));
}

assets.saveMeta(state.currentAsset);
Expand Down Expand Up @@ -197,6 +201,16 @@ static void showImport(Assets& assets, cubos::core::ecs::EventReader<AssetSelect
ImGui::Text("Palette File Path:");
char paletteBuffer[256] = "";
strncpy(paletteBuffer, state.paletteFilePath.c_str(), sizeof(paletteBuffer) - 1);
if (strcmp(paletteBuffer, "") == 0)
{
auto paletteId = assets.readMeta(state.currentAsset)->get("paletteId");
if (paletteId.has_value())
{
AnyAsset paletteHandle{paletteId.value()};
auto palettePath = assets.readMeta(paletteHandle)->get("path");
strncpy(paletteBuffer, palettePath.value().c_str(), sizeof(paletteBuffer) - 1);
}
}
if (ImGui::InputTextWithHint("##paletteFilePath", "Ex:/assets/models/main.pal", paletteBuffer,
sizeof(paletteBuffer)))
{
Expand Down Expand Up @@ -239,6 +253,16 @@ static void showImport(Assets& assets, cubos::core::ecs::EventReader<AssetSelect

std::string& gridPath = state.gridFilePaths[i];
strncpy(inputBuffer, gridPath.c_str(), sizeof(inputBuffer) - 1);
if (strcmp(inputBuffer, "") == 0)
{
auto gridId = assets.readMeta(state.currentAsset)->get("grid" + std::to_string(i) + "Id");
if (gridId.has_value())
{
AnyAsset gridHandle{gridId.value()};
auto gridPath = assets.readMeta(gridHandle)->get("path");
strncpy(inputBuffer, gridPath.value().c_str(), sizeof(inputBuffer) - 1);
}
}
if (ImGui::InputTextWithHint(("##gridFilePath" + std::to_string(i)).c_str(), "Ex:/assets/models/car.grd",
inputBuffer, sizeof(inputBuffer)))
{
Expand Down
1 change: 1 addition & 0 deletions tools/tesseratos/src/tesseratos/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ int main(int argc, char** argv)

cubos.startupSystem("configure Assets plugin").tagged(cubos::engine::settingsTag).call([](Settings& settings) {
settings.setString("assets.io.path", TESSERATOS_ASSETS_FOLDER);
settings.setBool("assets.io.readOnly", false);
});

cubos.startupSystem("load and set the Input Bindings")
Expand Down

0 comments on commit a9ed994

Please sign in to comment.