Crossfire Resources Editor
ArchetypesWrapper.cpp
Go to the documentation of this file.
1 /*
2  * Crossfire -- cooperative multi-player graphical RPG and adventure game
3  *
4  * Copyright (c) 2022 the Crossfire Development Team
5  *
6  * Crossfire is free software and comes with ABSOLUTELY NO WARRANTY. You are
7  * welcome to redistribute it under certain conditions. For details, please
8  * see COPYING and LICENSE.
9  *
10  * The authors can be reached via e-mail at <crossfire@metalforge.org>.
11  */
12 
13 #include "ArchetypesWrapper.h"
14 #include "../ResourcesManager.h"
15 
17 
18 constexpr int csvFieldCount = 20;
19 const char *csvFields[csvFieldCount] = {
20  "arch_name",
21  "hp",
22  "maxhp",
23  "con",
24  "regen",
25  "ac",
26  "wc",
27  "weight",
28  "experience",
29  "level",
30  "suggested_level",
31  "damage",
32  "speed",
33  "dps",
34  "sp",
35  "maxsp",
36  "pow",
37  "wis",
38  "str",
39  "intl",
40 };
41 
42 void ArchetypesWrapper::fillMenu(QMenu *menu) {
43  connect(menu->addAction(tr("Add archetype")), &QAction::triggered, [this] () { addArchetype(); });
44 }
45 
47  auto origins = myResources->archetypeFiles();
48  auto keys = getManager()->archetypes()->keys();
49 
51  if (aqd.exec() != QDialog::Accepted) {
52  return;
53  }
54 
55  auto arch = get_archetype_struct();
56  CLEAR_FLAG(&arch->clone, FLAG_REMOVED);
57  arch->name = add_string(aqd.code().toStdString().c_str());
58  arch->clone.name = add_string(arch->name);
59  getManager()->archetypes()->define(arch->name, arch);
60  myResources->assetDefined(arch, aqd.file().toStdString());
63  myAssets.push_back(myResources->wrap(arch, this));
65 }
66 
67 void ArchetypesWrapper::fillCsvHeader(QString& contents) const
68 {
69  for (int f = 0; f < csvFieldCount; f++)
70  contents.append(f == 0 ? "" : ";").append(csvFields[f]);
71  for (int r = 0; r < NROFATTACKS; r++)
72  contents.append(";").append(resist_plus[r]);
73  contents.append("\n");
74 }
75 
76 void ArchetypesWrapper::exportAsCSV(const AssetWrapper *item, QString& contents) const
77 {
78  auto arch = const_cast<ArchetypeWrapper *>(dynamic_cast<const ArchetypeWrapper *>(item));
79  auto object = static_cast<ObjectWrapper *>(arch->clone());
80  for (int f = 0; f < csvFieldCount; f++)
81  contents.append(f == 0 ? "" : ";").append(object->property(csvFields[f]).toString());
82  for (int r = 0; r < NROFATTACKS; r++)
83  contents.append(";").append(QString::number(object->getObject()->resist[r]));
84  contents.append("\n");
85 }
ArchetypesWrapper::fillMenu
virtual void fillMenu(QMenu *menu) override
Definition: ArchetypesWrapper.cpp:42
ArchetypesWrapper::fillCsvHeader
virtual void fillCsvHeader(QString &contents) const
Definition: ArchetypesWrapper.cpp:67
AssetWrapper::AfterChildAdd
@ AfterChildAdd
Definition: AssetWrapper.h:33
ResourcesManager::wrap
ArchetypeWrapper * wrap(archetype *arch, AssetWrapper *parent)
Definition: ResourcesManager.h:134
ResourcesManager::assetDefined
virtual void assetDefined(const archetype *arch, const std::string &filename) override
Definition: ResourcesManager.h:101
ArchetypesWrapper::exportAsCSV
virtual void exportAsCSV(const AssetWrapper *item, QString &contents) const override
Definition: ArchetypesWrapper.cpp:76
ArchetypesWrapper.h
csvFieldCount
constexpr int csvFieldCount
Definition: ArchetypesWrapper.cpp:18
AssetOriginAndCreationDialog::CreateAsset
@ CreateAsset
Definition: AssetOriginAndCreationDialog.h:25
AssetWrapper::BeforeChildAdd
@ BeforeChildAdd
Definition: AssetWrapper.h:33
ObjectWrapper
Definition: ObjectWrapper.h:36
ResourcesManager::archetypeFiles
std::vector< std::string > archetypeFiles() const
Definition: ResourcesManager.h:111
AssetWrapper
Base class for all assets that can be displayed or edited by CRE.
Definition: AssetWrapper.h:25
AssetOriginAndCreationDialog.h
AssetOriginAndCreationDialog
Helper dialog to input origin of an asset, and maybe create a new one.
Definition: AssetOriginAndCreationDialog.h:21
ResourcesManager::archetypeModified
void archetypeModified(archetype *arch)
Definition: ResourcesManager.cpp:213
csvFields
const char * csvFields[csvFieldCount]
Definition: ArchetypesWrapper.cpp:19
ArchetypeWrapper
Definition: ArchetypeWrapper.h:25
AssetOriginAndCreationDialog::Archetype
@ Archetype
Definition: AssetOriginAndCreationDialog.h:24
AssetWrapper::markModified
void markModified(ChangeType change, int extra=0)
Definition: AssetWrapper.h:57
AssetsCollectionWrapper< archetype >::myAssets
QVector< AssetWrapper * > myAssets
Definition: AssetsCollectionWrapper.h:41
AssetOriginAndCreationDialog::code
QString code() const
Definition: AssetOriginAndCreationDialog.h:37
ArchetypesWrapper::addArchetype
void addArchetype()
Definition: ArchetypesWrapper.cpp:46
AssetOriginAndCreationDialog::file
QString file() const
Definition: AssetOriginAndCreationDialog.h:38
ArchetypesWrapper::myResources
ResourcesManager * myResources
Definition: ArchetypesWrapper.h:46