Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions engine/includes/editor/assetconverter.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,9 @@ class ENGINE_EXPORT AssetConverterSettings : public Object {
struct SubItem {
TString uuid;

QImage icon;
TString type;

int32_t typeId;
QImage icon;

bool dirty = true;
};
Expand Down Expand Up @@ -79,6 +79,8 @@ class ENGINE_EXPORT AssetConverterSettings : public Object {
virtual TString absoluteDestination() const;
virtual void setAbsoluteDestination(const TString &destination);

virtual TString propertyAllias(const TString &name) const;

void resetIcon(const TString &uuid);
QImage icon(const TString &uuid);

Expand All @@ -98,11 +100,11 @@ class ENGINE_EXPORT AssetConverterSettings : public Object {

void setSubItemsDirty();

void setSubItem(const TString &name, const TString &uuid, int32_t type);
void setSubItem(const TString &name, const TString &uuid, const TString &type);
virtual void setSubItemData(const TString &name, const Variant &data);

AssetConverter::ReturnCode saveBinary(const Variant &data);
TString saveSubData(const Variant &data, const TString &path, int32_t type);
TString saveSubData(const Variant &data, const TString &path, const TString &type);

bool loadSettings();
void saveSettings();
Expand All @@ -120,8 +122,6 @@ class ENGINE_EXPORT AssetConverterSettings : public Object {
protected:
virtual TString defaultIconPath(const TString &type) const;

void setType(uint32_t type);

void setVersion(uint32_t version);

QImage renderDocumentIcon(const TString &path, const TString &color = TString("#0277bd"));
Expand Down
2 changes: 2 additions & 0 deletions engine/includes/editor/converters/animconverter.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ class AnimImportSettings : public AssetConverterSettings {
AnimImportSettings();

private:
StringList typeNames() const override;

bool isReadOnly() const override;

TString defaultIconPath(const TString &) const override;
Expand Down
2 changes: 2 additions & 0 deletions engine/includes/editor/converters/controlschemeconverter.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
class ControlScehemeConverterSettings : public AssetConverterSettings {
public:
ControlScehemeConverterSettings();

StringList typeNames() const override;
};

class ControlSchemeConverter : public AssetConverter {
Expand Down
2 changes: 2 additions & 0 deletions engine/includes/editor/converters/fontconverter.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ class FontImportSettings : public AssetConverterSettings {
FontImportSettings();

private:
StringList typeNames() const override;

TString defaultIconPath(const TString &) const override;
};

Expand Down
2 changes: 2 additions & 0 deletions engine/includes/editor/converters/textconverter.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ class TextConverterSettings : public AssetConverterSettings {
private:
TString defaultIconPath(const TString &) const override;

StringList typeNames() const override;

};

class TextConverter : public AssetConverter {
Expand Down
3 changes: 3 additions & 0 deletions engine/includes/editor/converters/translatorconverter.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@ class TranslatorConverterSettings : public AssetConverterSettings {

private:
TString defaultIconPath(const TString &) const override;

StringList typeNames() const override;

};

class TranslatorConverter : public AssetConverter {
Expand Down
43 changes: 25 additions & 18 deletions engine/src/editor/assetconverter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,13 +52,7 @@ AssetConverterSettings::~AssetConverterSettings() {
Returns the asset type for conversion for more details see MetaType.
*/
uint32_t AssetConverterSettings::type() const {
return m_type;
}
/*!
Sets the asset type for conversion for more details see MetaType.
*/
void AssetConverterSettings::setType(uint32_t type) {
m_type = type;
return MetaType::type(typeName().data());
}
/*!
Returns true if asset cannot be cahnged using any embedded editor; returns true by the default.
Expand Down Expand Up @@ -145,7 +139,7 @@ QImage AssetConverterSettings::icon(const TString &uuid) {
for(auto &it : m_subItems) {
if(it.second.uuid == uuid) {
if(it.second.icon.isNull() && !it.second.icon.load(path.data())) {
it.second.icon = documentIcon(MetaType::name(it.second.typeId));
it.second.icon = documentIcon(it.second.type);
}
return it.second.icon;
}
Expand Down Expand Up @@ -288,6 +282,12 @@ TString AssetConverterSettings::absoluteDestination() const {
void AssetConverterSettings::setAbsoluteDestination(const TString &destination) {
m_absoluteDestination = destination;
}
/*!
\internal
*/
TString AssetConverterSettings::propertyAllias(const TString &name) const {
return name;
}
/*!
Returns list of all sub-item keys.
*/
Expand Down Expand Up @@ -329,7 +329,7 @@ TString AssetConverterSettings::subTypeName(const TString &key) const {
int32_t AssetConverterSettings::subType(const TString &key) const {
auto it = m_subItems.find(key);
if(it != m_subItems.end()) {
return it->second.typeId;
return MetaType::type(it->second.type.data());
}
return 0;
}
Expand All @@ -344,9 +344,9 @@ void AssetConverterSettings::setSubItemsDirty() {
/*!
Sets a sub-item with \a name, \a uuid, and \a type.
*/
void AssetConverterSettings::setSubItem(const TString &name, const TString &uuid, int32_t type) {
void AssetConverterSettings::setSubItem(const TString &name, const TString &uuid, const TString &type) {
if(!name.isEmpty() && !uuid.isEmpty()) {
m_subItems[name] = {uuid, QImage(), type, false};
m_subItems[name] = {uuid, type, QImage(), false};
}
}
/*!
Expand Down Expand Up @@ -380,8 +380,8 @@ AssetConverter::ReturnCode AssetConverterSettings::saveBinary(const Variant &dat
This method generated UUID id needed and registers a new sub-item.
\sa AssetConverterSettings::setSubItem()
*/
TString AssetConverterSettings::saveSubData(const Variant &data, const TString &path, int32_t type) {
TString uuid = subItem(path);
TString AssetConverterSettings::saveSubData(const Variant &data, const TString &path, const TString &type) {
TString uuid(subItem(path));
if(uuid.isEmpty()) {
uuid = QUuid::createUuid().toString().toStdString();
}
Expand Down Expand Up @@ -416,6 +416,11 @@ bool AssetConverterSettings::loadSettings() {
auto it = map.find(property.name());
if(it != map.end()) {
v = it->second;
} else {
it = map.find(propertyAllias(property.name()));
if(it != map.end()) {
v = it->second;
}
}
v.convert(MetaType::type(property.type().name()));
property.write(this, v);
Expand Down Expand Up @@ -444,7 +449,12 @@ bool AssetConverterSettings::loadSettings() {
auto item = array.begin();
TString uuid = item->toString();
item++;
int type = item->toInt();
TString type;
if(item->type() == MetaType::INTEGER) {
type = MetaType::name(item->toInt());
} else {
type = item->toString();
}
setSubItem(subIt.first, uuid, type);
item++;
if(item != array.end()) {
Expand Down Expand Up @@ -481,7 +491,6 @@ void AssetConverterSettings::saveSettings() {
obj[gMd5] = hash();
obj[gGUID] = destination();
obj[gSettings] = set;
obj[gType] = type();

VariantMap sub;
for(auto it : m_subItems) {
Expand All @@ -490,15 +499,13 @@ void AssetConverterSettings::saveSettings() {
if(!item.dirty) {
VariantList array;
array.push_back(item.uuid);
array.push_back(item.typeId);
array.push_back(item.type);

Variant data = subItemData(it.first);
if(data.isValid()) {
array.push_back(data);
}

array.push_back(subTypeName(it.first));

sub[it.first] = array;
}
}
Expand Down
4 changes: 2 additions & 2 deletions engine/src/editor/codebuilder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,11 @@ namespace {

BuilderSettings::BuilderSettings(CodeBuilder *builder) :
m_builder(builder) {
setType(MetaType::type<Text *>());

}

StringList BuilderSettings::typeNames() const {
return { "Code" };
return { "Text" };
}

TString BuilderSettings::defaultIconPath(const TString &) const {
Expand Down
5 changes: 4 additions & 1 deletion engine/src/editor/converters/animconverter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,13 @@ namespace {
}

AnimImportSettings::AnimImportSettings() {
setType(MetaType::type<AnimationClip *>());
setVersion(FORMAT_VERSION);
}

StringList AnimImportSettings::typeNames() const {
return { "AnimationClip" };
}

bool AnimImportSettings::isReadOnly() const {
return false;
}
Expand Down
7 changes: 3 additions & 4 deletions engine/src/editor/converters/assimpconverter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,6 @@ AssimpImportSettings::AssimpImportSettings() :
m_rotationError(0.5f),
m_scaleError(0.5f) {

setType(MetaType::type<Prefab *>());
setVersion(FORMAT_VERSION);
}

Expand Down Expand Up @@ -510,7 +509,7 @@ Mesh *AssimpConverter::importMesh(const aiScene *scene, const aiNode *element, A
total_i += indexCount;
}

TString uuid = fbxSettings->saveSubData(Engine::toVariant(mesh), actor->name(), MetaType::type<Mesh *>());
TString uuid = fbxSettings->saveSubData(Engine::toVariant(mesh), actor->name(), MetaType::name<Mesh>());

Mesh *resource = Engine::loadResource<Mesh>(uuid);
if(resource == nullptr) {
Expand Down Expand Up @@ -732,7 +731,7 @@ void AssimpConverter::importAnimation(const aiScene *scene, AssimpImportSettings

clip.m_tracks.sort(compare);

fbxSettings->saveSubData(Engine::toVariant(&clip), animation->mName.C_Str(), MetaType::type<AnimationClip *>());
fbxSettings->saveSubData(Engine::toVariant(&clip), animation->mName.C_Str(), MetaType::name<AnimationClip>());
}
}

Expand All @@ -756,7 +755,7 @@ void AssimpConverter::importPose(AssimpImportSettings *fbxSettings) {
pose->addBone(&b);
}

TString uuid = fbxSettings->saveSubData(Engine::toVariant(pose), "Pose", MetaType::type<Pose *>());
TString uuid = fbxSettings->saveSubData(Engine::toVariant(pose), "Pose", MetaType::name<Pose>());

Pose *resource = Engine::loadResource<Pose>(uuid);
if(resource == nullptr) {
Expand Down
8 changes: 7 additions & 1 deletion engine/src/editor/converters/controlschemeconverter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,14 @@ namespace {
const char *gData("Data");
}

#define FORMAT_VERSION 1

ControlScehemeConverterSettings::ControlScehemeConverterSettings() {
setType(MetaType::type<ControlScheme *>());
setVersion(FORMAT_VERSION);
}

StringList ControlScehemeConverterSettings::typeNames() const {
return { "ControlScheme" };
}

AssetConverter::ReturnCode ControlSchemeConverter::convertFile(AssetConverterSettings *settings) {
Expand Down
5 changes: 4 additions & 1 deletion engine/src/editor/converters/fontconverter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,13 @@ namespace {
#define FORMAT_VERSION 1

FontImportSettings::FontImportSettings() {
setType(MetaType::type<Font *>());
setVersion(FORMAT_VERSION);
}

StringList FontImportSettings::typeNames() const {
return { "Font" };
}

TString FontImportSettings::defaultIconPath(const TString &) const {
return ":/Style/styles/dark/images/font.svg";
}
Expand Down
1 change: 0 additions & 1 deletion engine/src/editor/converters/mapconverter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
#define FORMAT_VERSION 5

MapConverterSettings::MapConverterSettings() {
setType(MetaType::type<Scene *>());
setVersion(FORMAT_VERSION);
}

Expand Down
9 changes: 3 additions & 6 deletions engine/src/editor/converters/prefabconverter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@

#include "components/actor.h"

#include <QFile>

#include <json.h>
#include <file.h>

Expand All @@ -13,7 +11,6 @@
#define FORMAT_VERSION 5

PrefabConverterSettings::PrefabConverterSettings() {
setType(MetaType::type<Prefab *>());
setVersion(FORMAT_VERSION);
}

Expand All @@ -38,9 +35,9 @@ TString PrefabConverter::templatePath() const {
}

void PrefabConverter::createFromTemplate(const TString &destination) {
QFile src(templatePath().data());
if(src.open(QFile::ReadOnly)) {
TString data = src.readAll().toStdString();
File src(templatePath().data());
if(src.open(File::ReadOnly)) {
TString data = src.readAll();
src.close();

Variant variant = Json::load(data);
Expand Down
5 changes: 4 additions & 1 deletion engine/src/editor/converters/textconverter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,17 @@
#define FORMAT_VERSION 1

TextConverterSettings::TextConverterSettings() {
setType(MetaType::type<Text *>());
setVersion(FORMAT_VERSION);
}

TString TextConverterSettings::defaultIconPath(const TString &) const {
return ":/Style/styles/dark/images/text.svg";
}

StringList TextConverterSettings::typeNames() const {
return { "Text" };
}

AssetConverter::ReturnCode TextConverter::convertFile(AssetConverterSettings *settings) {
File src(settings->source());
if(src.open(File::ReadOnly)) {
Expand Down
5 changes: 4 additions & 1 deletion engine/src/editor/converters/translatorconverter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,17 @@
#define FORMAT_VERSION 1

TranslatorConverterSettings::TranslatorConverterSettings() {
setType(MetaType::type<Translator *>());
setVersion(FORMAT_VERSION);
}

TString TranslatorConverterSettings::defaultIconPath(const TString &) const {
return ":/Style/styles/dark/images/l10n.svg";
}

StringList TranslatorConverterSettings::typeNames() const {
return { "Translator" };
}

AssetConverter::ReturnCode TranslatorConverter::convertFile(AssetConverterSettings *settings) {
QFile src(settings->source().data());
if(src.open(QIODevice::ReadOnly)) {
Expand Down
5 changes: 4 additions & 1 deletion modules/editor/motiontools/converter/animationbuilder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,13 @@
#define FORMAT_VERSION 12

AnimationBuilderSettings::AnimationBuilderSettings() {
setType(MetaType::type<AnimationStateMachine *>());
setVersion(FORMAT_VERSION);
}

StringList AnimationBuilderSettings::typeNames() const {
return { "AnimationStateMachine" };
}

TString AnimationBuilderSettings::defaultIconPath(const TString &) const {
return ":/Style/styles/dark/images/machine.svg";
}
Expand Down
Loading
Loading