Tweak loader for MP1

This commit is contained in:
Aruki
2018-12-27 20:16:39 -07:00
parent d6340dced9
commit 7588200c26
37 changed files with 3780 additions and 65 deletions

View File

@@ -13,6 +13,7 @@ void CGameTemplate::Serialize(IArchive& Arc)
{
Arc << SerialParameter("ScriptObjects", mScriptTemplates)
<< SerialParameter("PropertyArchetypes", mPropertyTemplates)
<< SerialParameter("MiscTemplates", mMiscTemplates)
<< SerialParameter("States", mStates)
<< SerialParameter("Messages", mMessages);
}
@@ -51,6 +52,13 @@ void CGameTemplate::Load(const TString& kFilePath)
Internal_LoadPropertyTemplate(Iter->second);
}
}
for (auto Iter = mMiscTemplates.begin(); Iter != mMiscTemplates.end(); Iter++)
{
SScriptTemplatePath& MiscPath = Iter->second;
TString AbsPath = gkGameRoot + MiscPath.Path;
MiscPath.pTemplate = std::make_shared<CScriptTemplate>(this, -1, AbsPath);
}
}
void CGameTemplate::Save()
@@ -118,6 +126,16 @@ void CGameTemplate::SaveGameTemplates(bool ForceAll /*= false*/)
}
}
}
for (auto Iter = mMiscTemplates.begin(); Iter != mMiscTemplates.end(); Iter++)
{
SScriptTemplatePath& Path = Iter->second;
if( Path.pTemplate )
{
Path.pTemplate->Save(ForceAll);
}
}
}
uint32 CGameTemplate::GameVersion(TString VersionName)
@@ -286,6 +304,21 @@ bool CGameTemplate::RenamePropertyArchetype(const TString& kTypeName, const TStr
return false;
}
CScriptTemplate* CGameTemplate::FindMiscTemplate(const TString& kTemplateName)
{
auto Iter = mMiscTemplates.find(kTemplateName);
if (Iter == mMiscTemplates.end())
{
return nullptr;
}
else
{
SScriptTemplatePath& Path = Iter->second;
return Path.pTemplate.get();
}
}
TString CGameTemplate::GetGameDirectory() const
{
return mSourceFile.GetFileDirectory();

View File

@@ -35,54 +35,23 @@ struct SObjId
}
};
/** Struct holding a reference to a script object template */
struct SScriptTemplatePath
/** Struct holding a reference to a template */
template<typename TemplateT>
struct TTemplatePath
{
/** File path to the template file, relative to the game directory */
TString Path;
/** Template in memory */
std::shared_ptr<CScriptTemplate> pTemplate;
std::shared_ptr<TemplateT> pTemplate;
/** Constructor */
SScriptTemplatePath()
TTemplatePath()
{}
SScriptTemplatePath(const TString& kInPath, CScriptTemplate* pInTemplate)
TTemplatePath(const TString& kInPath, TemplateT* pInTemplate)
: Path(kInPath)
, pTemplate( std::shared_ptr<CScriptTemplate>(pInTemplate) )
{}
/** Serializer */
void Serialize(IArchive& Arc)
{
if (Arc.FileVersion() == 0)
{
Arc << SerialParameter("Path", Path, SH_Attribute);
}
else
{
Arc.SerializePrimitive(Path, 0);
}
}
};
/** Struct holding a reference to a property template */
struct SPropertyTemplatePath
{
/** File path to the template file, relative to the game directory */
TString Path;
/** Template in memory */
std::shared_ptr<IProperty> pTemplate;
/** Constructor */
SPropertyTemplatePath()
{}
SPropertyTemplatePath(const TString& kInPath, IProperty* pInTemplate)
: Path(kInPath)
, pTemplate( std::shared_ptr<IProperty>(pInTemplate) )
, pTemplate( std::shared_ptr<TemplateT>(pInTemplate) )
{}
/** Serializer */
@@ -92,6 +61,9 @@ struct SPropertyTemplatePath
}
};
typedef TTemplatePath<CScriptTemplate> SScriptTemplatePath;
typedef TTemplatePath<IProperty> SPropertyTemplatePath;
/** CGameTemplate - Per-game template data */
class CGameTemplate
{
@@ -103,6 +75,7 @@ class CGameTemplate
/** Template arrays */
std::map<SObjId, SScriptTemplatePath> mScriptTemplates;
std::map<TString, SPropertyTemplatePath> mPropertyTemplates;
std::map<TString, SScriptTemplatePath> mMiscTemplates;
std::map<SObjId, TString> mStates;
std::map<SObjId, TString> mMessages;
@@ -130,6 +103,7 @@ public:
IProperty* FindPropertyArchetype(const TString& kTypeName);
TString GetPropertyArchetypeFilePath(const TString& kTypeName);
bool RenamePropertyArchetype(const TString& kTypeName, const TString& kNewTypeName);
CScriptTemplate* FindMiscTemplate(const TString& kTemplateName);
TString GetGameDirectory() const;
// Inline Accessors

View File

@@ -91,6 +91,7 @@ void IProperty::Serialize(IArchive& rArc)
// The archetype must exist, or else the template file is malformed.
ASSERT(pArchetype != nullptr);
ASSERT(pArchetype->Type() == Type());
InitFromArchetype(pArchetype);
}