*/
unsigned int millis(void);
-namespace std {
+/*namespace std {
template<class T>
constexpr const T& clamp(const T& v, const T& lo, const T& hi) {
return (v > hi) ? hi : ((v > lo) ? v : lo);
}
-}
+}*/
#endif // COMMON_HPP_
static inline Item* getItem(const std::string& s)
{ return &itemList[s]; }
+
+ static bool save(void);
+ static void load(void);
};
#endif // INVENTORY_HPP_
WorldSystem::loader();
+ InventorySystem::load();
+
/////////////////////////////
// //
// actually start the game //
// save
game::briceSave();
+ InventorySystem::save();
WorldSystem::save();
// exit
#include <components.hpp>
#include <engine.hpp>
#include <error.hpp>
+#include <fileio.hpp>
#include <font.hpp>
#include <player.hpp>
#include <render.hpp>
#include <ui.hpp>
#include <forward_list>
+#include <iostream>
+#include <fstream>
#include <unordered_map>
#include <tinyxml2.h>
game::events.emit<UseItemEvent>(mce.position, items[0].item, &attack->second);
}
}
- return true;
+ return false;
}
bool InventorySystem::receive(const MouseReleaseEvent &mre)
return true;
}
+
+bool InventorySystem::save(void)
+{
+ std::ofstream s (game::config::xmlFolder + "inventory.dat");
+
+ // signature?
+ s << "831998\n";
+
+ for (const auto& i : items) {
+ if (i.item != nullptr && i.count > 0)
+ s << std::string(i.item->name) << '\n' << i.count << '\n';
+ }
+
+ // end of list?
+ s.close();
+ return true;
+}
+
+void InventorySystem::load(void)
+{
+ // attempt to load data
+ std::ifstream sf (game::config::xmlFolder + "inventory.dat");
+ if (sf.good()) {
+ sf.close();
+ auto lines = readFileA(game::config::xmlFolder + "inventory.dat");
+
+ // check signature
+ if (std::stoi(lines[0]) != 831998)
+ UserError("Save file signature is invalid... (delete it)");
+
+ for (unsigned int i = 1; i < lines.size(); i += 2) {
+ if (lines[i].size() > 0) {
+ int count = std::stoi(lines[i + 1]);
+ if (count > 0)
+ add(lines[i], count);
+ }
+ }
+ }
+}
}
}
});
- return true;
+ return false;
}
void DialogSystem::update(entityx::EntityManager &en, entityx::EventManager &ev, entityx::TimeDelta dt)
--output;\r
*output = (char)((input | BYTE_MARK) & BYTE_MASK);\r
input >>= 6;\r
- //[[fallthrough]];\r
+ [[fallthrough]];\r
case 3:\r
--output;\r
*output = (char)((input | BYTE_MARK) & BYTE_MASK);\r
input >>= 6;\r
- //[[fallthrough]];\r
+ [[fallthrough]];\r
case 2:\r
--output;\r
*output = (char)((input | BYTE_MARK) & BYTE_MASK);\r
input >>= 6;\r
- //[[fallthrough]];\r
+ [[fallthrough]];\r
case 1:\r
--output;\r
*output = (char)(input | FIRST_BYTE_MARK[*length]);\r
case SDL_KEYUP:
ev.emit<KeyUpEvent>(SDL_KEY);
- if (SDL_KEY == SDLK_ESCAPE)
+ if (SDL_KEY == SDLK_ESCAPE) {
ui::menu::toggle();
-
- if (SDL_KEY == SDLK_h) {
+ } else if (SDL_KEY == SDLK_h) {
quest::toggle();
} else switch (SDL_KEY) {
case SDLK_F3: