extension.cpp

main 88 lines · 2.3 KB Raw
Alex Alex Commit Map Editor 18/10/2026 23:40
1//////////////////////////////////////////////////////////////////////
2// This file is part of Remere's Map Editor
3//////////////////////////////////////////////////////////////////////
4// Remere's Map Editor is free software: you can redistribute it and/or modify
5// it under the terms of the GNU General Public License as published by
6// the Free Software Foundation, either version 3 of the License, or
7// (at your option) any later version.
8//
9// Remere's Map Editor is distributed in the hope that it will be useful,
10// but WITHOUT ANY WARRANTY; without even the implied warranty of
11// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12// GNU General Public License for more details.
13//
14// You should have received a copy of the GNU General Public License
15// along with this program. If not, see <http://www.gnu.org/licenses/>.
16//////////////////////////////////////////////////////////////////////
17
18#include "main.h"
19
20#include "extension.h"
21
22MaterialsExtension::MaterialsExtension(std::string name, std::string author, std::string description) :
23 name(name),
24 author(author),
25 description(description),
26 for_all_versions(false) {
27 ////
28}
29
30MaterialsExtension::~MaterialsExtension() {
31 ////
32}
33
34void MaterialsExtension::addVersion(const std::string& versionString) {
35 if (versionString == "all") {
36 for_all_versions = true;
37 } else {
38 ClientVersion* client = ClientVersion::get(versionString);
39 if (client) {
40 ClientVersionList supported_versions = ClientVersion::getAllVersionsSupportedForClientVersion(client);
41 version_list.insert(version_list.end(), supported_versions.begin(), supported_versions.end());
42 }
43 }
44}
45
46bool MaterialsExtension::isForVersion(uint16_t versionId) {
47 if (for_all_versions) {
48 return true;
49 }
50
51 for (ClientVersion* version : version_list) {
52 if (version->getID() == versionId) {
53 return true;
54 }
55 }
56 return false;
57}
58
59std::string MaterialsExtension::getVersionString() {
60 if (for_all_versions) {
61 return "All";
62 }
63
64 std::string versions;
65 std::string last;
66 for (ClientVersion* version : version_list) {
67 if (!last.empty()) {
68 if (!versions.empty()) {
69 versions += ", " + last;
70 } else {
71 versions = last;
72 }
73 }
74 last = version->getName();
75 }
76
77 if (!last.empty()) {
78 if (!versions.empty()) {
79 versions += " and " + last;
80 } else {
81 versions = last;
82 }
83 } else {
84 return "None";
85 }
86 return versions;
87}
88
Top