mirror of
https://github.com/AxioDL/PrimeWorldEditor.git
synced 2025-12-20 18:29:13 +00:00
Tweak loader for MP1
This commit is contained in:
40
src/Core/Tweaks/CTweakData.h
Normal file
40
src/Core/Tweaks/CTweakData.h
Normal file
@@ -0,0 +1,40 @@
|
||||
#ifndef CTWEAKDATA_H
|
||||
#define CTWEAKDATA_H
|
||||
|
||||
#include "Core/Resource/CResource.h"
|
||||
#include "Core/Resource/Script/CScriptTemplate.h"
|
||||
#include "Core/Resource/Script/Property/TPropertyRef.h"
|
||||
|
||||
/** Tweak data assets for MP1 */
|
||||
class CTweakData : public CResource
|
||||
{
|
||||
DECLARE_RESOURCE_TYPE(Tweaks)
|
||||
|
||||
/** Script template specifying tweak data layout */
|
||||
CScriptTemplate* mpTemplate;
|
||||
|
||||
/** Tweak data */
|
||||
std::vector<uint8> mTweakData;
|
||||
|
||||
public:
|
||||
CTweakData(CScriptTemplate* pTemplate, CResourceEntry* pEntry = 0)
|
||||
: mpTemplate(pTemplate)
|
||||
, CResource(pEntry)
|
||||
{
|
||||
CStructProperty* pProperties = pTemplate->Properties();
|
||||
mTweakData.resize(pProperties->DataSize());
|
||||
pProperties->Construct(mTweakData.data());
|
||||
}
|
||||
|
||||
inline CScriptTemplate* TweakTemplate() const
|
||||
{
|
||||
return mpTemplate;
|
||||
}
|
||||
|
||||
inline CStructRef TweakData() const
|
||||
{
|
||||
return CStructRef((void*) mTweakData.data(), mpTemplate->Properties());
|
||||
}
|
||||
};
|
||||
|
||||
#endif // CTWEAKDATA_H
|
||||
54
src/Core/Tweaks/CTweakLoader.cpp
Normal file
54
src/Core/Tweaks/CTweakLoader.cpp
Normal file
@@ -0,0 +1,54 @@
|
||||
#include "CTweakLoader.h"
|
||||
#include "Core/Resource/Factory/CScriptLoader.h"
|
||||
#include "Core/Resource/Script/NGameList.h"
|
||||
|
||||
CTweakData* CTweakLoader::LoadCTWK(IInputStream& CTWK, CResourceEntry* pEntry)
|
||||
{
|
||||
// Find the correct template based on the asset ID.
|
||||
static const std::unordered_map<uint, const char*> skIdToTemplateName =
|
||||
{
|
||||
{ 0x1D180D7C, "TweakParticle" },
|
||||
{ 0x264A4972, "TweakPlayer" },
|
||||
{ 0x33B3323A, "TweakGunRes" },
|
||||
{ 0x39AD28D3, "TweakCameraBob" },
|
||||
{ 0x3FAEC012, "TweakPlayerControls", },
|
||||
{ 0x5ED56350, "TweakBall", },
|
||||
{ 0x5F24EFF8, "TweakSlideShow", },
|
||||
{ 0x6907A32D, "TweakPlayerGun", },
|
||||
{ 0x85CA11E9, "TweakPlayerRes", },
|
||||
{ 0x94C76ECD, "TweakTargeting", },
|
||||
{ 0x953A7C63, "TweakGame", },
|
||||
{ 0xC9954E56, "TweakGuiColors", },
|
||||
{ 0xE66A4F86, "TweakAutoMapper", },
|
||||
{ 0xED2E48A9, "TweakGui", },
|
||||
{ 0xF1ED8FD7, "TweakPlayerControls", }
|
||||
};
|
||||
|
||||
auto Find = skIdToTemplateName.find( pEntry->ID().ToLong() );
|
||||
ASSERT( Find != skIdToTemplateName.end() );
|
||||
const char* pkTemplateName = Find->second;
|
||||
|
||||
// Fetch template
|
||||
CGameTemplate* pGameTemplate = NGameList::GetGameTemplate( pEntry->Game() );
|
||||
ASSERT( pGameTemplate != nullptr );
|
||||
|
||||
CScriptTemplate* pTweakTemplate = pGameTemplate->FindMiscTemplate(pkTemplateName);
|
||||
ASSERT( pTweakTemplate != nullptr );
|
||||
|
||||
// Load tweak data
|
||||
CTweakData* pTweakData = new CTweakData(pTweakTemplate, pEntry);
|
||||
CScriptLoader::LoadStructData( CTWK, pTweakData->TweakData() );
|
||||
|
||||
// Verify
|
||||
if (!CTWK.EoF() && CTWK.PeekShort() != -1)
|
||||
{
|
||||
errorf("%s: unread property data, tweak template may be malformed (%d bytes left)", *CTWK.GetSourceString(), CTWK.Size() - CTWK.Tell());
|
||||
}
|
||||
|
||||
return pTweakData;
|
||||
}
|
||||
|
||||
void CTweakLoader::LoadNTWK(IInputStream& NTWK, std::vector<CTweakData*>& OutTweaks)
|
||||
{
|
||||
// Unimplemented
|
||||
}
|
||||
18
src/Core/Tweaks/CTweakLoader.h
Normal file
18
src/Core/Tweaks/CTweakLoader.h
Normal file
@@ -0,0 +1,18 @@
|
||||
#ifndef CTWEAKLOADER_H
|
||||
#define CTWEAKLOADER_H
|
||||
|
||||
#include "CTweakData.h"
|
||||
|
||||
/** Class responsible for loading tweak data */
|
||||
class CTweakLoader
|
||||
{
|
||||
/** Private constructor */
|
||||
CTweakLoader() {}
|
||||
|
||||
public:
|
||||
/** Loader entry point */
|
||||
static CTweakData* LoadCTWK(IInputStream& CTWK, CResourceEntry* pEntry);
|
||||
static void LoadNTWK(IInputStream& NTWK, std::vector<CTweakData*>& OutTweaks);
|
||||
};
|
||||
|
||||
#endif // CTWEAKLOADER_H
|
||||
33
src/Core/Tweaks/CTweakManager.cpp
Normal file
33
src/Core/Tweaks/CTweakManager.cpp
Normal file
@@ -0,0 +1,33 @@
|
||||
#include "CTweakManager.h"
|
||||
#include "Core/GameProject/CGameProject.h"
|
||||
#include "Core/GameProject/CResourceIterator.h"
|
||||
|
||||
CTweakManager::CTweakManager(CGameProject* pInProject)
|
||||
: mpProject(pInProject)
|
||||
{
|
||||
}
|
||||
|
||||
void CTweakManager::LoadTweaks()
|
||||
{
|
||||
// MP1 - Load all tweak assets into memory
|
||||
if (mpProject->Game() <= EGame::Prime)
|
||||
{
|
||||
for (TResourceIterator<EResourceType::Tweaks> It(mpProject->ResourceStore()); It; ++It)
|
||||
{
|
||||
CTweakData* pTweaks = (CTweakData*) It->Load();
|
||||
mTweakObjects.push_back(pTweaks);
|
||||
}
|
||||
}
|
||||
|
||||
// MP2+ - Not supported, but tweaks are stored in Standard.ntwk
|
||||
else
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
void CTweakManager::SaveTweaks()
|
||||
{
|
||||
// In MP1, to save an individual tweak asset, just call Tweak->Entry()->Save()
|
||||
// In MP2+, call this function.
|
||||
//@todo
|
||||
}
|
||||
27
src/Core/Tweaks/CTweakManager.h
Normal file
27
src/Core/Tweaks/CTweakManager.h
Normal file
@@ -0,0 +1,27 @@
|
||||
#ifndef CTWEAKMANAGER_H
|
||||
#define CTWEAKMANAGER_H
|
||||
|
||||
#include "CTweakData.h"
|
||||
|
||||
/** Class responsible for managing game tweak data, including saving/loading and providing access */
|
||||
class CTweakManager
|
||||
{
|
||||
/** Project */
|
||||
CGameProject* mpProject;
|
||||
|
||||
/** All tweak resources in the current game */
|
||||
std::vector< TResPtr<CTweakData> > mTweakObjects;
|
||||
|
||||
public:
|
||||
CTweakManager(CGameProject* pInProject);
|
||||
void LoadTweaks();
|
||||
void SaveTweaks();
|
||||
|
||||
// Accessors
|
||||
inline const std::vector< TResPtr<CTweakData> >& TweakObjects() const
|
||||
{
|
||||
return mTweakObjects;
|
||||
}
|
||||
};
|
||||
|
||||
#endif // CTWEAKMANAGER_H
|
||||
Reference in New Issue
Block a user