starting playing the wherigo

Signed-off-by: Peter Siegmund <mars3142@noreply.mars3142.dev>
This commit is contained in:
2026-02-13 02:41:12 +01:00
parent 50267e47dc
commit f9c45ca81f
34 changed files with 4055 additions and 84 deletions

43
main/include/app.h Normal file
View File

@@ -0,0 +1,43 @@
#pragma once
#include <cartridge/cartridge.h>
#include <wx/wx.h>
#include <memory>
#include <string>
extern "C" {
struct lua_State;
}
class cApp : public wxApp
{
public:
bool OnInit() override;
int OnExit() override;
bool loadCartridge(const std::string &filePath);
void startGame();
void unloadCartridge();
// Save/Load game state
bool saveGameState(const std::string &saveFilePath);
bool loadGameState(const std::string &saveFilePath);
std::string getAutoSavePath() const;
// Generate completion log (for wherigo.com)
bool generateCompletionLog(const std::string &logFilePath);
std::string getCompletionLogPath() const;
lua_State* getLuaState() const { return m_luaState; }
int getCartridgeRef() const { return m_cartridgeRef; }
cartridge::Cartridge* getCartridge() const { return m_cartridge.get(); }
bool isCartridgeLoaded() const { return m_cartridge != nullptr; }
private:
bool initLuaState();
lua_State* m_luaState = nullptr;
int m_cartridgeRef = -1; // LUA_NOREF
std::unique_ptr<cartridge::Cartridge> m_cartridge;
std::string m_cartridgePath;
};

View File

@@ -1,9 +0,0 @@
#pragma once
#include <wx/wx.h>
class cApp : public wxApp
{
public:
bool OnInit() override;
};

View File

@@ -0,0 +1,73 @@
#ifndef GAME_ENGINE_H
#define GAME_ENGINE_H
#include <wx/wx.h>
#include <wx/timer.h>
#include <wx/event.h>
#include <vector>
#include <memory>
#include <functional>
extern "C" {
struct lua_State;
}
namespace wherigo {
// Custom event for game state changes
class GameStateEvent : public wxEvent {
public:
GameStateEvent(wxEventType eventType = wxEVT_NULL, int id = 0)
: wxEvent(id, eventType) {}
wxEvent* Clone() const override { return new GameStateEvent(*this); }
};
wxDECLARE_EVENT(EVT_GAME_STATE_CHANGED, GameStateEvent);
class GameEngine : public wxEvtHandler {
public:
static GameEngine& getInstance();
void init(lua_State *L, int cartridgeRef);
void shutdown();
void start();
void stop();
void updatePlayerPosition(double lat, double lng, double alt = 0.0);
// Notify listeners that game state has changed
void notifyStateChanged();
lua_State* getLuaState() const { return m_luaState; }
int getCartridgeRef() const { return m_cartridgeRef; }
private:
GameEngine();
~GameEngine();
GameEngine(const GameEngine&) = delete;
GameEngine& operator=(const GameEngine&) = delete;
void onGameTick(wxTimerEvent& event);
void checkTimers();
void checkZones();
lua_State* m_luaState = nullptr;
int m_cartridgeRef = -1;
wxTimer m_gameTimer;
bool m_running = false;
double m_playerLat = 0.0;
double m_playerLng = 0.0;
double m_playerAlt = 0.0;
wxDECLARE_EVENT_TABLE();
};
} // namespace wherigo
#endif // GAME_ENGINE_H

View File

@@ -0,0 +1,43 @@
#ifndef MEDIA_MANAGER_H
#define MEDIA_MANAGER_H
#include <cartridge/cartridge.h>
#include <map>
#include <memory>
#include <string>
#include <vector>
extern "C" {
struct lua_State;
}
namespace wherigo {
class MediaManager {
public:
static MediaManager& getInstance();
void init(lua_State *L, cartridge::Cartridge *cartridge);
// Get media data by ZMedia object name (e.g., "Title Plate 1")
std::vector<uint8_t> getMediaByName(const std::string &name);
// Get media data by index
std::vector<uint8_t> getMediaByIndex(int index);
private:
MediaManager() = default;
void buildMediaIndex(lua_State *L);
lua_State *m_luaState = nullptr;
cartridge::Cartridge *m_cartridge = nullptr;
// Map from media name to cartridge object index
std::map<std::string, int> m_nameToIndex;
};
} // namespace wherigo
#endif // MEDIA_MANAGER_H

View File

@@ -0,0 +1,45 @@
#ifndef LUA_PERSISTENCE_H
#define LUA_PERSISTENCE_H
#include <string>
#include <vector>
extern "C" {
struct lua_State;
}
namespace wherigo {
class LuaPersistence {
public:
// Save current Lua state to file
static bool saveState(lua_State* L, const std::string& filePath);
// Load Lua state from file
static bool loadState(lua_State* L, const std::string& filePath);
// Save specific global variables
static bool saveGlobals(lua_State* L, const std::string& filePath,
const std::vector<std::string>& globals);
// Load specific global variables
static bool loadGlobals(lua_State* L, const std::string& filePath);
private:
// Serialize a Lua value (recursive)
static void serializeValue(lua_State* L, int index, std::string& output, int depth = 0);
// Deserialize from string back to Lua stack
static bool deserializeValue(lua_State* L, const std::string& input, size_t& pos);
// Helper to serialize table
static void serializeTable(lua_State* L, int index, std::string& output, int depth);
// Collect all global variables that should be saved
static std::vector<std::string> getGameGlobals(lua_State* L);
};
} // namespace wherigo
#endif // LUA_PERSISTENCE_H

View File

@@ -0,0 +1,16 @@
#ifndef WHERIGO_LUA_H
#define WHERIGO_LUA_H
extern "C" {
#include <lua.h>
}
namespace wherigo {
int luaopen_Wherigo(lua_State *L);
void resetMediaCounter();
}
#endif // WHERIGO_LUA_H

View File

@@ -0,0 +1,66 @@
#ifndef WHERIGO_COMPLETION_H
#define WHERIGO_COMPLETION_H
#include <string>
#include <vector>
#include <ctime>
extern "C" {
struct lua_State;
}
namespace wherigo {
struct CompletionData {
std::string cartridgeName;
std::string cartridgeGUID;
std::string playerName;
std::string completionCode;
time_t startTime;
time_t endTime;
int duration; // seconds
struct TaskCompletion {
std::string name;
bool completed;
time_t completionTime;
};
std::vector<TaskCompletion> tasks;
struct ItemFound {
std::string name;
time_t foundTime;
};
std::vector<ItemFound> items;
struct ZoneVisited {
std::string name;
time_t visitTime;
};
std::vector<ZoneVisited> zones;
};
class WherigoCompletion {
public:
// Generate completion log from current Lua state
static bool generateCompletionLog(lua_State* L, const std::string& filePath,
const std::string& playerName = "Player");
// Extract completion data from Lua state
static CompletionData extractCompletionData(lua_State* L, const std::string& playerName);
// Generate .gwl XML file
static bool writeGWLFile(const CompletionData& data, const std::string& filePath);
// Generate completion code (hash/signature)
static std::string generateCompletionCode(const CompletionData& data);
private:
static std::string escapeXML(const std::string& str);
static std::string formatTime(time_t t);
};
} // namespace wherigo
#endif // WHERIGO_COMPLETION_H

View File

@@ -0,0 +1,16 @@
#ifndef ZOBJECT_H
#define ZOBJECT_H
extern "C" {
#include <lua.h>
}
namespace wherigo {
int zobject_MoveTo(lua_State *L);
int zobject_Contains(lua_State *L);
}
#endif // ZOBJECT_H

17
main/include/lua/ztimer.h Normal file
View File

