diff options
author | Ash Wolf <ninji@wuffs.org> | 2023-06-28 22:22:32 +0100 |
---|---|---|
committer | Ash Wolf <ninji@wuffs.org> | 2023-06-28 22:22:32 +0100 |
commit | c0c336500955a23e344651e5412c9d9d441ef4ee (patch) | |
tree | 790769c748db307cf3314f6e896e2f61c68561a2 /src/T2DLL/T2MoverModuleList.cpp | |
parent | 37e364b2c6cc7487a1c888d256a73e5337bb7189 (diff) | |
download | t2win-c0c336500955a23e344651e5412c9d9d441ef4ee.tar.gz t2win-c0c336500955a23e344651e5412c9d9d441ef4ee.zip |
first pass of T2DLL
Diffstat (limited to '')
-rw-r--r-- | src/T2DLL/T2MoverModuleList.cpp | 102 |
1 files changed, 91 insertions, 11 deletions
diff --git a/src/T2DLL/T2MoverModuleList.cpp b/src/T2DLL/T2MoverModuleList.cpp index a0262cd..0629242 100644 --- a/src/T2DLL/T2MoverModuleList.cpp +++ b/src/T2DLL/T2MoverModuleList.cpp @@ -1,49 +1,129 @@ +#include "T2Archive.h" +#include "T2ElvModuleList.h" +#include "T2MoverDef.h" +#include "T2MoverModule.h" #include "T2MoverModuleList.h" +#include "T2StairModuleList.h" -T2MoverModuleList::T2MoverModuleList() { +T2MoverModuleList::T2MoverModuleList() + : LArray(sizeof(T2MoverModule *)) +{ + mMaxModule = 0; + mModuleCount = 0; + SetRect(&mBaseRect, 0, 0, 0, 0); } /*virtual*/ T2MoverModuleList::~T2MoverModuleList() { + LArrayIterator iterator(*this); + T2MoverModule *moverModule = NULL; + + while (iterator.Next(&moverModule)) { + if (moverModule) + delete moverModule; + } + + RemoveItemsAt(mItemCount, 1); } -/*virtual*/ int T2MoverModuleList::Init(T2MoverDef*, const RECT&) { +/*virtual*/ BOOL T2MoverModuleList::Init(T2MoverDef* moverDef, const RECT& baseRect) { + mMaxModule = moverDef->GetMaxModule(); + mModuleCount = 0; + mBaseRect = baseRect; + return true; } -int T2MoverModuleList::InsertModuleAt(int, T2MoverModule*) { +BOOL T2MoverModuleList::InsertModuleAt(int where, T2MoverModule* module) { + InsertItemsAt(1, where, &module); + return true; } void T2MoverModuleList::AllClear() { + RemoveItemsAt(mItemCount, 1); } -/*virtual*/ void T2MoverModuleList::Destruct(T2TowerDoc*) { +/*virtual*/ void T2MoverModuleList::Destruct(T2TowerDoc* towerDoc) { + LArrayIterator iterator(*this); + T2MoverModule *moverModule = NULL; + + while (iterator.Next(&moverModule)) { + if (moverModule) + RemoveModule(towerDoc, moverModule); + } } -/*virtual*/ void T2MoverModuleList::RemoveModule(T2TowerDoc*, T2MoverModule*) { +/*virtual*/ void T2MoverModuleList::RemoveModule(T2TowerDoc* towerDoc, T2MoverModule* moverModule) { + moverModule->RemoveContents(towerDoc); + Remove(&moverModule); + moverModule->SetUsed(false); + delete moverModule; } -/*virtual*/ void T2MoverModuleList::Read(T2Archive&, T2TowerDoc*) { +/*virtual*/ void T2MoverModuleList::Read(T2Archive& archive, T2TowerDoc* towerDoc) { + AllClear(); + + short v; + archive >> v; + mMaxModule = v; + + archive.ReadSRect(mBaseRect); } -/*virtual*/ void T2MoverModuleList::Write(T2Archive&) { +/*virtual*/ void T2MoverModuleList::Write(T2Archive& archive) { + archive << (short) mMaxModule; + archive.WriteSRect(mBaseRect); + + archive << mItemCount; + + LArrayIterator iterator(*this); + T2MoverModule *moverModule = NULL; + + while (iterator.Next(&moverModule)) + moverModule->Save(archive); } /*virtual*/ T2MoverModule* T2MoverModuleList::ConstructModule() { + return new T2MoverModule; } -/*virtual*/ void T2MoverModuleList::StopAdded(T2TowerDoc*, T2Mover*, int) { +/*virtual*/ void T2MoverModuleList::StopAdded(T2TowerDoc* towerDoc, T2Mover*, int) { } -/*virtual*/ void T2MoverModuleList::StopRemoved(T2TowerDoc*, T2Mover*, int) { +/*virtual*/ void T2MoverModuleList::StopRemoved(T2TowerDoc* towerDoc, T2Mover*, int) { } unsigned int T2MoverModuleList::GetItemCount() { + return GetCount(); } -/*static*/ T2MoverModuleList* T2MoverModuleList::ReadMMList(T2Archive&, T2TowerDoc*) { +/*static*/ T2MoverModuleList* T2MoverModuleList::ReadMMList(T2Archive& archive, T2TowerDoc* towerDoc) { + T2MoverModuleList *list = NULL; + + DWORD code; + archive >> code; + + if (code == '_MML') + list = new T2MoverModuleList; + else if (code == 'ElML') + list = new T2ElvModuleList; + else if (code == 'StML') + list = new T2StairModuleList; + + if (list) + list->Read(archive, towerDoc); + + return list; } -/*static*/ void T2MoverModuleList::WriteMMList(T2MoverModuleList*, T2Archive&) { +/*static*/ void T2MoverModuleList::WriteMMList(T2MoverModuleList* list, T2Archive& archive) { + if (!list) { + DWORD code = 'xMML'; + archive << code; + } else { + archive << list->GetMMClassID(); + list->Write(archive); + } } /*virtual*/ int T2MoverModuleList::GetModuleCount() const { + return mModuleCount; } |