aboutsummaryrefslogtreecommitdiff
path: root/src/item.cc
blob: 6c91206177079fd477152b40e166b3552fad1e48 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
#include "json.hpp"
#include "item.h"
#include "weapon.h"
#include "armor.h"
#include "utils.h"
#include <iostream>
#include <memory>
#include <sstream>

using namespace std;
typedef nlohmann::json json;

namespace entry {
    shared_ptr<Item> Item::create(const json& data) {
        if(data["type"] == "weapon") {
            return utils::loadDFromJson<Item, Weapon>(data);
        } else if(data["type"] == "armor") {
            return utils::loadDFromJson<Item, Armor>(data);
        }
        return shared_ptr<Item>(new Item(data));
    }

    string genText(const Substantial& s) {
        stringstream text;
        text << "Cost: " << s.getCost() << " cp, i.e., " << utils::getCostString(s.getCost());
        text << ". Weight: " << s.getWeight() << " lbs.";
        return text.str();
    }
}