@@ -0,0 +1,17 @@
#ifndef ZTIMER_H
#define ZTIMER_H
extern "C" {
#include <lua.h>
}
namespace wherigo {
int ztimer_Start(lua_State *L);
int ztimer_Stop(lua_State *L);
int ztimer_Reset(lua_State *L);
}
#endif // ZTIMER_H

View File

@@ -1,14 +0,0 @@
#pragma once
#include <wx/wx.h>
class cFrame : public wxMDIParentFrame
{
public:
cFrame();
private:
void OnHello(wxCommandEvent& event);
void OnExit(wxCommandEvent& event);
void OnAbout(wxCommandEvent& event);
};

View File

@@ -0,0 +1,40 @@
#pragma once
#include <wx/wx.h>
#include <wx/listbox.h>
#include <wx/notebook.h>
class cGameScreen : public wxFrame
{
public:
cGameScreen(wxWindow *parent);
void refreshUI();
private:
void OnClose(wxCloseEvent& event);
void OnExit(wxCommandEvent& event);
void OnAbout(wxCommandEvent& event);
void OnSaveGame(wxCommandEvent& event);
void OnLoadGame(wxCommandEvent& event);
void OnExportCompletion(wxCommandEvent& event);
void OnGameStateChanged(wxEvent& event);
void OnZoneSelected(wxCommandEvent& event);
void OnTaskSelected(wxCommandEvent& event);
void OnInventorySelected(wxCommandEvent& event);
void OnCharacterSelected(wxCommandEvent& event);
void OnItemSelected(wxCommandEvent& event);
void populateZones();
void populateTasks();
void populateInventory();
void populateCharacters();
void populateItems();
wxNotebook* m_notebook;
wxListBox* m_zoneList;
wxListBox* m_taskList;
wxListBox* m_inventoryList;
wxListBox* m_characterList;
wxListBox* m_itemList;
};

View File

@@ -0,0 +1,33 @@
#pragma once
#include <wx/wx.h>
#include <wx/statbmp.h>
#include <wx/html/htmlwin.h>
class cGameScreen;
class cStartScreen : public wxFrame
{
public:
cStartScreen();
void showCartridgeInfo();
void onGameClosed();
private:
void OnOpenCartridge(wxCommandEvent& event);
void OnStartGame(wxCommandEvent& event);
void OnExit(wxCommandEvent& event);
void OnAbout(wxCommandEvent& event);
wxPanel* m_infoPanel;
wxStaticText* m_cartridgeName;
wxStaticText* m_cartridgeAuthor;
wxHtmlWindow* m_cartridgeDesc;
wxStaticBitmap* m_splashImage;
wxButton* m_openButton;
wxButton* m_startButton;
cGameScreen* m_gameFrame;
bool m_cartridgeLoaded;
};

View File

@@ -0,0 +1,50 @@
#ifndef WHERIGO_DIALOG_H
#define WHERIGO_DIALOG_H
#include <wx/wx.h>
#include <wx/dialog.h>
#include <vector>
#include <string>
#include <functional>
namespace wherigo {
struct DialogEntry {
std::string text;
std::string mediaName;
std::vector<std::string> buttons;
};
class WherigoMessageDialog : public wxDialog {
public:
WherigoMessageDialog(wxWindow *parent, const wxString &text,
const wxString &title = "Wherigo",
const std::vector<wxString> &buttons = {},
const wxString &mediaName = "");
int getSelectedButton() const { return m_selectedButton; }
private:
void onButton(wxCommandEvent &event);
int m_selectedButton = -1;
};
class WherigoDialogRunner {
public:
static WherigoDialogRunner& getInstance();
void showMessageBox(const wxString &text, const wxString &title = "Wherigo",
std::function<void(int)> callback = nullptr);
void showDialog(const std::vector<DialogEntry> &entries,
std::function<void(int)> callback = nullptr);
private:
WherigoDialogRunner() = default;
};
} // namespace wherigo
#endif // WHERIGO_DIALOG_H