Crossfire Server, Trunk
ScriptFileManager.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 "ScriptFileManager.h"
14 #include "scripts/ScriptFile.h"
15 #include <QVariant>
16 
18  setProperty(tipProperty, tr("Display all Python scripts used in maps."));
19 }
20 
22 {
23  qDeleteAll(myScripts.values());
24 }
25 
27 {
28  QList<ScriptFile*> list;
29  foreach(ScriptFile* script, myScripts.values())
30  {
31  if (script->forMap(map))
32  {
33  list.append(script);
34  }
35  }
36  return list;
37 }
38 
40 {
41  if (!myScripts.contains(path))
42  {
44  myScripts.insert(path, new ScriptFile(this, path));
46  }
47  return myScripts[path];
48 }
49 
51 {
52  QHash<QString, ScriptFile*>::iterator script = myScripts.begin();
53  while (script != myScripts.end())
54  {
55  if ((*script)->removeMap(map))
56  {
57  ScriptFile* s = *script;
58  script = myScripts.erase(script);
59  delete s;
60  }
61  else
62  {
63  script++;
64  }
65  }
66 }
67 
68 QList<ScriptFile*> ScriptFileManager::scripts() const
69 {
70  return myScripts.values();
71 }
72 
73 void ScriptFileManager::addHook(const QString &file, HookInformation *hook) {
74  getFile(file)->addHook(hook);
75 }
ScriptFileManager.h
AssetWrapper::AfterChildAdd
@ AfterChildAdd
Definition: AssetWrapper.h:33
ScriptFile::forMap
bool forMap(const CREMapInformation *map) const
Definition: ScriptFile.cpp:30
ScriptFileManager::myScripts
QHash< QString, ScriptFile * > myScripts
Definition: ScriptFileManager.h:59
guildoracle.list
list
Definition: guildoracle.py:87
mad_mage_user.file
file
Definition: mad_mage_user.py:15
AssetWrapper::tipProperty
static const char * tipProperty
Definition: AssetWrapper.h:34
CREMapInformation
Definition: CREMapInformation.h:27
AssetWrapper::BeforeChildAdd
@ BeforeChildAdd
Definition: AssetWrapper.h:33
disinfect.map
map
Definition: disinfect.py:4
ScriptFile.h
ScriptFileManager::scriptsForMap
QList< ScriptFile * > scriptsForMap(CREMapInformation *map)
Definition: ScriptFileManager.cpp:26
AssetWrapper
Definition: AssetWrapper.h:25
python_init.path
path
Definition: python_init.py:8
ScriptFileManager::removeMap
void removeMap(CREMapInformation *map)
Definition: ScriptFileManager.cpp:50
ScriptFileManager::ScriptFileManager
ScriptFileManager(AssetWrapper *parent)
Definition: ScriptFileManager.cpp:17
ScriptFileManager::scripts
QList< ScriptFile * > scripts() const
Definition: ScriptFileManager.cpp:68
ScriptFile
Definition: ScriptFile.h:48
ScriptFileManager::getFile
ScriptFile * getFile(const QString &path)
Definition: ScriptFileManager.cpp:39
ScriptFile::addHook
void addHook(HookInformation *hook)
Definition: ScriptFile.cpp:25
AssetWrapper::markModified
void markModified(ChangeType change, int extra=0)
Definition: AssetWrapper.h:55
HookInformation
Definition: ScriptFile.h:25
ScriptFileManager::~ScriptFileManager
virtual ~ScriptFileManager()
Definition: ScriptFileManager.cpp:21
ScriptFileManager::addHook
void addHook(const QString &file, HookInformation *hook)
Definition: ScriptFileManager.cpp:73