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)
|
||||
|
||||
Reference in New Issue
Block a user