Serialize and deserialize.
This commit is contained in:
		
					parent
					
						
							
								e762ab05c6
							
						
					
				
			
			
				commit
				
					
						7b6eca1067
					
				
			
		
					 6 changed files with 96 additions and 60 deletions
				
			
		| 
						 | 
				
			
			@ -1,45 +1,25 @@
 | 
			
		|||
#ifndef BILLYSHEET_ADRESSE_HPP
 | 
			
		||||
#define BILLYSHEET_ADRESSE_HPP
 | 
			
		||||
 | 
			
		||||
#include <cstdint>
 | 
			
		||||
#include "characteristic.hpp"
 | 
			
		||||
#include <nlohmann/json.hpp>
 | 
			
		||||
 | 
			
		||||
using json = nlohmann::json;
 | 
			
		||||
 | 
			
		||||
namespace character::characteristic {
 | 
			
		||||
	class Adresse final {
 | 
			
		||||
	private:
 | 
			
		||||
		const std::uint32_t base{ 1 };
 | 
			
		||||
		std::uint32_t carac{ 0 };
 | 
			
		||||
		std::uint32_t materiel{ 0 };
 | 
			
		||||
		std::uint32_t additional{ 0 };
 | 
			
		||||
 | 
			
		||||
	class Adresse final : public Characteristic {
 | 
			
		||||
	public:
 | 
			
		||||
		Adresse() noexcept = default;
 | 
			
		||||
		Adresse() noexcept: Characteristic(1, 0, 0, 0) {}
 | 
			
		||||
 | 
			
		||||
		~Adresse() noexcept = default;
 | 
			
		||||
 | 
			
		||||
		[[nodiscard]] std::uint32_t get_base() const { return base; }
 | 
			
		||||
 | 
			
		||||
		[[nodiscard]] std::uint32_t get_carac() const { return carac; }
 | 
			
		||||
 | 
			
		||||
		[[nodiscard]] std::uint32_t get_materiel() const { return materiel; }
 | 
			
		||||
 | 
			
		||||
		[[nodiscard]] std::uint32_t get_additional() const { return additional; }
 | 
			
		||||
		~Adresse() noexcept final = default;
 | 
			
		||||
 | 
			
		||||
		friend void from_json(const json &j, Adresse &adresse) {
 | 
			
		||||
			const_cast<std::uint32_t&>(adresse.base) = j.at("base");
 | 
			
		||||
			adresse.carac = j.at("carac");
 | 
			
		||||
			adresse.materiel =j.at("materiel");
 | 
			
		||||
			adresse.additional =j.at("additional");
 | 
			
		||||
			nlohmann::from_json(j, static_cast<Characteristic &>(adresse));
 | 
			
		||||
		}
 | 
			
		||||
	};
 | 
			
		||||
 | 
			
		||||
	void to_json(json &j, const Adresse &adresse) {
 | 
			
		||||
		j.emplace("base", adresse.get_base());
 | 
			
		||||
		j.emplace("carac", adresse.get_carac());
 | 
			
		||||
		j.emplace("materiel", adresse.get_materiel());
 | 
			
		||||
		j.emplace("additional", adresse.get_additional());
 | 
			
		||||
		to_json(j, static_cast<Characteristic>(adresse));
 | 
			
		||||
	}
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -1,21 +1,23 @@
 | 
			
		|||
#ifndef BILLYSHEET_CHANCE_HPP
 | 
			
		||||
#define BILLYSHEET_CHANCE_HPP
 | 
			
		||||
 | 
			
		||||
#include <cstdint>
 | 
			
		||||
#include "characteristic.hpp"
 | 
			
		||||
 | 
			
		||||
namespace character::characteristic {
 | 
			
		||||
	class Chance final {
 | 
			
		||||
	private:
 | 
			
		||||
		const std::uint32_t base{ 3 };
 | 
			
		||||
		std::uint32_t carac{ 0 };
 | 
			
		||||
		std::uint32_t materiel{ 0 };
 | 
			
