git repos / blockattack-game

blame: source/code/ModInfo.cpp

normal view · raw

3affd2d6 Poul Sander 2020-12-27 15:56 1
/*
3affd2d6 Poul Sander 2020-12-27 15:56 2
===========================================================================
3affd2d6 Poul Sander 2020-12-27 15:56 3
blockattack - Block Attack - Rise of the Blocks
3affd2d6 Poul Sander 2020-12-27 15:56 4
Copyright (C) 2005-2020 Poul Sander
3affd2d6 Poul Sander 2020-12-27 15:56 5
3affd2d6 Poul Sander 2020-12-27 15:56 6
This program is free software: you can redistribute it and/or modify
3affd2d6 Poul Sander 2020-12-27 15:56 7
it under the terms of the GNU General Public License as published by
3affd2d6 Poul Sander 2020-12-27 15:56 8
the Free Software Foundation, either version 2 of the License, or
3affd2d6 Poul Sander 2020-12-27 15:56 9
(at your option) any later version.
3affd2d6 Poul Sander 2020-12-27 15:56 10
3affd2d6 Poul Sander 2020-12-27 15:56 11
This program is distributed in the hope that it will be useful,
3affd2d6 Poul Sander 2020-12-27 15:56 12
but WITHOUT ANY WARRANTY; without even the implied warranty of
3affd2d6 Poul Sander 2020-12-27 15:56 13
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
3affd2d6 Poul Sander 2020-12-27 15:56 14
GNU General Public License for more details.
3affd2d6 Poul Sander 2020-12-27 15:56 15
3affd2d6 Poul Sander 2020-12-27 15:56 16
You should have received a copy of the GNU General Public License
3affd2d6 Poul Sander 2020-12-27 15:56 17
along with this program.  If not, see http://www.gnu.org/licenses/
3affd2d6 Poul Sander 2020-12-27 15:56 18
3affd2d6 Poul Sander 2020-12-27 15:56 19
Source information and contacts persons can be found at
3affd2d6 Poul Sander 2020-12-27 15:56 20
http://blockattack.net
3affd2d6 Poul Sander 2020-12-27 15:56 21
===========================================================================
3affd2d6 Poul Sander 2020-12-27 15:56 22
*/
3affd2d6 Poul Sander 2020-12-27 15:56 23
3affd2d6 Poul Sander 2020-12-27 15:56 24
#include "ModInfo.hpp"
3affd2d6 Poul Sander 2020-12-27 15:56 25
#include "sago/SagoMisc.hpp"
3affd2d6 Poul Sander 2020-12-27 15:56 26
#include "rapidjson/document.h"
3affd2d6 Poul Sander 2020-12-27 15:56 27
#include <iostream>
3affd2d6 Poul Sander 2020-12-27 15:56 28
#include <boost/algorithm/string.hpp>
3affd2d6 Poul Sander 2020-12-27 15:56 29
3affd2d6 Poul Sander 2020-12-27 15:56 30
void ModInfo::InitModList(const std::vector<std::string>& modlist) {
3affd2d6 Poul Sander 2020-12-27 15:56 31
	this->mod_list = modlist;
3affd2d6 Poul Sander 2020-12-27 15:56 32
	sprite_filename_list.clear();
3affd2d6 Poul Sander 2020-12-27 15:56 33
	for (const std::string& s : mod_list) {
3affd2d6 Poul Sander 2020-12-27 15:56 34
		std::string filename_info = std::string("modinfo/") + s + ".json";
3affd2d6 Poul Sander 2020-12-27 15:56 35
		if (sago::FileExists(filename_info.c_str())) {
3affd2d6 Poul Sander 2020-12-27 15:56 36
			std::string content = sago::GetFileContent(filename_info.c_str());
3affd2d6 Poul Sander 2020-12-27 15:56 37
			rapidjson::Document document;
3affd2d6 Poul Sander 2020-12-27 15:56 38
			document.Parse(content.c_str());
3affd2d6 Poul Sander 2020-12-27 15:56 39
			if ( !document.IsObject() ) {
3affd2d6 Poul Sander 2020-12-27 15:56 40
				std::cerr << "Failed to parse: " << filename_info << "\n";
3affd2d6 Poul Sander 2020-12-27 15:56 41
				continue;
3affd2d6 Poul Sander 2020-12-27 15:56 42
			}
3affd2d6 Poul Sander 2020-12-27 15:56 43
			const auto& t = document.GetObject().FindMember("sprites");
3affd2d6 Poul Sander 2020-12-27 15:56 44
			if (t != document.MemberEnd() && t->value.IsString()) {
3affd2d6 Poul Sander 2020-12-27 15:56 45
				std::string sprites = t->value.GetString();
3affd2d6 Poul Sander 2020-12-27 15:56 46
				std::vector<std::string> sprites_vector;
3affd2d6 Poul Sander 2020-12-27 15:56 47
				boost::split(sprites_vector, sprites, boost::is_any_of(","));
3affd2d6 Poul Sander 2020-12-27 15:56 48
				sprite_filename_list.insert(sprite_filename_list.end(), sprites_vector.begin(), sprites_vector.end());
3affd2d6 Poul Sander 2020-12-27 15:56 49
			}
3affd2d6 Poul Sander 2020-12-27 15:56 50
		}
3affd2d6 Poul Sander 2020-12-27 15:56 51
	}
3affd2d6 Poul Sander 2020-12-27 15:56 52
}
3affd2d6 Poul Sander 2020-12-27 15:56 53
3affd2d6 Poul Sander 2020-12-27 15:56 54
const std::vector<std::string>& ModInfo::getModList() {
3affd2d6 Poul Sander 2020-12-27 15:56 55
	return this->mod_list;
3affd2d6 Poul Sander 2020-12-27 15:56 56
}
3affd2d6 Poul Sander 2020-12-27 15:56 57
3affd2d6 Poul Sander 2020-12-27 15:56 58
const std::vector<std::string>& ModInfo::getModSpriteFiles() {
3affd2d6 Poul Sander 2020-12-27 15:56 59
	return this->sprite_filename_list;
3affd2d6 Poul Sander 2020-12-27 15:56 60
}
1970-01-01 00:00 61