ImportExport: remove entirely.
This commit is contained in:
parent
1337329efb
commit
9469518a4e
7 changed files with 0 additions and 421 deletions
|
@ -28,7 +28,6 @@
|
||||||
#include "../GameData/Accessories.h"
|
#include "../GameData/Accessories.h"
|
||||||
#define STYLENAMES_DEFINITION
|
#define STYLENAMES_DEFINITION
|
||||||
#include "../GameData/StyleNames.h"
|
#include "../GameData/StyleNames.h"
|
||||||
#include "../ImportExport/Export.h"
|
|
||||||
|
|
||||||
#include "Application.h"
|
#include "Application.h"
|
||||||
|
|
||||||
|
|
|
@ -135,14 +135,6 @@ set(Gvas_SOURCES
|
||||||
Gvas/PropertySerialiser.cpp
|
Gvas/PropertySerialiser.cpp
|
||||||
)
|
)
|
||||||
|
|
||||||
set(ImportExport_SOURCES
|
|
||||||
ImportExport/Import.h
|
|
||||||
ImportExport/Import.cpp
|
|
||||||
ImportExport/Export.h
|
|
||||||
ImportExport/Export.cpp
|
|
||||||
ImportExport/Keys.h
|
|
||||||
)
|
|
||||||
|
|
||||||
if(CORRADE_TARGET_WINDOWS)
|
if(CORRADE_TARGET_WINDOWS)
|
||||||
set(SAVETOOL_RC_FILE resource.rc)
|
set(SAVETOOL_RC_FILE resource.rc)
|
||||||
endif()
|
endif()
|
||||||
|
@ -222,7 +214,6 @@ add_executable(MassBuilderSaveTool
|
||||||
${Logger_SOURCES}
|
${Logger_SOURCES}
|
||||||
${BinaryIo_SOURCES}
|
${BinaryIo_SOURCES}
|
||||||
${Gvas_SOURCES}
|
${Gvas_SOURCES}
|
||||||
${ImportExport_SOURCES}
|
|
||||||
${SAVETOOL_RC_FILE}
|
${SAVETOOL_RC_FILE}
|
||||||
${Assets}
|
${Assets}
|
||||||
)
|
)
|
||||||
|
|
|
@ -1,127 +0,0 @@
|
||||||
// MassBuilderSaveTool
|
|
||||||
// Copyright (C) 2021-2024 Guillaume Jacquemin
|
|
||||||
//
|
|
||||||
// This program is free software: you can redistribute it and/or modify
|
|
||||||
// it under the terms of the GNU General Public License as published by
|
|
||||||
// the Free Software Foundation, either version 3 of the License, or
|
|
||||||
// (at your option) any later version.
|
|
||||||
//
|
|
||||||
// This program is distributed in the hope that it will be useful,
|
|
||||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
// GNU General Public License for more details.
|
|
||||||
//
|
|
||||||
// You should have received a copy of the GNU General Public License
|
|
||||||
// along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
||||||
|
|
||||||
#include <Corrade/Utility/Format.h>
|
|
||||||
#include <Corrade/Utility/Path.h>
|
|
||||||
|
|
||||||
#include "../Logger/Logger.h"
|
|
||||||
#include "../BinaryIo/Writer.h"
|
|
||||||
#include "../Configuration/Configuration.h"
|
|
||||||
#include "../Utilities/Crc32.h"
|
|
||||||
|
|
||||||
#include "Keys.h"
|
|
||||||
|
|
||||||
#include "Export.h"
|
|
||||||
|
|
||||||
namespace mbst::ImportExport {
|
|
||||||
|
|
||||||
static Containers::String last_export_error;
|
|
||||||
|
|
||||||
Containers::StringView
|
|
||||||
lastExportError() {
|
|
||||||
return last_export_error;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool
|
|
||||||
exportStyle(Containers::StringView mass_name, mbst::GameObjects::CustomStyle& style) {
|
|
||||||
Containers::String style_type_str;
|
|
||||||
switch(style.type) {
|
|
||||||
case GameObjects::CustomStyle::Type::Unknown:
|
|
||||||
style_type_str = "Style";
|
|
||||||
break;
|
|
||||||
case GameObjects::CustomStyle::Type::Frame:
|
|
||||||
style_type_str = "FrameStyle";
|
|
||||||
break;
|
|
||||||
case GameObjects::CustomStyle::Type::Armour:
|
|
||||||
style_type_str = "ArmourStyle";
|
|
||||||
break;
|
|
||||||
case GameObjects::CustomStyle::Type::Weapon:
|
|
||||||
style_type_str = "WeaponStyle";
|
|
||||||
break;
|
|
||||||
case GameObjects::CustomStyle::Type::Global:
|
|
||||||
style_type_str = "GlobalStyle";
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
auto filename = Utility::format("{}_{}_{}.style.mbst", mass_name, style_type_str, style.name);
|
|
||||||
for(auto& c : filename) {
|
|
||||||
if(c == ' ') {
|
|
||||||
c = '_';
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
auto path = Utility::Path::join(conf().directories().styles, filename);
|
|
||||||
BinaryIo::Writer writer{path};
|
|
||||||
|
|
||||||
if(!writer.open()) {
|
|
||||||
last_export_error = path + " couldn't be opened.";
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
if(!writer.writeString("MBSTSTYLE")) {
|
|
||||||
LOG_ERROR(last_export_error = "Couldn't write magic bytes into " + filename);
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
writer.writeValueToArray<Keys::CustomStyle>(Keys::CustomStyle::Name);
|
|
||||||
writer.writeUEStringToArray(style.name);
|
|
||||||
|
|
||||||
writer.writeValueToArray<Keys::CustomStyle>(Keys::CustomStyle::Colour);
|
|
||||||
writer.writeValueToArray<Color4>(style.colour);
|
|
||||||
writer.writeValueToArray<Keys::CustomStyle>(Keys::CustomStyle::Metallic);
|
|
||||||
writer.writeValueToArray<float>(style.metallic);
|
|
||||||
writer.writeValueToArray<Keys::CustomStyle>(Keys::CustomStyle::Gloss);
|
|
||||||
writer.writeValueToArray<float>(style.gloss);
|
|
||||||
writer.writeValueToArray<Keys::CustomStyle>(Keys::CustomStyle::Glow);
|
|
||||||
writer.writeValueToArray<bool>(style.glow);
|
|
||||||
|
|
||||||
writer.writeValueToArray<Keys::CustomStyle>(Keys::CustomStyle::PatternId);
|
|
||||||
writer.writeValueToArray<std::int32_t>(style.patternId);
|
|
||||||
writer.writeValueToArray<Keys::CustomStyle>(Keys::CustomStyle::PatternOpacity);
|
|
||||||
writer.writeValueToArray<float>(style.opacity);
|
|
||||||
writer.writeValueToArray<Keys::CustomStyle>(Keys::CustomStyle::PatternOffset);
|
|
||||||
writer.writeValueToArray<Vector2>(style.offset);
|
|
||||||
writer.writeValueToArray<Keys::CustomStyle>(Keys::CustomStyle::PatternRotation);
|
|
||||||
writer.writeValueToArray<float>(style.rotation);
|
|
||||||
writer.writeValueToArray<Keys::CustomStyle>(Keys::CustomStyle::PatternScale);
|
|
||||||
writer.writeValueToArray<float>(style.scale);
|
|
||||||
|
|
||||||
if(!writer.writeUint64(writer.array().size())) {
|
|
||||||
LOG_ERROR(last_export_error = "Couldn't write data size into " + filename);
|
|
||||||
writer.closeFile();
|
|
||||||
Utility::Path::remove(path);
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
auto crc = Utilities::crc32(0, writer.array());
|
|
||||||
if(!writer.writeUint32(crc)) {
|
|
||||||
LOG_ERROR(last_export_error = "Couldn't write CRC32 checksum into " + filename);
|
|
||||||
writer.closeFile();
|
|
||||||
Utility::Path::remove(path);
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
if(!writer.flushToFile()) {
|
|
||||||
LOG_ERROR(last_export_error = "Couldn't write data into " + filename);
|
|
||||||
writer.closeFile();
|
|
||||||
Utility::Path::remove(path);
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
|
@ -1,31 +0,0 @@
|
||||||
#pragma once
|
|
||||||
|
|
||||||
// MassBuilderSaveTool
|
|
||||||
// Copyright (C) 2021-2024 Guillaume Jacquemin
|
|
||||||
//
|
|
||||||
// This program is free software: you can redistribute it and/or modify
|
|
||||||
// it under the terms of the GNU General Public License as published by
|
|
||||||
// the Free Software Foundation, either version 3 of the License, or
|
|
||||||
// (at your option) any later version.
|
|
||||||
//
|
|
||||||
// This program is distributed in the hope that it will be useful,
|
|
||||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
// GNU General Public License for more details.
|
|
||||||
//
|
|
||||||
// You should have received a copy of the GNU General Public License
|
|
||||||
// along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
||||||
|
|
||||||
#include <Corrade/Containers/StringView.h>
|
|
||||||
|
|
||||||
#include "../GameObjects/CustomStyle.h"
|
|
||||||
|
|
||||||
using namespace Corrade;
|
|
||||||
|
|
||||||
namespace mbst::ImportExport {
|
|
||||||
|
|
||||||
auto lastExportError() -> Containers::StringView;
|
|
||||||
|
|
||||||
bool exportStyle(Containers::StringView mass_name, GameObjects::CustomStyle& style);
|
|
||||||
|
|
||||||
}
|
|
|
@ -1,186 +0,0 @@
|
||||||
// MassBuilderSaveTool
|
|
||||||
// Copyright (C) 2021-2024 Guillaume Jacquemin
|
|
||||||
//
|
|
||||||
// This program is free software: you can redistribute it and/or modify
|
|
||||||
// it under the terms of the GNU General Public License as published by
|
|
||||||
// the Free Software Foundation, either version 3 of the License, or
|
|
||||||
// (at your option) any later version.
|
|
||||||
//
|
|
||||||
// This program is distributed in the hope that it will be useful,
|
|
||||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
// GNU General Public License for more details.
|
|
||||||
//
|
|
||||||
// You should have received a copy of the GNU General Public License
|
|
||||||
// along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
||||||
|
|
||||||
#include <cstring>
|
|
||||||
|
|
||||||
#include <Corrade/Containers/Array.h>
|
|
||||||
#include <Corrade/Containers/Optional.h>
|
|
||||||
#include <Corrade/Containers/String.h>
|
|
||||||
#include <Corrade/Utility/Path.h>
|
|
||||||
|
|
||||||
#include "../BinaryIo/Reader.h"
|
|
||||||
#include "../Configuration/Configuration.h"
|
|
||||||
#include "../Logger/Logger.h"
|
|
||||||
#include "../Utilities/Crc32.h"
|
|
||||||
|
|
||||||
#include "Keys.h"
|
|
||||||
|
|
||||||
#include "Import.h"
|
|
||||||
|
|
||||||
namespace mbst::ImportExport {
|
|
||||||
|
|
||||||
static Containers::String last_import_error;
|
|
||||||
|
|
||||||
Containers::StringView
|
|
||||||
lastImportError() {
|
|
||||||
return last_import_error;
|
|
||||||
}
|
|
||||||
|
|
||||||
Containers::Optional<GameObjects::CustomStyle>
|
|
||||||
importStyle(Containers::StringView filename) {
|
|
||||||
auto path = Utility::Path::join(conf().directories().styles, filename);
|
|
||||||
if(!Utility::Path::exists(path)) {
|
|
||||||
LOG_ERROR(last_import_error = path + " doesn't exist.");
|
|
||||||
return Containers::NullOpt;
|
|
||||||
}
|
|
||||||
|
|
||||||
BinaryIo::Reader reader{path};
|
|
||||||
if(!reader.open()) {
|
|
||||||
last_import_error = path + " couldn't be opened.";
|
|
||||||
return Containers::NullOpt;
|
|
||||||
}
|
|
||||||
|
|
||||||
Containers::Array<char> magic_bytes;
|
|
||||||
if(!reader.readArray(magic_bytes, 9)) {
|
|
||||||
LOG_ERROR(last_import_error = "Couldn't read the magic bytes.");
|
|
||||||
return Containers::NullOpt;
|
|
||||||
}
|
|
||||||
|
|
||||||
Containers::StringView magic_bytes_view = magic_bytes;
|
|
||||||
static const auto expected_magic_bytes = "MBSTSTYLE"_s;
|
|
||||||
if(magic_bytes_view != expected_magic_bytes) {
|
|
||||||
LOG_ERROR(last_import_error = "Magic bytes are mismatched.");
|
|
||||||
return Containers::NullOpt;
|
|
||||||
}
|
|
||||||
|
|
||||||
std::size_t data_size;
|
|
||||||
if(!reader.readUint64(data_size)) {
|
|
||||||
LOG_ERROR(last_import_error = "Couldn't read data size.");
|
|
||||||
return Containers::NullOpt;
|
|
||||||
}
|
|
||||||
|
|
||||||
std::uint32_t crc;
|
|
||||||
if(!reader.readUint32(crc)) {
|
|
||||||
LOG_ERROR(last_import_error = "Couldn't read CRC-32 checksum.");
|
|
||||||
return Containers::NullOpt;
|
|
||||||
}
|
|
||||||
|
|
||||||
auto position = reader.position();
|
|
||||||
|
|
||||||
{
|
|
||||||
Containers::Array<char> data;
|
|
||||||
if(!reader.readArray(data, data_size)) {
|
|
||||||
LOG_ERROR(last_import_error = "Couldn't read data.");
|
|
||||||
return Containers::NullOpt;
|
|
||||||
}
|
|
||||||
|
|
||||||
auto computed_crc = Utilities::crc32(0, data);
|
|
||||||
if(computed_crc != crc) {
|
|
||||||
LOG_ERROR(last_import_error = Utility::format("CRC-32 checksum doesn't match. "
|
|
||||||
"Expected {}, got {} instead.",
|
|
||||||
crc, computed_crc));
|
|
||||||
return Containers::NullOpt;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if(!reader.seek(position)) {
|
|
||||||
LOG_ERROR(last_import_error = Utility::format("Couldn't seek to position {}.", position));
|
|
||||||
return Containers::NullOpt;
|
|
||||||
}
|
|
||||||
|
|
||||||
GameObjects::CustomStyle style{};
|
|
||||||
|
|
||||||
while(!reader.eof()) {
|
|
||||||
Keys::CustomStyle key;
|
|
||||||
if(!reader.readValue(key)) {
|
|
||||||
if(reader.eof()) {
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
LOG_ERROR(last_import_error = "Couldn't read key.");
|
|
||||||
return Containers::NullOpt;
|
|
||||||
}
|
|
||||||
|
|
||||||
switch(key) {
|
|
||||||
case Keys::Name:
|
|
||||||
if(!reader.readUEString(style.name)) {
|
|
||||||
LOG_ERROR(last_import_error = "Couldn't read style name.");
|
|
||||||
return Containers::NullOpt;
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
case Keys::Colour:
|
|
||||||
if(!reader.readValue<Color4>(style.colour)) {
|
|
||||||
LOG_ERROR(last_import_error = "Couldn't read style colour.");
|
|
||||||
return Containers::NullOpt;
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
case Keys::Metallic:
|
|
||||||
if(!reader.readFloat(style.metallic)) {
|
|
||||||
LOG_ERROR(last_import_error = "Couldn't read style metallic.");
|
|
||||||
return Containers::NullOpt;
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
case Keys::Gloss:
|
|
||||||
if(!reader.readFloat(style.gloss)) {
|
|
||||||
LOG_ERROR(last_import_error = "Couldn't read style gloss.");
|
|
||||||
return Containers::NullOpt;
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
case Keys::Glow:
|
|
||||||
if(!reader.readValue(style.glow)) {
|
|
||||||
LOG_ERROR(last_import_error = "Couldn't read style glow.");
|
|
||||||
return Containers::NullOpt;
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
case Keys::PatternId:
|
|
||||||
if(!reader.readInt32(style.patternId)) {
|
|
||||||
LOG_ERROR(last_import_error = "Couldn't read style pattern ID.");
|
|
||||||
return Containers::NullOpt;
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
case Keys::PatternOpacity:
|
|
||||||
if(!reader.readFloat(style.opacity)) {
|
|
||||||
LOG_ERROR(last_import_error = "Couldn't read style pattern opacity.");
|
|
||||||
return Containers::NullOpt;
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
case Keys::PatternOffset:
|
|
||||||
if(!reader.readValue(style.offset)) {
|
|
||||||
LOG_ERROR(last_import_error = "Couldn't read style pattern offset.");
|
|
||||||
return Containers::NullOpt;
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
case Keys::PatternRotation:
|
|
||||||
if(!reader.readFloat(style.rotation)) {
|
|
||||||
LOG_ERROR(last_import_error = "Couldn't read style pattern rotation.");
|
|
||||||
return Containers::NullOpt;
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
case Keys::PatternScale:
|
|
||||||
if(!reader.readFloat(style.scale)) {
|
|
||||||
LOG_ERROR(last_import_error = "Couldn't read style pattern scale.");
|
|
||||||
return Containers::NullOpt;
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
LOG_ERROR(last_import_error = Utility::format("Unknown key {}.", key));
|
|
||||||
return Containers::NullOpt;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return Utility::move(style);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
|
@ -1,31 +0,0 @@
|
||||||
#pragma once
|
|
||||||
|
|
||||||
// MassBuilderSaveTool
|
|
||||||
// Copyright (C) 2021-2024 Guillaume Jacquemin
|
|
||||||
//
|
|
||||||
// This program is free software: you can redistribute it and/or modify
|
|
||||||
// it under the terms of the GNU General Public License as published by
|
|
||||||
// the Free Software Foundation, either version 3 of the License, or
|
|
||||||
// (at your option) any later version.
|
|
||||||
//
|
|
||||||
// This program is distributed in the hope that it will be useful,
|
|
||||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
// GNU General Public License for more details.
|
|
||||||
//
|
|
||||||
// You should have received a copy of the GNU General Public License
|
|
||||||
// along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
||||||
|
|
||||||
#include <Corrade/Containers/StringView.h>
|
|
||||||
|
|
||||||
#include "../GameObjects/CustomStyle.h"
|
|
||||||
|
|
||||||
using namespace Corrade;
|
|
||||||
|
|
||||||
namespace mbst::ImportExport {
|
|
||||||
|
|
||||||
auto lastImportError() -> Containers::StringView;
|
|
||||||
|
|
||||||
auto importStyle(Containers::StringView filename) -> Containers::Optional<GameObjects::CustomStyle>;
|
|
||||||
|
|
||||||
}
|
|
|
@ -1,36 +0,0 @@
|
||||||
#pragma once
|
|
||||||
|
|
||||||
// MassBuilderSaveTool
|
|
||||||
// Copyright (C) 2021-2024 Guillaume Jacquemin
|
|
||||||
//
|
|
||||||
// This program is free software: you can redistribute it and/or modify
|
|
||||||
// it under the terms of the GNU General Public License as published by
|
|
||||||
// the Free Software Foundation, either version 3 of the License, or
|
|
||||||
// (at your option) any later version.
|
|
||||||
//
|
|
||||||
// This program is distributed in the hope that it will be useful,
|
|
||||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
// GNU General Public License for more details.
|
|
||||||
//
|
|
||||||
// You should have received a copy of the GNU General Public License
|
|
||||||
// along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
||||||
|
|
||||||
#include <cstdint>
|
|
||||||
|
|
||||||
namespace mbst::ImportExport::Keys {
|
|
||||||
|
|
||||||
enum CustomStyle: std::uint8_t {
|
|
||||||
Name = 0, // type: string
|
|
||||||
Colour = 1, // type: Magnum::Color4
|
|
||||||
Metallic = 2, // type: float
|
|
||||||
Gloss = 3, // type: float
|
|
||||||
Glow = 4, // type: bool
|
|
||||||
PatternId = 5, // type: std::int32_t
|
|
||||||
PatternOpacity = 6, // type: float
|
|
||||||
PatternOffset = 7, // type: Magnum::Vector2
|
|
||||||
PatternRotation = 8, // type: float
|
|
||||||
PatternScale = 9, // type: float
|
|
||||||
};
|
|
||||||
|
|
||||||
}
|
|
Loading…
Reference in a new issue