Rigs of Rods 2023.09
Soft-body Physics Simulation
All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
Loading...
Searching...
No Matches
SkinFileFormat.cpp
Go to the documentation of this file.
1/*
2 This source file is part of Rigs of Rods
3 Copyright 2005-2012 Pierre-Michel Ricordel
4 Copyright 2007-2012 Thomas Fischer
5 Copyright 2013-2020 Petr Ohlidal
6
7 For more information, see http://www.rigsofrods.org/
8
9 Rigs of Rods is free software: you can redistribute it and/or modify
10 it under the terms of the GNU General Public License version 3, as
11 published by the Free Software Foundation.
12
13 Rigs of Rods is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
17
18 You should have received a copy of the GNU General Public License
19 along with Rigs of Rods. If not, see <http://www.gnu.org/licenses/>.
20*/
21
22#include "SkinFileFormat.h"
23
24#include "Application.h"
25#include "Console.h"
26#include "Utils.h"
27
28#include <OgreEntity.h>
29#include <OgreMaterialManager.h>
30#include <OgrePass.h>
31#include <OgreSubEntity.h>
32#include <OgreTechnique.h>
33
34std::vector<RoR::SkinDocumentPtr> RoR::SkinParser::ParseSkins(Ogre::DataStreamPtr& stream)
35{
36 std::vector<SkinDocumentPtr> result;
37 std::unique_ptr<RoR::SkinDocument> curr_skin;
38 try
39 {
40 while(!stream->eof())
41 {
42 std::string line = SanitizeUtf8String(stream->getLine());
43
44 // Ignore blanks & comments
45 if (!line.length() || line.substr(0, 2) == "//")
46 {
47 continue;
48 }
49
50 if (!curr_skin)
51 {
52 // No current skin -- So first valid data should be skin name
53 Ogre::StringUtil::trim(line);
54 curr_skin = std::unique_ptr<SkinDocument>(new SkinDocument);
55 curr_skin->name = line;
56 stream->skipLine("{");
57 }
58 else
59 {
60 // Already in skin
61 if (line == "}")
62 {
63 result.push_back(std::shared_ptr<SkinDocument>(curr_skin.release())); // Finished
64 }
65 else
66 {
67 RoR::SkinParser::ParseSkinAttribute(line, curr_skin.get());
68 }
69 }
70 }
71
72 if (curr_skin)
73 {
76 fmt::format("Skin '{}' in file '{}' not properly closed with '}}'",
77 curr_skin->name, stream->getName()));
78 result.push_back(std::shared_ptr<SkinDocument>(curr_skin.release())); // Submit anyway
79 }
80 }
81 catch (Ogre::Exception& e)
82 {
85 fmt::format("Error parsing skin file '{}', message: {}",
86 stream->getName(), e.getFullDescription()));
87 }
88 return result;
89}
90
91void RoR::SkinParser::ParseSkinAttribute(const std::string& line, SkinDocument* skin_def) // static
92{
93 Ogre::StringVector params = Ogre::StringUtil::split(line, "\t=,;\n");
94 for (unsigned int i=0; i < params.size(); i++)
95 {
96 Ogre::StringUtil::trim(params[i]);
97 }
98 Ogre::String& attrib = params[0];
99 Ogre::StringUtil::toLowerCase(attrib);
100
101 if (attrib == "replacetexture" && params.size() == 3) { skin_def->replace_textures.insert(std::make_pair(params[1], params[2])); return; }
102 if (attrib == "replacematerial" && params.size() == 3) { skin_def->replace_materials.insert(std::make_pair(params[1], params[2])); return; }
103 if (attrib == "preview" && params.size() >= 2) { skin_def->thumbnail = params[1]; return; }
104 if (attrib == "description" && params.size() >= 2) { skin_def->description = params[1]; return; }
105 if (attrib == "authorname" && params.size() >= 2) { skin_def->author_name = params[1]; return; }
106 if (attrib == "authorid" && params.size() == 2) { skin_def->author_id = PARSEINT(params[1]); return; }
107 if (attrib == "guid" && params.size() >= 2) { skin_def->guid = params[1]; Ogre::StringUtil::trim(skin_def->guid); Ogre::StringUtil::toLowerCase(skin_def->guid); return; }
108 if (attrib == "name" && params.size() >= 2) { skin_def->name = params[1]; Ogre::StringUtil::trim(skin_def->name); return; }
109}
Central state/object manager and communications hub.
#define PARSEINT(x)
Definition Application.h:58
@ CONSOLE_MSGTYPE_ACTOR
Parsing/spawn/simulation messages for actors.
Definition Console.h:63
void putMessage(MessageArea area, MessageType type, std::string const &msg, std::string icon="")
Definition Console.cpp:103
@ CONSOLE_SYSTEM_WARNING
Definition Console.h:53
static void ParseSkinAttribute(const std::string &line, SkinDocument *skin_def)
static std::vector< SkinDocumentPtr > ParseSkins(Ogre::DataStreamPtr &stream)
Console * GetConsole()
std::string SanitizeUtf8String(std::string const &str_in)
Definition Utils.cpp:120
std::map< std::string, std::string > replace_textures
std::string author_name
std::string thumbnail
std::string description
std::map< std::string, std::string > replace_materials