loading works!!
This commit is contained in:
@@ -6,6 +6,10 @@
|
||||
#include "Puzzle.h"
|
||||
#include "SDL3/SDL_mouse.h"
|
||||
#include "bgfx/bgfx.h"
|
||||
#include "bx/error.h"
|
||||
#include "bx/file.h"
|
||||
#include "bx/filepath.h"
|
||||
#include "bx/string.h"
|
||||
#include "imgui.h"
|
||||
#include "rendering/Rendering.h"
|
||||
#include <SDL3/SDL.h>
|
||||
@@ -72,6 +76,57 @@ namespace Game
|
||||
|
||||
Generated::Setup(PuzzleData);
|
||||
|
||||
bx::Error err;
|
||||
bx::DirectoryReader dirIter;
|
||||
bx::FileInfo info;
|
||||
bx::FilePath puzzleDirPath{"game/data/puzzles"};
|
||||
uint32_t puzIdx = 0;
|
||||
if (dirIter.open(puzzleDirPath, &err))
|
||||
{
|
||||
while (true)
|
||||
{
|
||||
int32_t readCount = dirIter.read(&info, sizeof(info), &err);
|
||||
if (readCount == 0) break;
|
||||
if (err.isOk())
|
||||
{
|
||||
if (info.type != bx::FileType::File) continue;
|
||||
bx::StringView pathEnd = info.filePath.getExt();
|
||||
if (bx::strCmpI(pathEnd, ".pzl") != 0) continue;
|
||||
if (puzIdx >= BX_COUNTOF(Puzzles))
|
||||
{
|
||||
LOG_WARN("Too many puzzles!");
|
||||
break;
|
||||
}
|
||||
|
||||
bx::FilePath fullPath = puzzleDirPath;
|
||||
fullPath.join(info.filePath);
|
||||
LOG("Loading %s", fullPath.getCPtr());
|
||||
|
||||
Generated::Deserializer ser;
|
||||
ser.Init(fullPath);
|
||||
if (Generated::Load(&Puzzles[puzIdx].Data, 1, ser))
|
||||
{
|
||||
Puzzles[puzIdx].Setup();
|
||||
++puzIdx;
|
||||
}
|
||||
else
|
||||
{
|
||||
LOG_WARN("Failed to load puzzle!");
|
||||
}
|
||||
ser.Finish();
|
||||
}
|
||||
else
|
||||
{
|
||||
LOG_ERROR("Failed parsing file name at %s:\n%s", puzzleDirPath.getCPtr(), err.getMessage());
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
LOG_ERROR("Failed to open puzzle dir at %s:\n%s", puzzleDirPath.getCPtr(), err.getMessage().getCPtr());
|
||||
}
|
||||
|
||||
if (Cubes.Count == 0)
|
||||
{
|
||||
for (uint32_t yy = 0; yy < 11; ++yy)
|
||||
|
||||
@@ -38,7 +38,7 @@ namespace Generated
|
||||
}
|
||||
const StaticPuzzleCard& GetCard(const StaticPuzzleData& data, StaticPuzzleCardHandle H)
|
||||
{
|
||||
// assert(IsValid(H));
|
||||
assert(IsValid(H));
|
||||
return data.Cards[H.Idx];
|
||||
}
|
||||
|
||||
@@ -203,7 +203,7 @@ namespace Generated
|
||||
if (dataChanged)
|
||||
{
|
||||
char path[128]{0};
|
||||
bx::snprintf(path, sizeof(path), "game/data/%s.pzl", obj.PuzzleName);
|
||||
bx::snprintf(path, sizeof(path), "game/data/puzzles/%s.pzl", obj.PuzzleName);
|
||||
Serializer ser;
|
||||
ser.Init(path);
|
||||
if (Save(&obj, 1, ser))
|
||||
@@ -231,4 +231,15 @@ namespace Generated
|
||||
lhs += rhs;
|
||||
return lhs;
|
||||
}
|
||||
PuzPos operator-=(PuzPos lhs, const PuzPos& rhs)
|
||||
{
|
||||
lhs.X -= rhs.X;
|
||||
lhs.Y -= rhs.Y;
|
||||
return lhs;
|
||||
}
|
||||
PuzPos operator-(PuzPos lhs, const PuzPos& rhs)
|
||||
{
|
||||
lhs -= rhs;
|
||||
return lhs;
|
||||
}
|
||||
} // namespace Generated
|
||||
|
||||
BIN
src/game/data/puzzles/hell yea.pzl
LFS
Normal file
BIN
src/game/data/puzzles/hell yea.pzl
LFS
Normal file
Binary file not shown.
BIN
src/game/data/puzzles/test.pzl
LFS
Normal file
BIN
src/game/data/puzzles/test.pzl
LFS
Normal file
Binary file not shown.
Reference in New Issue
Block a user