OpenClonk
c4def-handle.cpp
Go to the documentation of this file.
1 /*
2  * mape - C4 Landscape.txt editor
3  *
4  * Copyright (c) 2005-2009, Armin Burgmeier
5  *
6  * Distributed under the terms of the ISC license; see accompanying file
7  * "COPYING" for details.
8  *
9  * "Clonk" is a registered trademark of Matthes Bender, used with permission.
10  * See accompanying file "TRADEMARK" for details.
11  *
12  * To redistribute this file separately, substitute the full license texts
13  * for the above references.
14  */
15 
16 #include "C4Include.h"
17 
18 #include "object/C4Def.h"
19 #include "object/C4DefList.h"
20 #include "lib/StdMeshLoader.h"
21 
22 /* This is a simple implementation of C4DefList for what is required by
23  * mape. We cannot link the full implementation since it would introduce
24  * a dependency on C4Game, and therefore the rest of the engine. */
25 
26 C4Def::C4Def(): Script(), C4PropListStatic(ScriptEngine.GetPropList(), nullptr, nullptr)
27 {
28  Script.SetDef(this);
29  assert(ScriptEngine.GetPropList());
30  Graphics.pDef = this;
31 
32  Next = nullptr;
33  Script.Clear();
34 }
35 
37 {
39  Script.Clear();
40 }
41 
43 {
44  FirstDef = nullptr;
45 }
46 
48 {
49  Clear();
50 }
51 
53 {
54  while(FirstDef)
55  {
56  C4Def* out = FirstDef;
58  delete out;
59  }
60 }
61 
63 {
64  C4Def* cdef;
65  for(cdef = FirstDef; cdef != nullptr; cdef = cdef->Next)
66  if(cdef->id == id)
67  return cdef;
68  return nullptr;
69 }
70 
72 {
73  return ID2Def(C4ID(name));
74 }
75 
77 {
78  int counter = 0;
79  for(C4Def* cdef = FirstDef; cdef != nullptr; cdef = cdef->Next)
80  {
81  if(counter == iIndex) return cdef;
82  ++counter;
83  }
84 
85  return nullptr;
86 }
87 
89 {
90  int counter = 0;
91  for(C4Def* cdef = FirstDef; cdef != nullptr; cdef = cdef->Next)
92  ++counter;
93  return counter;
94 }
95 
96 bool C4DefList::Add(C4Def* def, bool fOverload)
97 {
98  assert(ID2Def(def->id) == nullptr);
99 
100  def->Next = FirstDef;
101  FirstDef = def;
102 
103  return true;
104 }
105 
106 bool C4Def::Load(C4Group& hGroup, StdMeshSkeletonLoader& loader, DWORD dwLoadWhat, const char* szLanguage, C4SoundSystem* pSoundSystem, C4DefGraphicsPtrBackup *)
107 {
108  // Assume ID has been set already!
109 
110  // Register with script engine
111  ::ScriptEngine.RegisterGlobalConstant(id.ToString(), C4VPropList(this));
112  ParentKeyName = ::Strings.RegString(id.ToString());
114 
115  if(!Script.Load(hGroup, "Script.c", nullptr, nullptr))
116  {
117  return false;
118  }
119 
120  return true;
121 }
122 
C4AulScriptEngine ScriptEngine
Definition: C4Globals.cpp:43
C4StringTable Strings
Definition: C4Globals.cpp:42
C4Value C4VPropList(C4PropList *p)
Definition: C4Value.h:242
uint32_t DWORD
C4DefList Definitions
C4PropListStatic * GetPropList()
Definition: C4Aul.h:151
void RegisterGlobalConstant(const char *szName, const C4Value &rValue)
Definition: C4Aul.cpp:123
Definition: C4Def.h:99
bool Load(C4Group &hGroup, StdMeshSkeletonLoader &loader, DWORD dwLoadWhat, const char *szLanguage, class C4SoundSystem *pSoundSystem=nullptr, C4DefGraphicsPtrBackup *gfx_backup=nullptr)
~C4Def() override
C4DefScriptHost Script
Definition: C4Def.h:181
C4DefGraphics Graphics
Definition: C4Def.h:191
C4ID id
Definition: C4Def.h:101
C4Def * Next
Definition: C4Def.h:198
int32_t GetDefCount()
void Clear()
C4Def * FirstDef
Definition: C4DefList.h:35
C4Def * GetDef(int32_t Index)
bool Add(C4Def *ndef, bool fOverload)
~C4DefList() override
C4Def * GetByName(const StdStrBuf &)
C4Def * ID2Def(C4ID id)
void SetDef(C4Def *to_def)
Definition: C4ScriptHost.h:144
Definition: C4Id.h:26
void Clear()
Definition: C4PropList.h:70
C4RefCntPointer< C4String > ParentKeyName
Definition: C4PropList.h:279
virtual bool Load(C4Group &hGroup, const char *szFilename, const char *szLanguage, C4LangStringTable *pLocalTable)
void Reg2List(C4AulScriptEngine *pEngine)
C4String * RegString(StdStrBuf String)