		||||
		std::uint32_t additional{ 0 };
 | 
			
		||||
 | 
			
		||||
	class Chance final : public Characteristic {
 | 
			
		||||
	public:
 | 
			
		||||
		Chance() noexcept = default;
 | 
			
		||||
		Chance() noexcept: Characteristic(3, 0, 0, 0) {}
 | 
			
		||||
 | 
			
		||||
		~Chance() noexcept = default;
 | 
			
		||||
		~Chance() noexcept final = default;
 | 
			
		||||
 | 
			
		||||
		friend void from_json(const json &j, Chance &chance) {
 | 
			
		||||
			nlohmann::from_json(j, static_cast<Characteristic &>(chance));
 | 
			
		||||
		}
 | 
			
		||||
	};
 | 
			
		||||
 | 
			
		||||
	void to_json(json &j, const Chance &chance) {
 | 
			
		||||
		to_json(j, static_cast<Characteristic>(chance));
 | 
			
		||||
	}
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
							
								
								
									
										50
									
								
								include/characteristic/characteristic.hpp
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										50
									
								
								include/characteristic/characteristic.hpp
									
										
									
									
									
										Normal file
									
								
							| 
						 | 
				
			
			@ -0,0 +1,50 @@
 | 
			
		|||
#ifndef BILLYSHEET_CHARACTERISTIC_HPP
 | 
			
		||||
#define BILLYSHEET_CHARACTERISTIC_HPP
 | 
			
		||||
 | 
			
		||||
#include <cstdint>
 | 
			
		||||
#include <nlohmann/json.hpp>
 | 
			
		||||
 | 
			
		||||
using json = nlohmann::json;
 | 
			
		||||
 | 
			
		||||
namespace character::characteristic {
 | 
			
		||||
	class Characteristic {
 | 
			
		||||
	protected:
 | 
			
		||||
		const std::uint32_t base{ 0 };
 | 
			
		||||
		std::uint32_t carac{ 0 };
 | 
			
		||||
		std::uint32_t materiel{ 0 };
 | 
			
		||||
		std::uint32_t additional{ 0 };
 | 
			
		||||
 | 
			
		||||
	public:
 | 
			
		||||
		Characteristic() noexcept = default;
 | 
			
		||||
 | 
			
		||||
		Characteristic(const std::uint32_t base, const std::uint32_t carac, const std::uint32_t materiel, const std::uint32_t additional) :
 | 
			
		||||
				base(base), carac(carac), materiel(materiel), additional(additional) {}
 | 
			
		||||
 | 
			
		||||
		virtual ~Characteristic() noexcept = default;
 | 
			
		||||
 | 
			
		||||
		[[nodiscard]] std::uint32_t get_base() const { return base; }
 | 
			
		||||
 | 
			
		||||
		[[nodiscard]] std::uint32_t get_carac() const { return carac; }
 | 
			
		||||
 | 
			
		||||
		[[nodiscard]] std::uint32_t get_materiel() const { return materiel; }
 | 
			
		||||
 | 
			
		||||
		[[nodiscard]] std::uint32_t get_additional() const { return additional; }
 | 
			
		||||
 | 
			
		||||
		friend void from_json(const json &j, Characteristic &charac) {
 | 
			
		||||
			const_cast<std::uint32_t &>(charac.base) = j.at("base");
 | 
			
		||||
			charac.carac = j.at("carac");
 | 
			
		||||
			charac.materiel = j.at("materiel");
 | 
			
		||||
			charac.additional = j.at("additional");
 | 
			
		||||
		}
 | 
			
		||||
	};
 | 
			
		||||
 | 
			
		||||
	void to_json(json &j, const Characteristic &charac) {
 | 
			
		||||
		j.emplace("base", charac.get_base());
 | 
			
		||||
		j.emplace("carac", charac.get_carac());
 | 
			
		||||
		j.emplace("materiel", charac.get_materiel());
 | 
			
		||||
		j.emplace("additional", charac.get_additional());
 | 
			
		||||
	}
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
#endif //BILLYSHEET_CHARACTERISTIC_HPP
 | 
			
