1 // Copyright 2001-2019 Crytek GmbH / Crytek Group. All rights reserved.
4 #include "Script/Elements/ScriptInclude.h"
6 #include <CrySerialization/BlackBox.h>
7 #include <CrySerialization/IArchiveHost.h>
8 #include <CrySerialization/STL.h>
9 #include <CrySchematyc2/GUIDRemapper.h>
10 #include <CrySchematyc2/Deprecated/DocUtils.h>
11 #include <CrySchematyc2/Env/IEnvRegistry.h>
12 #include <CrySchematyc2/Serialization/ISerializationContext.h>
13 #include <CrySchematyc2/Serialization/SerializationUtils.h>
17 //////////////////////////////////////////////////////////////////////////
18 CScriptInclude::CScriptInclude(IScriptFile
& file
, const SGUID
& guid
, const SGUID
& scopeGUID
, const char* szFileName
, const SGUID
& refGUID
)
19 : CScriptElementBase(EScriptElementType::Include
, file
)
21 , m_scopeGUID(scopeGUID
)
22 , m_fileName(szFileName
)
26 //////////////////////////////////////////////////////////////////////////
27 EAccessor
CScriptInclude::GetAccessor() const
29 return EAccessor::Private
;
32 //////////////////////////////////////////////////////////////////////////
33 SGUID
CScriptInclude::GetGUID() const
38 //////////////////////////////////////////////////////////////////////////
39 SGUID
CScriptInclude::GetScopeGUID() const
44 //////////////////////////////////////////////////////////////////////////
45 bool CScriptInclude::SetName(const char* szName
)
50 //////////////////////////////////////////////////////////////////////////
51 const char* CScriptInclude::GetName() const
53 return m_fileName
.c_str();
56 //////////////////////////////////////////////////////////////////////////
57 void CScriptInclude::EnumerateDependencies(const ScriptDependancyEnumerator
& enumerator
) const {}
59 //////////////////////////////////////////////////////////////////////////
60 void CScriptInclude::Refresh(const SScriptRefreshParams
& params
) {}
62 //////////////////////////////////////////////////////////////////////////
63 void CScriptInclude::Serialize(Serialization::IArchive
& archive
)
65 CRY_PROFILE_FUNCTION(PROFILE_LOADING_ONLY
);
67 CScriptElementBase::Serialize(archive
);
69 SerializationContext::SetValidatorLink(archive
, SValidatorLink(m_guid
)); // #SchematycTODO : Can we set this from CScriptElementBase?
70 switch(SerializationContext::GetPass(archive
))
72 case ESerializationPass::PreLoad
:
74 archive(m_guid
, "guid");
75 archive(m_scopeGUID
, "scope_guid");
76 archive(m_fileName
, "fileName");
77 archive(m_refGUID
, "refGUID");
79 ////////////////////////////////////////////////////////////////////////////////////////////////////
80 // Temporary fix to ensure files load in the correct order.
81 // Ideally include dependencies should be resolved by the doc manager.
82 IScriptRegistry
& scriptRegistry
= gEnv
->pSchematyc2
->GetScriptRegistry();
83 const IScriptFile
* pRefFile
= scriptRegistry
.GetFile(m_refGUID
);
86 pRefFile
= scriptRegistry
.LoadFile(m_fileName
.c_str());
89 m_refGUID
= pRefFile
->GetGUID();
92 //////////////////////////////////////////////////
95 case ESerializationPass::Save
:
97 archive(m_guid
, "guid");
98 archive(m_scopeGUID
, "scope_guid");
99 archive(m_fileName
, "fileName");
100 archive(m_refGUID
, "refGUID");
103 case ESerializationPass::Edit
:
105 archive(m_fileName
, "fileName", "!FileName");
111 //////////////////////////////////////////////////////////////////////////
112 void CScriptInclude::RemapGUIDs(IGUIDRemapper
& guidRemapper
)
114 m_guid
= guidRemapper
.Remap(m_guid
);
115 m_scopeGUID
= guidRemapper
.Remap(m_scopeGUID
);
116 m_refGUID
= guidRemapper
.Remap(m_refGUID
);
119 //////////////////////////////////////////////////////////////////////////
120 const char* CScriptInclude::GetFileName() const
122 return m_fileName
.c_str();
125 //////////////////////////////////////////////////////////////////////////
126 SGUID
CScriptInclude::GetRefGUID() const