starting playing the wherigo
Signed-off-by: Peter Siegmund <mars3142@noreply.mars3142.dev>
This commit is contained in:
73
main/include/lua/game_engine.h
Normal file
73
main/include/lua/game_engine.h
Normal 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
|
||||
|
||||
43
main/include/lua/media_manager.h
Normal file
43
main/include/lua/media_manager.h
Normal 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
|
||||
|
||||
45
main/include/lua/persistence.h
Normal file
45
main/include/lua/persistence.h
Normal 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
|
||||
|
||||
16
main/include/lua/wherigo.h
Normal file
16
main/include/lua/wherigo.h
Normal 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
|
||||
|
||||
66
main/include/lua/wherigo_completion.h
Normal file
66
main/include/lua/wherigo_completion.h
Normal 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
|
||||
|
||||
16
main/include/lua/zobject.h
Normal file
16
main/include/lua/zobject.h
Normal 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
17
main/include/lua/ztimer.h
Normal 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
|
||||
|
||||
Reference in New Issue
Block a user