Antkeeper  0.0.1
diet-loader.cpp
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2023 Christopher J. Howard
3  *
4  * This file is part of Antkeeper source code.
5  *
6  * Antkeeper source code is free software: you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation, either version 3 of the License, or
9  * (at your option) any later version.
10  *
11  * Antkeeper source code is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with Antkeeper source code. If not, see <http://www.gnu.org/licenses/>.
18  */
19 
24 #include "game/ant/gene/diet.hpp"
25 #include <engine/math/angles.hpp>
26 #include <engine/math/numbers.hpp>
27 #include <stdexcept>
28 
29 using namespace ::ant;
30 
31 static void deserialize_diet_phene(phene::diet& phene, const json& phene_element, resource_manager* resource_manager)
32 {
33 
34 }
35 
36 template <>
37 gene::diet* resource_loader<gene::diet>::load(resource_manager* resource_manager, PHYSFS_File* file, const std::filesystem::path& path)
38 {
39  // Load JSON data
41 
42  // Validate gene file
43  auto diet_element = data->find("diet");
44  if (diet_element == data->end())
45  throw std::runtime_error("Invalid diet gene.");
46 
47  // Allocate gene
48  gene::diet* diet = new gene::diet();
49 
50  // Deserialize gene
51  gene::deserialize_gene(*diet, &deserialize_diet_phene, *diet_element, resource_manager);
52 
53  // Free JSON data
54  delete data;
55 
56  return diet;
57 }
static T * load(resource_manager *resourceManager, PHYSFS_File *file, const std::filesystem::path &path)
Loads resource data.
Loads resources.
nlohmann::json json
JSON data.
Definition: json.hpp:26
monophenic_gene< phene::diet > diet
Monophenic diet gene.
Definition: gene/diet.hpp:30
void deserialize_gene(monophenic_gene< T > &gene, void(*deserialize_phene)(T &, const json &, resource_manager *), const json &gene_element, resource_manager *resource_manager)
Deserializes a gene.
Definition: gene-loader.hpp:43
Definition: caste.hpp:25