static puzzle data!
This commit is contained in:
@@ -1,10 +1,9 @@
|
||||
#include "Log.h"
|
||||
#include "Puzzle.h"
|
||||
#include "bx/string.h"
|
||||
#include "imgui.h"
|
||||
#include "rendering/Rendering.h"
|
||||
|
||||
#include "bx/bx.h"
|
||||
#include "imgui.h"
|
||||
#include <cassert>
|
||||
|
||||
namespace
|
||||
@@ -16,25 +15,43 @@ namespace
|
||||
{1, 0},
|
||||
};
|
||||
|
||||
Generated::StaticPuzzleData* StaticDataInstance = nullptr;
|
||||
Generated::StaticPuzzleData StaticData;
|
||||
} // namespace
|
||||
|
||||
namespace Generated
|
||||
{
|
||||
void Setup(StaticPuzzleData& data)
|
||||
void Setup()
|
||||
{
|
||||
StaticDataInstance = &data;
|
||||
LOG("Setting up static puzzle data");
|
||||
for (int32_t i = 0; i < BX_COUNTOF(data.Cards); ++i)
|
||||
{
|
||||
data.Cards[i].ModelHandle = Game::GameRendering::Get().GetModelHandleFromPath("models/w straight.glb");
|
||||
}
|
||||
LoadStaticPuzzleData();
|
||||
}
|
||||
|
||||
StaticPuzzleData& GetStaticPuzzleData()
|
||||
{
|
||||
assert(StaticDataInstance != nullptr);
|
||||
return *StaticDataInstance;
|
||||
return StaticData;
|
||||
}
|
||||
|
||||
void LoadStaticPuzzleData()
|
||||
{
|
||||
Deserializer ser;
|
||||
ser.Init("game/data/static/puzzle.dat");
|
||||
if (ser.ReadT("SPUZ", StaticData))
|
||||
{
|
||||
LOG("Successfully loaded static puzzle data!");
|
||||
}
|
||||
ser.Finish();
|
||||
}
|
||||
|
||||
void SaveStaticPuzzleData()
|
||||
{
|
||||
auto& data = GetStaticPuzzleData();
|
||||
Serializer ser;
|
||||
ser.Init("game/data/static/puzzle.dat");
|
||||
if (ser.WriteT("SPUZ", GetStaticPuzzleData()))
|
||||
{
|
||||
LOG("Successfully saved static puzzle data!");
|
||||
}
|
||||
ser.Finish();
|
||||
}
|
||||
const StaticPuzzleCard& GetCard(const StaticPuzzleData& data, StaticPuzzleCardHandle H)
|
||||
{
|
||||
@@ -167,6 +184,18 @@ namespace Generated
|
||||
|
||||
namespace Generated
|
||||
{
|
||||
constexpr float UIPuzBoxSize = 26;
|
||||
|
||||
const char* GetShortNodeName(const PuzzleNode& node)
|
||||
{
|
||||
PuzzleElementType::Enum elemMax = PuzzleElementType::None;
|
||||
for (int32_t i = 0; i < BX_COUNTOF(node.PlacedTypes); ++i)
|
||||
{
|
||||
if (node.PlacedTypes[i] > elemMax) elemMax = node.PlacedTypes[i];
|
||||
}
|
||||
return PuzzleElementType::ShortName[elemMax];
|
||||
}
|
||||
|
||||
bool RenderDebugUI(PuzzleData& obj)
|
||||
{
|
||||
bool dataChanged = false;
|
||||
@@ -197,6 +226,47 @@ namespace Generated
|
||||
dataChanged = true;
|
||||
}
|
||||
ImGui::PopID();
|
||||
|
||||
ImVec2 puzCursorStart = ImGui::GetCursorScreenPos();
|
||||
auto& drawList = *ImGui::GetWindowDrawList();
|
||||
|
||||
for (int32_t y = 0; y < obj.HeightTiles; ++y)
|
||||
{
|
||||
for (int32_t x = 0; x < obj.WidthTiles; ++x)
|
||||
{
|
||||
PuzzleNode& node = obj.PlacedNodes[Puzzle::Config::MaxPuzzleSizeTiles * y + x];
|
||||
ImVec2 pos = ImVec2{puzCursorStart.x + x * UIPuzBoxSize + 5, puzCursorStart.y + y * UIPuzBoxSize};
|
||||
ImGui::SetCursorScreenPos(pos);
|
||||
ImGui::Text("%s", GetShortNodeName(node));
|
||||
}
|
||||
}
|
||||
|
||||
for (int32_t y = 0; y <= obj.HeightTiles; ++y)
|
||||
{
|
||||
ImVec2 linePos = {puzCursorStart.x, puzCursorStart.y + y * UIPuzBoxSize};
|
||||
drawList.AddLine(linePos,
|
||||
{linePos.x + obj.WidthTiles * UIPuzBoxSize, linePos.y},
|
||||
y % Puzzle::Config::CardSize == 0 ? 0xFFFFFFFF : 0x11FFFFFF);
|
||||
}
|
||||
for (int32_t x = 0; x <= obj.WidthTiles; ++x)
|
||||
{
|
||||
ImVec2 linePos = {puzCursorStart.x + x * UIPuzBoxSize, puzCursorStart.y};
|
||||
drawList.AddLine(linePos,
|
||||
{linePos.x, linePos.y + obj.HeightTiles * UIPuzBoxSize},
|
||||
x % Puzzle::Config::CardSize == 0 ? 0xFFFFFFFF : 0x11FFFFFF);
|
||||
}
|
||||
|
||||
ImGui::Spacing();
|
||||
ImGui::Spacing();
|
||||
|
||||
if (ImGui::TreeNodeEx("Available Cards", ImGuiTreeNodeFlags_DefaultOpen | ImGuiTreeNodeFlags_Framed))
|
||||
{
|
||||
for (int32_t i = 0; i < obj.AvailableCardCount; ++i)
|
||||
{
|
||||
ImGui::Text("Card");
|
||||
}
|
||||
ImGui::TreePop();
|
||||
}
|
||||
}
|
||||
ImGui::End();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user