sm64coopdx/data/dynos_bin_lights.cpp

70 lines
1.8 KiB
C++
Raw Permalink Normal View History

2022-04-02 00:19:26 +00:00
#include "dynos.cpp.h"
/////////////
// Parsing //
/////////////
DataNode<Lights1>* DynOS_Lights_Parse(GfxData* aGfxData, DataNode<Lights1>* aNode) {
if (aNode->mData) return aNode;
// Check tokens count
if (aNode->mTokens.Count() < 10) {
PrintDataError(" ERROR: %s: not enough data", aNode->mName.begin());
2022-04-02 00:19:26 +00:00
return aNode;
}
// Parse def token
if (aNode->mTokens[0] != "gdSPDefLights1") {
PrintDataError(" ERROR: Invalid def token: should be gdSPDefLights1, is %s", aNode->mTokens[0].begin());
2022-04-02 00:19:26 +00:00
return aNode;
}
// Parse data tokens
u8 ar = (u8) aNode->mTokens[1].ParseInt();
u8 ag = (u8) aNode->mTokens[2].ParseInt();
u8 ab = (u8) aNode->mTokens[3].ParseInt();
u8 r1 = (u8) aNode->mTokens[4].ParseInt();
u8 g1 = (u8) aNode->mTokens[5].ParseInt();
u8 b1 = (u8) aNode->mTokens[6].ParseInt();
s8 x1 = (s8) aNode->mTokens[7].ParseInt();
s8 y1 = (s8) aNode->mTokens[8].ParseInt();
s8 z1 = (s8) aNode->mTokens[9].ParseInt();
aNode->mData = New<Lights1>();
*aNode->mData = gdSPDefLights1(ar, ag, ab, r1, g1, b1, x1, y1, z1);
aNode->mLoadIndex = aGfxData->mLoadIndex++;
return aNode;
}
2022-04-02 02:50:42 +00:00
/////////////
// Writing //
/////////////
2022-06-25 07:52:53 +00:00
void DynOS_Lights_Write(BinFile* aFile, GfxData* aGfxData, DataNode<Lights1> *aNode) {
2022-04-02 02:50:42 +00:00
if (!aNode->mData) return;
// Header
2022-06-25 07:52:53 +00:00
aFile->Write<u8>(DATA_TYPE_LIGHT);
2022-04-02 02:50:42 +00:00
aNode->mName.Write(aFile);
// Data
2022-06-25 07:52:53 +00:00
aFile->Write<Lights1>(*aNode->mData);
2022-04-02 02:50:42 +00:00
}
/////////////
// Reading //
/////////////
2022-06-25 07:52:53 +00:00
void DynOS_Lights_Load(BinFile *aFile, GfxData *aGfxData) {
2022-04-02 02:50:42 +00:00
DataNode<Lights1> *_Node = New<DataNode<Lights1>>();
// Name
_Node->mName.Read(aFile);
// Data
_Node->mData = New<Lights1>();
2022-06-25 07:52:53 +00:00
*_Node->mData = aFile->Read<Lights1>();
2022-04-02 02:50:42 +00:00
// Append
aGfxData->mLights.Add(_Node);
}