2022-03-06 09:51:57 +01:00
|
|
|
// MassBuilderSaveTool
|
2023-09-02 18:30:29 +02:00
|
|
|
// Copyright (C) 2021-2023 Guillaume Jacquemin
|
2022-03-06 09:51:57 +01:00
|
|
|
//
|
|
|
|
// 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 <algorithm>
|
|
|
|
|
2022-11-21 18:00:38 +01:00
|
|
|
#include "PropertyNames.h"
|
2022-11-21 18:01:29 +01:00
|
|
|
#include "../Logger/Logger.h"
|
2023-11-29 12:33:26 +01:00
|
|
|
#include "../Gvas/Types/ArrayProperty.h"
|
|
|
|
#include "../Gvas/Types/ByteProperty.h"
|
|
|
|
#include "../Gvas/Types/GenericStructProperty.h"
|
|
|
|
#include "../Gvas/Types/IntProperty.h"
|
|
|
|
#include "../Gvas/Types/StringProperty.h"
|
|
|
|
#include "../Gvas/Types/VectorStructProperty.h"
|
2022-03-06 09:51:57 +01:00
|
|
|
|
|
|
|
#include "Mass.h"
|
|
|
|
|
|
|
|
using namespace Containers::Literals;
|
|
|
|
|
2023-11-29 12:33:26 +01:00
|
|
|
namespace mbst { namespace GameObjects {
|
|
|
|
|
2022-12-03 16:49:39 +01:00
|
|
|
Containers::ArrayView<ArmourPart>
|
|
|
|
Mass::armourParts() {
|
2022-03-06 09:51:57 +01:00
|
|
|
return _armour.parts;
|
|
|
|
}
|
|
|
|
|
2022-12-03 16:49:39 +01:00
|
|
|
void
|
|
|
|
Mass::getArmourParts() {
|
2022-11-21 18:01:29 +01:00
|
|
|
LOG_INFO("Getting armour parts.");
|
|
|
|
|
2023-11-29 12:33:26 +01:00
|
|
|
auto unit_data = _mass->at<Gvas::Types::GenericStructProperty>(MASS_UNIT_DATA);
|
2022-03-06 09:51:57 +01:00
|
|
|
if(!unit_data) {
|
2022-11-21 18:01:29 +01:00
|
|
|
LOG_ERROR_FORMAT("Couldn't find {} in {}.", MASS_UNIT_DATA, _filename);
|
2022-03-06 09:51:57 +01:00
|
|
|
_state = State::Invalid;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2023-11-29 12:33:26 +01:00
|
|
|
auto armour_array = unit_data->at<Gvas::Types::ArrayProperty>(MASS_ARMOUR_PARTS);
|
2022-03-06 09:51:57 +01:00
|
|
|
if(!armour_array) {
|
2022-11-21 18:01:29 +01:00
|
|
|
LOG_ERROR_FORMAT("Couldn't find {} in {}.", MASS_ARMOUR_PARTS, _filename);
|
2022-03-06 09:51:57 +01:00
|
|
|
_state = State::Invalid;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(armour_array->items.size() != _armour.parts.size()) {
|
2022-11-21 18:01:29 +01:00
|
|
|
LOG_ERROR_FORMAT("Armour part arrays are not of the same size. Expected {}, got {} instead.",
|
|
|
|
_armour.parts.size(), armour_array->items.size());
|
2022-03-06 09:51:57 +01:00
|
|
|
_state = State::Invalid;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2022-12-05 11:32:18 +01:00
|
|
|
for(std::uint32_t i = 0; i < armour_array->items.size(); i++) {
|
2023-11-29 12:33:26 +01:00
|
|
|
auto part_prop = armour_array->at<Gvas::Types::GenericStructProperty>(i);
|
2022-03-06 09:51:57 +01:00
|
|
|
auto& part = _armour.parts[i];
|
|
|
|
|
2023-11-29 12:33:26 +01:00
|
|
|
auto& armour_slot = part_prop->at<Gvas::Types::ByteProperty>(MASS_ARMOUR_SLOT)->enumValue;
|
|
|
|
#define c(enumerator, strenum, name) if(armour_slot == (strenum)) { part.slot = ArmourPart::Slot::enumerator; } else
|
2022-03-06 09:51:57 +01:00
|
|
|
#include "../Maps/ArmourSlots.hpp"
|
|
|
|
#undef c
|
|
|
|
{
|
2022-11-21 18:01:29 +01:00
|
|
|
LOG_ERROR_FORMAT("Invalid armour slot enumerator {}.", armour_slot);
|
2022-03-06 09:51:57 +01:00
|
|
|
_state = State::Invalid;
|
2022-11-21 18:01:29 +01:00
|
|
|
return;
|
2022-03-06 09:51:57 +01:00
|
|
|
}
|
|
|
|
|
2023-11-29 12:33:26 +01:00
|
|
|
part.id = part_prop->at<Gvas::Types::IntProperty>(MASS_ARMOUR_ID)->value;
|
2022-03-06 09:51:57 +01:00
|
|
|
|
2023-11-29 12:33:26 +01:00
|
|
|
auto part_styles = part_prop->at<Gvas::Types::ArrayProperty>(MASS_ARMOUR_STYLES);
|
2022-03-06 09:51:57 +01:00
|
|
|
if(!part_styles) {
|
2022-11-21 18:01:29 +01:00
|
|
|
LOG_ERROR_FORMAT("Part styles not found for part number {}.", i);
|
2022-03-06 09:51:57 +01:00
|
|
|
_state = State::Invalid;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(part_styles->items.size() != part.styles.size()) {
|
2022-11-21 18:01:29 +01:00
|
|
|
LOG_ERROR_FORMAT("Armour part style arrays are not of the same size. Expected {}, got {} instead.",
|
|
|
|
part.styles.size(), part_styles->items.size());
|
2022-03-06 09:51:57 +01:00
|
|
|
_state = State::Invalid;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2022-12-05 11:32:18 +01:00
|
|
|
for(std::uint32_t j = 0; j < part_styles->items.size(); j++) {
|
2023-11-29 12:33:26 +01:00
|
|
|
part.styles[j] = part_styles->at<Gvas::Types::IntProperty>(j)->value;
|
2022-03-06 09:51:57 +01:00
|
|
|
}
|
|
|
|
|
2023-11-29 12:33:26 +01:00
|
|
|
auto decals_array = part_prop->at<Gvas::Types::ArrayProperty>(MASS_ARMOUR_DECALS);
|
2022-03-06 09:51:57 +01:00
|
|
|
if(!decals_array) {
|
2022-11-21 18:01:29 +01:00
|
|
|
LOG_ERROR_FORMAT("Part decals not found for part number {}.", i);
|
2022-03-06 09:51:57 +01:00
|
|
|
_state = State::Invalid;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
part.decals = Containers::Array<Decal>{decals_array->items.size()};
|
|
|
|
|
|
|
|
getDecals(part.decals, decals_array);
|
|
|
|
|
2023-11-29 12:33:26 +01:00
|
|
|
auto accs_array = part_prop->at<Gvas::Types::ArrayProperty>(MASS_ARMOUR_ACCESSORIES);
|
2022-03-06 09:51:57 +01:00
|
|
|
if(!accs_array) {
|
2022-11-21 18:01:29 +01:00
|
|
|
LOG_WARNING_FORMAT("Part accessories not found for part number {}.", i);
|
2022-03-06 09:51:57 +01:00
|
|
|
part.accessories = Containers::Array<Accessory>{};
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(part.accessories.size() != accs_array->items.size()) {
|
|
|
|
part.accessories = Containers::Array<Accessory>{accs_array->items.size()};
|
|
|
|
}
|
|
|
|
|
|
|
|
getAccessories(part.accessories, accs_array);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-12-03 16:49:39 +01:00
|
|
|
bool
|
2023-11-29 12:33:26 +01:00
|
|
|
Mass::writeArmourPart(ArmourPart::Slot slot) {
|
2022-11-21 18:01:29 +01:00
|
|
|
LOG_INFO_FORMAT("Writing armour part in slot {}.", static_cast<int>(slot));
|
|
|
|
|
2022-03-06 09:51:57 +01:00
|
|
|
auto& part = *std::find_if(_armour.parts.begin(), _armour.parts.end(), [&slot](const ArmourPart& part){ return slot == part.slot; });
|
|
|
|
|
2023-11-29 12:33:26 +01:00
|
|
|
auto unit_data = _mass->at<Gvas::Types::GenericStructProperty>(MASS_UNIT_DATA);
|
2022-11-21 18:01:29 +01:00
|
|
|
if(!unit_data) {
|
|
|
|
_lastError = "Couldn't find the unit data in " + _filename + ".";
|
|
|
|
LOG_ERROR(_lastError);
|
|
|
|
_state = State::Invalid;
|
|
|
|
return false;
|
|
|
|
}
|
2022-03-06 09:51:57 +01:00
|
|
|
|
2023-11-29 12:33:26 +01:00
|
|
|
auto armour_array = unit_data->at<Gvas::Types::ArrayProperty>(MASS_ARMOUR_PARTS);
|
2022-11-21 18:01:29 +01:00
|
|
|
if(!armour_array) {
|
|
|
|
_lastError = "Couldn't find the armour part array in " + _filename + ".";
|
|
|
|
LOG_ERROR(_lastError);
|
|
|
|
_state = State::Invalid;
|
|
|
|
return false;
|
|
|
|
}
|
2022-03-06 09:51:57 +01:00
|
|
|
|
|
|
|
Containers::StringView slot_str = nullptr;
|
|
|
|
switch(slot) {
|
2023-11-29 12:33:26 +01:00
|
|
|
#define c(enumerator, strenum, name) case ArmourPart::Slot::enumerator: \
|
2022-03-06 09:51:57 +01:00
|
|
|
slot_str = strenum; \
|
|
|
|
break;
|
|
|
|
#include "../Maps/ArmourSlots.hpp"
|
|
|
|
#undef c
|
|
|
|
}
|
|
|
|
|
2023-11-29 12:33:26 +01:00
|
|
|
Gvas::Types::GenericStructProperty* part_prop = nullptr;
|
2022-03-06 09:51:57 +01:00
|
|
|
|
2022-12-05 11:32:18 +01:00
|
|
|
for(std::uint32_t i = 0; i < armour_array->items.size(); i++) {
|
2023-11-29 12:33:26 +01:00
|
|
|
part_prop = armour_array->at<Gvas::Types::GenericStructProperty>(i);
|
|
|
|
if(slot_str == part_prop->at<Gvas::Types::ByteProperty>(MASS_ARMOUR_SLOT)->enumValue) {
|
2022-04-08 12:44:30 +02:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
else {
|
2022-03-06 09:51:57 +01:00
|
|
|
part_prop = nullptr;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if(!part_prop) {
|
|
|
|
auto prefix = "Couldn't find the armour part for slot "_s;
|
|
|
|
switch(slot) {
|
2023-11-29 12:33:26 +01:00
|
|
|
#define c(enumerator, strenum, name) case ArmourPart::Slot::enumerator: \
|
2022-03-06 09:51:57 +01:00
|
|
|
_lastError = prefix + "ArmourSlot::" #enumerator "."_s; \
|
|
|
|
break;
|
|
|
|
#include "../Maps/ArmourSlots.hpp"
|
|
|
|
#undef c
|
|
|
|
}
|
2022-11-21 18:01:29 +01:00
|
|
|
LOG_ERROR(_lastError);
|
2022-03-06 09:51:57 +01:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2023-11-29 12:33:26 +01:00
|
|
|
part_prop->at<Gvas::Types::IntProperty>(MASS_ARMOUR_ID)->value = part.id;
|
2022-03-06 09:51:57 +01:00
|
|
|
|
2023-11-29 12:33:26 +01:00
|
|
|
auto part_styles = part_prop->at<Gvas::Types::ArrayProperty>(MASS_ARMOUR_STYLES);
|
2022-12-05 11:32:18 +01:00
|
|
|
for(std::uint32_t i = 0; i < part.styles.size(); i++) {
|
2023-11-29 12:33:26 +01:00
|
|
|
part_styles->at<Gvas::Types::IntProperty>(i)->value = part.styles[i];
|
2022-03-06 09:51:57 +01:00
|
|
|
}
|
|
|
|
|
2023-11-29 12:33:26 +01:00
|
|
|
auto decals_array = part_prop->at<Gvas::Types::ArrayProperty>(MASS_ARMOUR_DECALS);
|
2022-03-06 09:51:57 +01:00
|
|
|
writeDecals(part.decals, decals_array);
|
|
|
|
|
2023-10-29 11:31:21 +01:00
|
|
|
if(!part.accessories.isEmpty()) {
|
2023-11-29 12:33:26 +01:00
|
|
|
auto accs_array = part_prop->at<Gvas::Types::ArrayProperty>(MASS_ARMOUR_ACCESSORIES);
|
2022-03-06 09:51:57 +01:00
|
|
|
writeAccessories(part.accessories, accs_array);
|
|
|
|
}
|
|
|
|
|
|
|
|
if(!_mass->saveToFile()) {
|
|
|
|
_lastError = _mass->lastError();
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2022-12-03 16:49:39 +01:00
|
|
|
BulletLauncherAttachmentStyle&
|
|
|
|
Mass::bulletLauncherAttachmentStyle() {
|
2022-03-12 09:34:19 +01:00
|
|
|
return _armour.blAttachmentStyle;
|
|
|
|
}
|
|
|
|
|
2022-12-03 16:49:39 +01:00
|
|
|
Containers::ArrayView<BulletLauncherAttachment>
|
|
|
|
Mass::bulletLauncherAttachments() {
|
2022-03-12 09:34:19 +01:00
|
|
|
return _armour.blAttachment;
|
|
|
|
}
|
|
|
|
|
2022-12-03 16:49:39 +01:00
|
|
|
void
|
|
|
|
Mass::getBulletLauncherAttachments() {
|
2022-11-21 18:01:29 +01:00
|
|
|
LOG_INFO("Getting the bullet launcher attachment data.");
|
|
|
|
|
2023-11-29 12:33:26 +01:00
|
|
|
auto unit_data = _mass->at<Gvas::Types::GenericStructProperty>(MASS_UNIT_DATA);
|
2022-03-12 09:34:19 +01:00
|
|
|
if(!unit_data) {
|
2022-11-21 18:01:29 +01:00
|
|
|
LOG_ERROR_FORMAT("Couldn't find {} in {}.", MASS_UNIT_DATA, _filename);
|
2022-03-12 09:34:19 +01:00
|
|
|
_state = State::Invalid;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2023-11-29 12:33:26 +01:00
|
|
|
auto attach_style_prop = unit_data->at<Gvas::Types::ByteProperty>(MASS_BL_ATTACHMENT_STYLE);
|
|
|
|
auto attach_array = unit_data->at<Gvas::Types::ArrayProperty>(MASS_BL_ATTACHMENTS);
|
2022-03-12 09:34:19 +01:00
|
|
|
|
|
|
|
if(!attach_style_prop && !attach_array) {
|
2022-11-21 18:01:29 +01:00
|
|
|
LOG_WARNING_FORMAT("No bullet launcher attachment data found in {}.", _filename);
|
2022-03-12 09:34:19 +01:00
|
|
|
_armour.blAttachmentStyle = BulletLauncherAttachmentStyle::NotFound;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(attach_style_prop && !attach_array) {
|
2022-11-21 18:01:29 +01:00
|
|
|
LOG_WARNING_FORMAT("No bullet launcher attachments found in {}.", _filename);
|
2022-03-12 09:34:19 +01:00
|
|
|
_armour.blAttachmentStyle = BulletLauncherAttachmentStyle::NotFound;
|
|
|
|
_state = State::Invalid;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2022-03-13 15:25:11 +01:00
|
|
|
if(attach_array->items.size() == _weapons.bulletLaunchers.size() &&
|
|
|
|
attach_array->items.size() == _armour.blAttachment.size())
|
2022-03-12 09:34:19 +01:00
|
|
|
{
|
2022-12-05 11:32:18 +01:00
|
|
|
for(std::uint32_t i = 0; i < attach_array->items.size(); i++) {
|
2023-11-29 12:33:26 +01:00
|
|
|
auto attachment_prop = attach_array->at<Gvas::Types::GenericStructProperty>(i);
|
2022-03-12 09:34:19 +01:00
|
|
|
auto& attachment = _armour.blAttachment[i];
|
|
|
|
|
2023-11-29 12:33:26 +01:00
|
|
|
Containers::StringView socket = attachment_prop->at<Gvas::Types::StringProperty>(MASS_BL_ATTACHMENT_SOCKET)->value;
|
|
|
|
#define c(enumerator, strenum, name) if(socket == (strenum)) { attachment.socket = BulletLauncherAttachment::Socket::enumerator; } else
|
2022-03-12 09:34:19 +01:00
|
|
|
#include "../Maps/BulletLauncherSockets.hpp"
|
|
|
|
#undef c
|
|
|
|
{
|
2022-11-21 18:01:29 +01:00
|
|
|
LOG_ERROR_FORMAT("Invalid attachment socket {}.", socket);
|
2022-03-12 09:34:19 +01:00
|
|
|
_state = State::Invalid;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2023-11-29 12:33:26 +01:00
|
|
|
auto rel_loc_prop = attachment_prop->at<Gvas::Types::VectorStructProperty>(MASS_BL_ATTACHMENT_RELLOC);
|
2022-03-12 09:34:19 +01:00
|
|
|
attachment.relativeLocation = Vector3{rel_loc_prop->x, rel_loc_prop->y, rel_loc_prop->z};
|
2023-11-29 12:33:26 +01:00
|
|
|
auto off_loc_prop = attachment_prop->at<Gvas::Types::VectorStructProperty>(MASS_BL_ATTACHMENT_OFFLOC);
|
2022-03-12 09:34:19 +01:00
|
|
|
attachment.offsetLocation = Vector3{off_loc_prop->x, off_loc_prop->y, off_loc_prop->z};
|
2023-11-29 12:33:26 +01:00
|
|
|
auto rel_rot_prop = attachment_prop->at<Gvas::Types::VectorStructProperty>(MASS_BL_ATTACHMENT_RELROT);
|
2022-03-12 09:34:19 +01:00
|
|
|
attachment.relativeRotation = Vector3{rel_rot_prop->x, rel_rot_prop->y, rel_rot_prop->z};
|
2023-11-29 12:33:26 +01:00
|
|
|
auto off_rot_prop = attachment_prop->at<Gvas::Types::VectorStructProperty>(MASS_BL_ATTACHMENT_OFFROT);
|
2022-03-12 09:34:19 +01:00
|
|
|
attachment.offsetRotation = Vector3{off_rot_prop->x, off_rot_prop->y, off_rot_prop->z};
|
2023-11-29 12:33:26 +01:00
|
|
|
auto rel_scale_prop = attachment_prop->at<Gvas::Types::VectorStructProperty>(MASS_BL_ATTACHMENT_RELSCALE);
|
2022-03-12 09:34:19 +01:00
|
|
|
attachment.relativeScale = Vector3{rel_scale_prop->x, rel_scale_prop->y, rel_scale_prop->z};
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if(attach_style_prop) {
|
|
|
|
Containers::StringView attach_style = attach_style_prop->enumValue;
|
|
|
|
#define c(enumerator, strenum) if(attach_style == (strenum)) { _armour.blAttachmentStyle = BulletLauncherAttachmentStyle::enumerator; } else
|
|
|
|
#include "../Maps/BulletLauncherAttachmentStyles.hpp"
|
|
|
|
#undef c
|
|
|
|
{
|
2022-11-21 18:01:29 +01:00
|
|
|
LOG_ERROR_FORMAT("Invalid attachment style {}.", attach_style);
|
|
|
|
_state = State::Invalid;
|
2022-03-12 09:34:19 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
_armour.blAttachmentStyle = BulletLauncherAttachmentStyle::ActiveOne;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-12-03 16:49:39 +01:00
|
|
|
bool
|
|
|
|
Mass::writeBulletLauncherAttachments() {
|
2022-11-21 18:01:29 +01:00
|
|
|
LOG_INFO("Writing bullet launcher attachments.");
|
|
|
|
|
2023-11-29 12:33:26 +01:00
|
|
|
auto unit_data = _mass->at<Gvas::Types::GenericStructProperty>(MASS_UNIT_DATA);
|
2022-03-20 09:47:56 +01:00
|
|
|
if(!unit_data) {
|
|
|
|
_lastError = "No unit data in " + _filename;
|
2022-11-21 18:01:29 +01:00
|
|
|
LOG_ERROR(_lastError);
|
|
|
|
_state = State::Invalid;
|
2022-03-20 09:47:56 +01:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2023-11-29 12:33:26 +01:00
|
|
|
auto attach_style_prop = unit_data->at<Gvas::Types::ByteProperty>(MASS_BL_ATTACHMENT_STYLE);
|
|
|
|
auto attach_array = unit_data->at<Gvas::Types::ArrayProperty>(MASS_BL_ATTACHMENTS);
|
2022-03-20 09:47:56 +01:00
|
|
|
|
|
|
|
if(!attach_style_prop && !attach_array) {
|
|
|
|
_lastError = "No attachment properties to write to in " + _filename;
|
2022-11-21 18:01:29 +01:00
|
|
|
LOG_ERROR(_lastError);
|
|
|
|
_armour.blAttachmentStyle = BulletLauncherAttachmentStyle::NotFound;
|
2022-03-20 09:47:56 +01:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(attach_style_prop && !attach_array) {
|
2022-11-21 18:01:29 +01:00
|
|
|
_lastError = "Couldn't find the attachments in " + _filename;
|
|
|
|
LOG_ERROR(_lastError);
|
2022-03-20 09:47:56 +01:00
|
|
|
_armour.blAttachmentStyle = BulletLauncherAttachmentStyle::NotFound;
|
|
|
|
_state = State::Invalid;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(attach_array->items.size() == _weapons.bulletLaunchers.size() &&
|
|
|
|
attach_array->items.size() == _armour.blAttachment.size())
|
|
|
|
{
|
2022-12-05 11:32:18 +01:00
|
|
|
for(std::uint32_t i = 0; i < attach_array->items.size(); i++) {
|
2023-11-29 12:33:26 +01:00
|
|
|
auto attachment_prop = attach_array->at<Gvas::Types::GenericStructProperty>(i);
|
2022-03-20 09:47:56 +01:00
|
|
|
auto& attachment = _armour.blAttachment[i];
|
|
|
|
|
2023-11-29 12:33:26 +01:00
|
|
|
auto& socket = attachment_prop->at<Gvas::Types::StringProperty>(MASS_BL_ATTACHMENT_SOCKET)->value;
|
2022-03-20 09:47:56 +01:00
|
|
|
switch(attachment.socket) {
|
2023-11-29 12:33:26 +01:00
|
|
|
#define c(enumerator, strenum, name) case BulletLauncherAttachment::Socket::enumerator: socket = strenum; break;
|
2022-03-20 09:47:56 +01:00
|
|
|
#include "../Maps/BulletLauncherSockets.hpp"
|
|
|
|
#undef c
|
|
|
|
default:
|
|
|
|
_lastError = "Invalid socket type."_s;
|
2022-11-21 18:01:29 +01:00
|
|
|
LOG_ERROR(_lastError);
|
2022-03-20 09:47:56 +01:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2023-11-29 12:33:26 +01:00
|
|
|
auto rel_loc_prop = attachment_prop->at<Gvas::Types::VectorStructProperty>(MASS_BL_ATTACHMENT_RELLOC);
|
2022-03-20 09:47:56 +01:00
|
|
|
rel_loc_prop->x = attachment.relativeLocation.x();
|
|
|
|
rel_loc_prop->y = attachment.relativeLocation.y();
|
|
|
|
rel_loc_prop->z = attachment.relativeLocation.z();
|
2023-11-29 12:33:26 +01:00
|
|
|
auto off_loc_prop = attachment_prop->at<Gvas::Types::VectorStructProperty>(MASS_BL_ATTACHMENT_OFFLOC);
|
2022-03-20 09:47:56 +01:00
|
|
|
off_loc_prop->x = attachment.offsetLocation.x();
|
|
|
|
off_loc_prop->y = attachment.offsetLocation.y();
|
|
|
|
off_loc_prop->z = attachment.offsetLocation.z();
|
2023-11-29 12:33:26 +01:00
|
|
|
auto rel_rot_prop = attachment_prop->at<Gvas::Types::VectorStructProperty>(MASS_BL_ATTACHMENT_RELROT);
|
2022-03-20 09:47:56 +01:00
|
|
|
rel_rot_prop->x = attachment.relativeRotation.x();
|
|
|
|
rel_rot_prop->y = attachment.relativeRotation.y();
|
|
|
|
rel_rot_prop->z = attachment.relativeRotation.z();
|
2023-11-29 12:33:26 +01:00
|
|
|
auto off_rot_prop = attachment_prop->at<Gvas::Types::VectorStructProperty>(MASS_BL_ATTACHMENT_OFFROT);
|
2022-03-20 09:47:56 +01:00
|
|
|
off_rot_prop->x = attachment.offsetRotation.x();
|
|
|
|
off_rot_prop->y = attachment.offsetRotation.y();
|
|
|
|
off_rot_prop->z = attachment.offsetRotation.z();
|
2023-11-29 12:33:26 +01:00
|
|
|
auto rel_scale_prop = attachment_prop->at<Gvas::Types::VectorStructProperty>(MASS_BL_ATTACHMENT_RELSCALE);
|
2022-03-20 09:47:56 +01:00
|
|
|
rel_scale_prop->x = attachment.relativeScale.x();
|
|
|
|
rel_scale_prop->y = attachment.relativeScale.y();
|
|
|
|
rel_scale_prop->z = attachment.relativeScale.z();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if(!attach_style_prop) {
|
2023-11-29 12:33:26 +01:00
|
|
|
attach_style_prop = new Gvas::Types::ByteProperty;
|
2022-11-21 18:00:38 +01:00
|
|
|
attach_style_prop->name.emplace(MASS_BL_ATTACHMENT_STYLE);
|
2022-03-20 09:47:56 +01:00
|
|
|
attach_style_prop->enumType = "enuBLAttachmentStyle"_s;
|
2023-11-29 12:33:26 +01:00
|
|
|
Gvas::Types::ByteProperty::ptr prop{attach_style_prop};
|
2022-03-20 09:47:56 +01:00
|
|
|
arrayAppend(unit_data->properties, std::move(prop));
|
|
|
|
}
|
|
|
|
|
|
|
|
auto& attach_style = attach_style_prop->enumValue;
|
|
|
|
switch(_armour.blAttachmentStyle) {
|
|
|
|
#define c(enumerator, strenum) case BulletLauncherAttachmentStyle::enumerator: \
|
|
|
|
attach_style = strenum; \
|
|
|
|
break;
|
|
|
|
#include "../Maps/BulletLauncherAttachmentStyles.hpp"
|
|
|
|
#undef c
|
|
|
|
default:
|
|
|
|
_lastError = "Unknown BL attachment style.";
|
2022-11-21 18:01:29 +01:00
|
|
|
LOG_ERROR(_lastError);
|
2022-03-20 09:47:56 +01:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(!_mass->saveToFile()) {
|
|
|
|
_lastError = _mass->lastError();
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
2022-03-12 09:34:19 +01:00
|
|
|
}
|
|
|
|
|
2022-12-03 16:49:39 +01:00
|
|
|
Containers::ArrayView<CustomStyle>
|
|
|
|
Mass::armourCustomStyles() {
|
2022-03-06 09:51:57 +01:00
|
|
|
return _armour.customStyles;
|
|
|
|
}
|
|
|
|
|
2022-12-03 16:49:39 +01:00
|
|
|
void
|
|
|
|
Mass::getArmourCustomStyles() {
|
2022-11-21 18:01:29 +01:00
|
|
|
LOG_INFO("Getting the custom armour styles.");
|
|
|
|
|
2023-11-29 12:33:26 +01:00
|
|
|
auto unit_data = _mass->at<Gvas::Types::GenericStructProperty>(MASS_UNIT_DATA);
|
2022-03-06 09:51:57 +01:00
|
|
|
if(!unit_data) {
|
2022-11-21 18:01:29 +01:00
|
|
|
LOG_ERROR_FORMAT("Couldn't find {} in {}.", MASS_UNIT_DATA, _filename);
|
2022-03-06 09:51:57 +01:00
|
|
|
_state = State::Invalid;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2023-11-29 12:33:26 +01:00
|
|
|
auto armour_styles = unit_data->at<Gvas::Types::ArrayProperty>(MASS_CUSTOM_ARMOUR_STYLES);
|
2022-03-06 09:51:57 +01:00
|
|
|
if(!armour_styles) {
|
2022-11-21 18:01:29 +01:00
|
|
|
LOG_ERROR_FORMAT("Couldn't find {} in {}.", MASS_CUSTOM_ARMOUR_STYLES, _filename);
|
2022-03-06 09:51:57 +01:00
|
|
|
_state = State::Invalid;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(armour_styles->items.size() != _armour.customStyles.size()) {
|
2022-11-21 18:01:29 +01:00
|
|
|
LOG_ERROR_FORMAT("Custom armour style arrays are not of the same size. Expected {}, got {} instead.",
|
|
|
|
_armour.customStyles.size(), armour_styles->items.size());
|
2022-03-06 09:51:57 +01:00
|
|
|
_state = State::Invalid;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
getCustomStyles(_armour.customStyles, armour_styles);
|
|
|
|
}
|
|
|
|
|
2022-12-03 16:49:39 +01:00
|
|
|
bool
|
2022-12-05 11:32:18 +01:00
|
|
|
Mass::writeArmourCustomStyle(std::size_t index) {
|
2022-11-21 18:01:29 +01:00
|
|
|
LOG_INFO_FORMAT("Writing custom armour style {}.", index);
|
|
|
|
|
2022-03-06 09:51:57 +01:00
|
|
|
if(index > _armour.customStyles.size()) {
|
|
|
|
_lastError = "Style index out of range."_s;
|
2022-11-21 18:01:29 +01:00
|
|
|
LOG_ERROR(_lastError);
|
2022-03-06 09:51:57 +01:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2023-11-29 12:33:26 +01:00
|
|
|
auto unit_data = _mass->at<Gvas::Types::GenericStructProperty>(MASS_UNIT_DATA);
|
2022-03-06 09:51:57 +01:00
|
|
|
if(!unit_data) {
|
|
|
|
_lastError = "Couldn't find unit data in "_s + _filename;
|
2022-11-21 18:01:29 +01:00
|
|
|
LOG_ERROR(_lastError);
|
|
|
|
_state = State::Invalid;
|
2022-03-06 09:51:57 +01:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2023-11-29 12:33:26 +01:00
|
|
|
auto armour_styles = unit_data->at<Gvas::Types::ArrayProperty>(MASS_CUSTOM_ARMOUR_STYLES);
|
2022-03-06 09:51:57 +01:00
|
|
|
if(!armour_styles) {
|
|
|
|
_lastError = "Couldn't find armour custom styles in "_s + _filename;
|
2022-11-21 18:01:29 +01:00
|
|
|
LOG_ERROR(_lastError);
|
2022-03-06 09:51:57 +01:00
|
|
|
_state = State::Invalid;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return writeCustomStyle(_armour.customStyles[index], index, armour_styles);
|
|
|
|
}
|
2023-11-29 12:33:26 +01:00
|
|
|
|
|
|
|
}}
|