summaryrefslogtreecommitdiff
path: root/src/T2DLL/T2MoverModuleList.cpp
blob: 9711ec45f49efc34704110db73f428d0e4db174d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
#include "T2Archive.h"
#include "T2ElvModuleList.h"
#include "T2MoverDef.h"
#include "T2MoverModule.h"
#include "T2MoverModuleList.h"
#include "T2StairModuleList.h"

T2MoverModuleList::T2MoverModuleList()
    : LArray(sizeof(T2MoverModule *))
{
    mMaxModule = 0;
    mModuleCount = 0;
    SetRect(&mBaseRect, 0, 0, 0, 0);
}

/*virtual*/ T2MoverModuleList::~T2MoverModuleList() {
    LArrayIterator iterator(*this);
    T2MoverModule *theMoverModule = NULL;

    while (iterator.Next(&theMoverModule)) {
        if (theMoverModule)
            delete theMoverModule;
    }

    RemoveItemsAt(mItemCount, 1);
}

/*virtual*/ BOOL T2MoverModuleList::Init(T2MoverDef* moverDef, const RECT& baseRect) {
    mMaxModule = moverDef->GetMaxModule();
    mModuleCount = 0;
    mBaseRect = baseRect;
    return true;
}

BOOL T2MoverModuleList::InsertModuleAt(int where, T2MoverModule* module) {
    InsertItemsAt(1, where, &module);
    return true;
}

void T2MoverModuleList::AllClear() {
    RemoveItemsAt(mItemCount, 1);
}

/*virtual*/ void T2MoverModuleList::Destruct(T2TowerDoc* towerDoc) {
    LArrayIterator iterator(*this);
    T2MoverModule *theMoverModule = NULL;

    while (iterator.Next(&theMoverModule)) {
        if (theMoverModule)
            RemoveModule(towerDoc, theMoverModule);
    }
}

/*virtual*/ void T2MoverModuleList::RemoveModule(T2TowerDoc* towerDoc, T2MoverModule* moverModule) {
    moverModule->RemoveContents(towerDoc);
    Remove(&moverModule);
    moverModule->SetUsed(false);
    delete moverModule;
}

/*virtual*/ void T2MoverModuleList::Read(T2Archive& archive, T2TowerDoc* towerDoc) {
    AllClear();

    short v;
    archive >> v;
    mMaxModule = v;

    archive.ReadSRect(mBaseRect);
}

/*virtual*/ void T2MoverModuleList::Write(T2Archive& archive) {
    archive << (short) mMaxModule;
    archive.WriteSRect(mBaseRect);

    archive << mItemCount;

    LArrayIterator iterator(*this);
    T2MoverModule *theMoverModule = NULL;

    while (iterator.Next(&theMoverModule))
        theMoverModule->Save(archive);
}

/*virtual*/ T2MoverModule* T2MoverModuleList::ConstructModule() {
    return new T2MoverModule;
}

/*virtual*/ void T2MoverModuleList::StopAdded(T2TowerDoc* towerDoc, T2Mover*, int) {
}

/*virtual*/ void T2MoverModuleList::StopRemoved(T2TowerDoc* towerDoc, T2Mover*, int) {
}

unsigned int T2MoverModuleList::GetItemCount() {
    return GetCount();
}

/*static*/ T2MoverModuleList* T2MoverModuleList::ReadMMList(T2Archive& archive, T2TowerDoc* towerDoc) {
    T2MoverModuleList *theList = NULL;

    DWORD classID;
    archive >> classID;

    if (classID == '_MML')
        theList = new T2MoverModuleList;
    else if (classID == 'ElML')
        theList = new T2ElvModuleList;
    else if (classID == 'StML')
        theList = new T2StairModuleList;

    if (theList)
        theList->Read(archive, towerDoc);

    return theList;
}

/*static*/ void T2MoverModuleList::WriteMMList(T2MoverModuleList* list, T2Archive& archive) {
    if (!list) {
        DWORD code = 'xMML';
        archive << code;
    } else {
        archive << list->GetMMClassID();
        list->Write(archive);
    }
}

inline /*virtual*/ int T2MoverModuleList::GetModuleCount() const {
    return mModuleCount;
}