		||||
| 
						 | 
				
			
			@ -1,27 +1,28 @@
 | 
			
		|||
//
 | 
			
		||||
// Created by postaron on 10/01/2022.
 | 
			
		||||
//
 | 
			
		||||
 | 
			
		||||
#ifndef BILLYSHEET_ENDURANCE_HPP
 | 
			
		||||
#define BILLYSHEET_ENDURANCE_HPP
 | 
			
		||||
 | 
			
		||||
#include <cstdint>
 | 
			
		||||
#include "characteristic.hpp"
 | 
			
		||||
#include <nlohmann/json.hpp>
 | 
			
		||||
 | 
			
		||||
using json = nlohmann::json;
 | 
			
		||||
 | 
			
		||||
namespace character::characteristic {
 | 
			
		||||
	class Endurance final {
 | 
			
		||||
	private:
 | 
			
		||||
		const std::uint32_t base{ 2 };
 | 
			
		||||
		std::uint32_t carac{ 0 };
 | 
			
		||||
		std::uint32_t materiel{ 0 };
 | 
			
		||||
		std::uint32_t additional{ 0 };
 | 
			
		||||
 | 
			
		||||
	class Endurance final : public Characteristic {
 | 
			
		||||
	public:
 | 
			
		||||
		Endurance() noexcept = default;
 | 
			
		||||
		Endurance() noexcept: Characteristic(2, 0, 0, 0) {};
 | 
			
		||||
 | 
			
		||||
		~Endurance() noexcept = default;
 | 
			
		||||
		~Endurance() noexcept final = default;
 | 
			
		||||
 | 
			
		||||
		[[nodiscard]] std::uint32_t get_max_lp() const noexcept;
 | 
			
		||||
 | 
			
		||||
		friend void from_json(const json &j, Endurance &endurance) {
 | 
			
		||||
			nlohmann::from_json(j, static_cast<Characteristic &>(endurance));
 | 
			
		||||
		}
 | 
			
		||||
	};
 | 
			
		||||
 | 
			
		||||
	void to_json(json &j, const Endurance &endurance) {
 | 
			
		||||
		to_json(j, static_cast<Characteristic>(endurance));
 | 
			
		||||
	}
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -2,20 +2,23 @@
 | 
			
		|||
#define BILLYSHEET_HABILETE_HPP
 | 
			
		||||
 | 
			
		||||
#include <cstdint>
 | 
			
		||||
#include "characteristic.hpp"
 | 
			
		||||
 | 
			
		||||
namespace character::characteristic {
 | 
			
		||||
	class Habilete final {
 | 
			
		||||
	private:
 | 
			
		||||
		const std::uint32_t base{ 2 };
 | 
			
		||||
		std::uint32_t carac{ 0 };
 | 
			
		||||
		std::uint32_t materiel{ 0 };
 | 
			
		||||
		std::uint32_t additional{ 0 };
 | 
			
		||||
 | 
			
		||||
	class Habilete final : public Characteristic {
 | 
			
		||||
	public:
 | 
			
		||||
		Habilete() noexcept = default;
 | 
			
		||||
		Habilete() noexcept: Characteristic(2, 0, 0, 0) {};
 | 
			
		||||
 | 
			
		||||
		~Habilete() noexcept = default;
 | 
			
		||||
		~Habilete() noexcept final = default;
 | 
			
		||||
 | 
			
		||||
		friend void from_json(const json &j, Habilete &habilete) {
 | 
			
		||||
			nlohmann::from_json(j, static_cast<Characteristic &>(habilete));
 | 
			
		||||
		}
 | 
			
		||||
	};
 | 
			
		||||
 | 
			
		||||
	void to_json(json &j, const Habilete &habilete) {
 | 
			
		||||
		to_json(j, static_cast<Characteristic>(habilete));
 | 
			
		||||
	}
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue