diff --git a/Resources/monsters/shooty_peeps.xml b/Resources/monsters/shooty_peeps.xml
new file mode 100644
index 0000000..bad62c2
--- /dev/null
+++ b/Resources/monsters/shooty_peeps.xml
@@ -0,0 +1,3 @@
+
+
+
diff --git a/Resources/scenes/debugScene.xml b/Resources/scenes/debugScene.xml
index 39c9326..6b4ac64 100644
--- a/Resources/scenes/debugScene.xml
+++ b/Resources/scenes/debugScene.xml
@@ -3,20 +3,17 @@
-
+
-
+
-
-
-
-
-
+
+
diff --git a/Resources/scripts/ai_scripts.xml b/Resources/scripts/ai_scripts.xml
new file mode 100644
index 0000000..5640721
--- /dev/null
+++ b/Resources/scripts/ai_scripts.xml
@@ -0,0 +1,4 @@
+
+
+
+
diff --git a/Resources/scripts/weapon_scripts.xml b/Resources/scripts/weapon_scripts.xml
new file mode 100644
index 0000000..c090563
--- /dev/null
+++ b/Resources/scripts/weapon_scripts.xml
@@ -0,0 +1,3 @@
+
+
+
diff --git a/Resources/weapons/bubblegun.xml b/Resources/weapons/weapon_def.xml
similarity index 96%
rename from Resources/weapons/bubblegun.xml
rename to Resources/weapons/weapon_def.xml
index e8a8492..b89c0de 100644
--- a/Resources/weapons/bubblegun.xml
+++ b/Resources/weapons/weapon_def.xml
@@ -12,7 +12,7 @@
-
+
diff --git a/YuppleMayham/include/utility/resourcemanager.h b/YuppleMayham/include/utility/resourcemanager.h
index a5af8ac..6f38edc 100644
--- a/YuppleMayham/include/utility/resourcemanager.h
+++ b/YuppleMayham/include/utility/resourcemanager.h
@@ -1,77 +1,90 @@
#ifndef _H_RESOURCEMANAGER_H
#define _H_RESOURCEMANAGER_H
-#include
#include
#include
+#include
-#include "sound/soundeffect.h"
-#include "utility/xmlloader.h"
+#include "graphics/background.h"
#include "graphics/shader.h"
#include "graphics/sprite.h"
-#include "graphics/background.h"
+#include "sound/soundeffect.h"
+#include "utility/script.h"
+#include "utility/xmlloader.h"
#include
class Weapon;
-class Script;
class AnimationSet;
-class AIScript;
-class WeaponScript;
class SpriteComponent;
-class ResourceManager
-{
+class ResourceManager {
public:
- ResourceManager() :
- xmlLoader(std::make_shared())
- {
- xmlLoader->loadWeapons("weapons");
- xmlLoader->loadAnimations("animations");
- xmlLoader->loadTileSets("maps/tilesets");
- xmlLoader->loadMaps("maps");
- xmlLoader->loadScenes("scenes");
- xmlLoader->loadSoundEffects("sounds");
- shaders["__fallback__"] = std::make_unique();
- };
+ ResourceManager() : xmlLoader(std::make_shared()) {
+ xmlLoader->loadWeapons("weapons");
+ xmlLoader->loadAnimations("animations");
+ xmlLoader->loadMonsters("monsters");
+ xmlLoader->loadTileSets("maps/tilesets");
+ xmlLoader->loadMaps("maps");
+ xmlLoader->loadScripts("scripts", loadLuaString);
+ xmlLoader->loadScenes("scenes");
+ xmlLoader->loadSoundEffects("sounds");
+ shaders["__fallback__"] = std::make_unique();
+ };
- // Returns a NON-OWNING pointer to a sprite atlas
- SpriteAtlas* loadSpriteAtlas (const std::string& path, float frameSize, bool isDirectional = false);
- // Returns a NON-OWNING pointer to a static sprite
- Sprite* loadSpriteStatic (const std::string& path);
- // Returns a NON-OWNING pointer to a background
- Background* loadBackground (const std::string& path);
- const unsigned loadSoundEffect (const std::string& id);
- std::unique_ptr loadAIScript (const std::string& path);
- std::unique_ptr loadWeaponScript (const std::string& path);
- std::unique_ptr loadWeapon (const std::string& name, const unsigned weaponShaderID, const unsigned bulletShaderID);
- std::shared_ptr loadAnimationSet (const std::string& name, int entityid = 0);
+ // Returns a NON-OWNING pointer to a sprite atlas
+ SpriteAtlas *loadSpriteAtlas(const std::string &path, float frameSize,
+ bool isDirectional = false);
+ // Returns a NON-OWNING pointer to a static sprite
+ Sprite *loadSpriteStatic(const std::string &path);
+ // Returns a NON-OWNING pointer to a background
+ Background *loadBackground(const std::string &path);
+ const unsigned loadSoundEffect(const std::string &id);
+ template
+ std::unique_ptr loadScript(const std::string &id);
+ std::unique_ptr loadWeapon(const std::string &name,
+ const unsigned weaponShaderID,
+ const unsigned bulletShaderID);
+ std::shared_ptr loadAnimationSet(const std::string &name,
+ int entityid = 0);
- const unsigned loadShader (const std::string& name, const std::string& vertexPath, const std::string& fragPath);
- const SceneData* loadScene (const std::string& id);
- const TileSetData* loadTileSet (const std::string& name);
+ const unsigned loadShader(const std::string &name,
+ const std::string &vertexPath,
+ const std::string &fragPath);
+ const SceneData *loadScene(const std::string &id);
+ const TileSetData *loadTileSet(const std::string &name);
- // Returns a NON-OWNING pointer to a shader by ID
- Shader* getShaderByID(unsigned int ID);
+ // Returns a NON-OWNING pointer to a shader by ID
+ Shader *getShaderByID(unsigned int ID);
- void clearResources();
+ void clearResources();
- ~ResourceManager();
+ ~ResourceManager();
private:
- std::unordered_map> shaders;
- std::unordered_map shaderIDs;
- std::unordered_map> sounds;
- std::unordered_map> sprites;
- //std::unordered_map> weapons;
- //std::unordered_map scripts;
- std::unordered_map> backgrounds;
- std::unordered_map> tileSets;
- //std::unordered_map> entityData;
- //std::unordered_map> scenes;
- //std::unordered_map> maps;
- //std::unordered_map> tiles;
+ std::unordered_map> shaders;
+ std::unordered_map shaderIDs;
+ std::unordered_map> sounds;
+ std::unordered_map> sprites;
+ std::unordered_map> backgrounds;
+ std::unordered_map> tileSets;
- std::shared_ptr xmlLoader;
+ std::shared_ptr xmlLoader;
+
+ static bool loadLuaString(ScriptData *script);
};
+template
+std::unique_ptr ResourceManager::loadScript(const std::string &id) {
+ const ScriptData *data = xmlLoader->getScriptData(id);
+ if (data == nullptr)
+ return nullptr;
+ try {
+ std::unique_ptr script = std::make_unique(data->script);
+ return std::move(script);
+ } catch (std::exception &e) {
+ LOG(ERROR, "Failed to load script '{}'", data->fileName);
+ return nullptr;
+ }
+}
+
#endif // _H_RESOURCEMANAGER_H
diff --git a/YuppleMayham/include/utility/script.h b/YuppleMayham/include/utility/script.h
index 31c25fa..1121332 100644
--- a/YuppleMayham/include/utility/script.h
+++ b/YuppleMayham/include/utility/script.h
@@ -3,45 +3,45 @@
#define SOL_ALL_SAFETIES_ON 1
-#include
#include
#include
+#include
class Script {
public:
- sol::state lua;
- Script(const std::string& path);
- ~Script();
+ sol::state lua;
+ Script(const std::string &str);
+ ~Script();
+
private:
- bool loadScript(const std::string& path) {
- auto result = lua.script_file(path);
- if (!result.valid())
- {
- sol::error err = result;
- std::cerr << "Failed to load script ( " << path << " ) Error: " << err.what() << std::endl;
- }
- return result.valid();
- }
- void registerGlobalUserTypes();
+ bool loadScript(const std::string &str) {
+ auto result = lua.script(str);
+ if (!result.valid()) {
+ sol::error err = result;
+ std::cerr << "Failed to load script. Error: " << err.what() << std::endl;
+ }
+ return result.valid();
+ }
+ void registerGlobalUserTypes();
};
class AIScript : public Script {
public:
- AIScript(const std::string& path) : Script(path) { registerUserTypes(); }
+ AIScript(const std::string &str) : Script(str) { registerUserTypes(); }
- ~AIScript();
+ ~AIScript();
private:
-
- void registerUserTypes() ;
+ void registerUserTypes();
};
class WeaponScript : public Script {
public:
- WeaponScript(const std::string& path) : Script(path) { registerUserTypes(); }
- ~WeaponScript();
+ WeaponScript(const std::string &str) : Script(str) { registerUserTypes(); }
+ ~WeaponScript();
+
private:
- void registerUserTypes() ;
+ void registerUserTypes();
};
#endif // _H_SCRIPT_H
diff --git a/YuppleMayham/include/utility/xmlloader.h b/YuppleMayham/include/utility/xmlloader.h
index 65882bc..f18bd5e 100644
--- a/YuppleMayham/include/utility/xmlloader.h
+++ b/YuppleMayham/include/utility/xmlloader.h
@@ -1,91 +1,103 @@
#ifndef _H_XMLLOADER_H
#define _H_XMLLOADER_H
-#include
-#include
-#include
-#include
+#include
#include
+#include
+#include
+#include
+#include
-#include
-#include
#include
+#include
+#include
#include
struct Tile;
+// Except for the player, these definitions are mostly overrides of the monster
+// data
struct EntityData {
- bool isPlayer;
- bool animated;
- int x = 0, y = 0;
- std::string graphic;
- std::string weapon = "pistol";
- std::string script;
+ bool isPlayer;
+ bool animated;
+ int x = 0, y = 0;
+ float hp;
+ std::string monsterDef;
+ std::string graphic;
+ std::string weapon = "gun/pistol";
+ std::string script;
};
struct MapData {
- std::string name;
- struct TileSet {
- int startID = 1;
- std::string path;
- };
- std::vector tileSets;
- int width = 0, height = 0;
- float tileSize = 32.f;
- // 3D array, 0: layer, 1: y, 2: x
- // Holding tile startID + ids, 0 is an empty tile
- std::vector>> tiles;
+ std::string name;
+ struct TileSet {
+ int startID = 1;
+ std::string path;
+ };
+ std::vector tileSets;
+ int width = 0, height = 0;
+ float tileSize = 32.f;
+ // 3D array, 0: layer, 1: y, 2: x
+ // Holding tile startID + ids, 0 is an empty tile
+ std::vector>> tiles;
};
struct TileSetData {
- std::string name;
- std::string type;
- std::string file;
- int width = 0, height = 0;
- int columns = 0;
- int tileCount = 0;
- float tileSize = 64.f;
- struct TileData {
- int id = 0;
- std::string type;
- bool walkable = true;
- struct ObjectData {
- int id = 0;
- std::string name;
- glm::vec2 pos;
- glm::vec2 size;
- bool collidable = false;
- bool pickup = false;
- };
- std::vector> objects;
- };
- std::vector> tiles;
+ std::string name;
+ std::string type;
+ std::string file;
+ int width = 0, height = 0;
+ int columns = 0;
+ int tileCount = 0;
+ float tileSize = 64.f;
+ struct TileData {
+ int id = 0;
+ std::string type;
+ bool walkable = true;
+ struct ObjectData {
+ int id = 0;
+ std::string name;
+ glm::vec2 pos;
+ glm::vec2 size;
+ bool collidable = false;
+ bool pickup = false;
+ };
+ std::vector> objects;
+ };
+ std::vector> tiles;
};
struct SceneData {
- std::string id;
- std::string type;
- std::string bgFile;
+ std::string id;
+ std::string type;
+ std::string bgFile;
- const MapData* map;
- std::vector entities;
+ const MapData *map;
+ std::vector entities;
+};
+
+// Store our script as a string so we only need to read the file at boot
+struct ScriptData {
+ std::string id;
+ std::string fileName;
+ std::string script;
};
struct WeaponData {
- std::string id;
- float fireSpeed = 250.0f;
- int clipSize = 21;
- int maxAmmo = 512;
- std::string script = "";
- std::string graphic;
- bool animated = false;
- float sizeX = 50.f, sizeY = 50.f;
- float offsetX = 0.f, offsetY = 0.f;
- float bulletSizeX = 50.f, bulletSizeY = 50.f;
- std::string bulletGraphic;
- bool bulletAnimated = false;
- float bulletSpread = 1.0f, bulletSpeed = 3.0f, bulletDrop = 500.f;
- float modMin = 0.5f, modMax = 1.0f;
+ std::string id;
+ float fireSpeed = 250.0f;
+ int clipSize = 21;
+ int maxAmmo = 512;
+ std::string script = "";
+ std::string graphic;
+ bool animated = false;
+ float sizeX = 50.f, sizeY = 50.f;
+ float offsetX = 0.f, offsetY = 0.f;
+ float bulletSizeX = 50.f, bulletSizeY = 50.f;
+ std::string bulletGraphic;
+ bool bulletAnimated = false;
+ float bulletSpread = 1.0f, bulletSpeed = 3.0f, bulletDrop = 500.f;
+ float modMin = 0.5f, modMax = 1.0f;
};
// ID is the new tactic I've decided on.
@@ -94,111 +106,141 @@ struct WeaponData {
// This prefix will be used to look up the animation on
// the animation map
struct AnimationData {
- std::string id;
- std::string spriteAtlas;
- bool directional = false;
- bool oneShot;
- float FPS = 1.f;
- float frameSize;
+ std::string id;
+ std::string spriteAtlas;
+ bool directional = false;
+ bool oneShot;
+ float FPS = 1.f;
+ float frameSize;
+};
+
+// This holds a lot of defaults, but the scene can
+// override a large portion of the definitions here
+struct MonsterData {
+ std::string id;
+ std::string anim;
+ std::string weapon;
+ bool aggressive = false;
+ std::string behaviour;
+ float hp;
};
struct SoundData {
- std::string id; // /