added animation

but not full in ADeditor
This commit is contained in:
2010-09-05 16:25:23 +04:00
parent c898f978da
commit 8fa6b8e2a6
24 changed files with 924 additions and 725 deletions

View File

@@ -21,6 +21,7 @@ void Loader::load(QString filename)
file->close();
qFatal("Error parsing data.xml");
}
readAnimations();
readAliens();
readMaps();
readLevels();
@@ -206,6 +207,7 @@ void Loader::save(QString filename)
{
case srcTriggerType::onTimer :
elem.setAttribute("type","onTimer");
elem.setAttribute("timer",trig.timer);
break;
case srcTriggerType::onDestination :
elem.setAttribute("type","onDestination");
@@ -238,6 +240,16 @@ void Loader::save(QString filename)
elem.setAttribute("level",tol.levelId);
elem.setAttribute("tower",tol.towerId);
}
child = data.createElement("animations");
root.appendChild(child);
for (int i=0; i<animations.size(); i++)
{
tbAnimation ta = animations.values().at(i);
elem = data.createElement("animation");
child.appendChild(elem);
elem.setAttribute("id",ta.id);
elem.setAttribute("pathes",ta.pathes.join(";"));
}
cfile.write(data.toByteArray());
cfile.close();
//qDebug() << data.toByteArray();
@@ -268,6 +280,7 @@ Game_Data * Loader::loadlevel(int id)
tbWavePart tbwpt;
QList <tbWavePart> wplist;
QList <int> alienIds;
QList <int> animIds;
for (int i=0; i<wollist.size(); ++i)
{
WaveType wt;
@@ -304,7 +317,9 @@ Game_Data * Loader::loadlevel(int id)
tbAlien tbal = aliens.value(alienIds.at(i));
salt.armor = tbal.armor;
salt.health = tbal.health;
salt.imgType = tbal.imgType;
if (!animIds.contains(tbal.imgType))
animIds.append(tbal.imgType);
salt.imgType = animIds.indexOf(tbal.imgType);
salt.isFlying = tbal.isFlying;
salt.name = tbal.name;
salt.prise = tbal.prise;
@@ -325,7 +340,9 @@ Game_Data * Loader::loadlevel(int id)
stt.expByDamage = tbt.expByDamage;
stt.expByKill = tbt.expByKill;
stt.expByShot = tbt.expByShot;
stt.imgType = tbt.imgType;
if (!animIds.contains(tbt.imgType))
animIds.append(tbt.imgType);
stt.imgType = animIds.indexOf(tbt.imgType);
stt.name = tbt.name;
stt.radius = tbt.radius;
stt.reload = tbt.reload;
@@ -334,22 +351,35 @@ Game_Data * Loader::loadlevel(int id)
tbSplash tbs = splashes.value(tbt.splashId);
srcSplashType sst;
sst.autoControl = tbs.autoControl;
sst.imgType = tbs.imgType;
if (!animIds.contains(tbs.imgType))
animIds.append(tbs.imgType);
sst.imgType = animIds.indexOf(tbs.imgType);
sst.lifetime = tbs.lifetime;
sst.name = tbs.name;
sst.speed = tbs.speed;
stt.splashes.append(sst);
int recursiveCheck = 1;
fillTowerChains(&chlist,&trigIds,&stt,tbt.splashId,0,&recursiveCheck);
fillTowerChains(&animIds,&chlist,&trigIds,&stt,
tbt.splashId,0,&recursiveCheck);
for (int k=0; k<map->maxPlayers(); ++k)
gd->players[k]->srcTowers.append(stt);
qDebug() << tr("Tower %1 trig=%2 splash=%3").arg(stt.name).arg(stt.triggers.size()).arg(stt.splashes.size()) << tr("chain lenght %1").arg(recursiveCheck);
}
for (int i=0; i<animIds.size(); i++)
{
AnimationType anim;
for (int k=0; k<animations.value(animIds.at(i)).pathes.size(); k++)
anim.images.append(new QImage(animations.value(animIds.at(i))
.pathes.at(k)));
gd->curAnimations.append(anim);
}
return gd;
}
void Loader::fillTowerChains(QList <tbChain> * chlist, QList <int> * trigIds, srcTowerType * stt, int parId, int parIndex, int * recursiveCheck)
void Loader::fillTowerChains(QList <int> * animIds, QList <tbChain> * chlist,
QList <int> * trigIds, srcTowerType * stt,
int parId, int parIndex, int * recursiveCheck)
{
if (*recursiveCheck > 100)
{
@@ -385,14 +415,16 @@ void Loader::fillTowerChains(QList <tbChain> * chlist, QList <int> * trigIds, sr
tbSplash tbs = splashes.value(chlist->at(i).childSplashId);
srcSplashType sst;
sst.autoControl = tbs.autoControl;
sst.imgType = tbs.imgType;
if (!animIds->contains(tbs.imgType))
animIds->append(tbs.imgType);
sst.imgType = animIds->indexOf(tbs.imgType);
sst.lifetime = tbs.lifetime;
sst.name = tbs.name;
sst.speed = tbs.speed;
stt->splashes.append(sst);
stt->triggers[stt->splashes.at(parIndex).triggerIndexes.size()-1].childId = stt->splashes.size() - 1;
*recursiveCheck += 1;
fillTowerChains(chlist,trigIds,stt,chlist->at(i).childSplashId, stt->splashes.size()-1,recursiveCheck);
fillTowerChains(animIds,chlist,trigIds,stt,chlist->at(i).childSplashId, stt->splashes.size()-1,recursiveCheck);
}
}
}
@@ -441,21 +473,30 @@ void Loader::readAliens()
QDomNodeList alelems = doc->elementsByTagName("alien");
for (int i=0; i<alelems.size(); i++)
{
bool OK = true;
tbAlien al;
QDomNamedNodeMap nm = alelems.at(i).attributes();
al.id = nm.namedItem("id").nodeValue().toInt();
if (aliens.contains(al.id)) qCritical("Same alien ID dedected, replacing...");
if (aliens.contains(al.id)) qCritical("Same alien ID detected, replacing...");
al.name = nm.namedItem("name").nodeValue();
al.speed = nm.namedItem("speed").nodeValue().toFloat();
al.health = nm.namedItem("health").nodeValue().toFloat();
al.prise = nm.namedItem("prise").nodeValue().toInt();
al.armor = nm.namedItem("armor").nodeValue().toFloat();
al.imgType = nm.namedItem("imageType").nodeValue().toInt();
if (!animations.contains(al.imgType))
{
qCritical("Invalid animation Id");
OK = false;
}
al.regeneration = nm.namedItem("regeneration").nodeValue().toFloat();
al.score = nm.namedItem("score").nodeValue().toInt();
al.isFlying = (nm.namedItem("flying").nodeValue() == "true");
aliens.insert(al.id,al);
//qDebug() << tr("Alien %1 id=%2 health=%3 speed=%4 prise=%5 imgType=%6 armor=%7 regeneration=%8 score=%10").arg(al.name).arg(al.id).arg(al.health).arg(al.speed).arg(al.prise).arg(al.imgType).arg(al.armor).arg(al.regeneration).arg(al.score);
if (OK)
{
aliens.insert(al.id,al);
//qDebug() << tr("Alien %1 id=%2 health=%3 speed=%4 prise=%5 imgType=%6 armor=%7 regeneration=%8 score=%10").arg(al.name).arg(al.id).arg(al.health).arg(al.speed).arg(al.prise).arg(al.imgType).arg(al.armor).arg(al.regeneration).arg(al.score);
}
}
//qDebug("================");
qDebug() << tr("Found %1 aliens").arg(aliens.size());
@@ -472,7 +513,7 @@ void Loader::readWaves()
tbWave w;
QDomNamedNodeMap nm = welems.at(i).attributes();
w.id = nm.namedItem("id").nodeValue().toInt();
if (waves.contains(w.id)) qCritical("Same wave ID dedected, replacing...");
if (waves.contains(w.id)) qCritical("Same wave ID detected, replacing...");
w.prise = nm.namedItem("prise").nodeValue().toInt();
w.timeout = nm.namedItem("timeout").nodeValue().toInt();
waves.insert(w.id,w);
@@ -643,7 +684,7 @@ void Loader::readLevels()
QDomNamedNodeMap nm = lelems.at(i).attributes();
l.id = nm.namedItem("id").nodeValue().toInt();
l.name = nm.namedItem("name").nodeValue();
if (levels.contains(l.id)) qCritical("Same wave ID dedected, replacing...");
if (levels.contains(l.id)) qCritical("Same wave ID detected, replacing...");
l.mapId = nm.namedItem("map").nodeValue().toInt();
if (!maps.contains(l.mapId))
{
@@ -672,7 +713,7 @@ void Loader::readTriggers()
tbTrigger trig;
QDomNamedNodeMap nm = trelems.at(i).attributes();
trig.id = nm.namedItem("id").nodeValue().toInt();
if (triggers.contains(trig.id)) qCritical("Same splash ID dedected, replacing...");
if (triggers.contains(trig.id)) qCritical("Same splash ID detected, replacing...");
trig.name = nm.namedItem("name").nodeValue();
trig.damage = nm.namedItem("damage").nodeValue().toFloat();
trig.radius = nm.namedItem("radius").nodeValue().toFloat();
@@ -715,18 +756,27 @@ void Loader::readSplashes()
QDomNodeList selems = doc->elementsByTagName("splash");
for (int i=0; i<selems.size(); i++)
{
bool OK = true;
tbSplash s;
QDomNamedNodeMap nm = selems.at(i).attributes();
s.id = nm.namedItem("id").nodeValue().toInt();
if (splashes.contains(s.id)) qCritical("Same splash ID dedected, replacing...");
if (splashes.contains(s.id)) qCritical("Same splash ID detected, replacing...");
s.name = nm.namedItem("name").nodeValue();
s.speed = nm.namedItem("speed").nodeValue().toFloat();
s.lifetime = nm.namedItem("lifetime").nodeValue().toInt();
s.imgType = nm.namedItem("imageType").nodeValue().toInt();
if (!animations.contains(s.imgType))
{
qCritical("Invalid animation ID");
OK = false;
}
str = nm.namedItem("autoControl").nodeValue();
s.autoControl = (str == "true");
splashes.insert(s.id,s);
//qDebug() << tr("Splash %1 id=%2 speed=%3 imgType=%4 autoControl=%5 lifetime=%6").arg(s.name).arg(s.id).arg(s.speed).arg(s.imgType).arg(s.autoControl).arg(s.lifetime);
if (OK)
{
splashes.insert(s.id,s);
//qDebug() << tr("Splash %1 id=%2 speed=%3 imgType=%4 autoControl=%5 lifetime=%6").arg(s.name).arg(s.id).arg(s.speed).arg(s.imgType).arg(s.autoControl).arg(s.lifetime);
}
}
//qDebug("================");
qDebug() << tr("Found %1 splashes").arg(splashes.size());
@@ -734,6 +784,24 @@ void Loader::readSplashes()
}
void Loader::readAnimations()
{
animations.clear();
QDomNodeList animelems = doc->elementsByTagName("animation");
for (int i=0; i<animelems.size(); i++)
{
tbAnimation anim;
QDomNamedNodeMap nm = animelems.at(i).attributes();
anim.id = nm.namedItem("id").nodeValue().toInt();
if (animations.contains(anim.id)) qCritical("Same animation ID detected, replacing...");
anim.pathes = nm.namedItem("pathes").nodeValue().split(";");
animations.insert(anim.id,anim);
qDebug() << tr("animation id=%1 pathes=%2").arg(anim.id).arg(anim.pathes.join(";"));
}
qDebug() << tr("Found %1 animations").arg(animations.size());
}
void Loader::readTowers()
{
towers.clear();
@@ -744,13 +812,18 @@ void Loader::readTowers()
tbTower tw;
QDomNamedNodeMap nm = twelems.at(i).attributes();
tw.id = nm.namedItem("id").nodeValue().toInt();
if (towers.contains(tw.id)) qCritical("Same tower ID dedected, replacing...");
if (towers.contains(tw.id)) qCritical("Same tower ID detected, replacing...");
tw.name = nm.namedItem("name").nodeValue();
tw.radius = nm.namedItem("radius").nodeValue().toFloat();
tw.expByDamage = nm.namedItem("expByDamage").nodeValue().toFloat();
tw.expByKill = nm.namedItem("expByKill").nodeValue().toFloat();
tw.expByShot = nm.namedItem("expByShot").nodeValue().toFloat();
tw.imgType = nm.namedItem("imageType").nodeValue().toInt();
if (!animations.contains(tw.imgType))
{
qCritical("Invalid animation ID");
OK = false;
}
tw.reload = nm.namedItem("reload").nodeValue().toInt();
tw.cost = nm.namedItem("cost").nodeValue().toInt();
tw.buildTime = nm.namedItem("buildTime").nodeValue().toInt();
@@ -782,7 +855,7 @@ void Loader::readMaps()
tbMap m;
QDomNamedNodeMap mn = melems.at(i).attributes();
m.id = mn.namedItem("id").nodeValue().toInt();
if (maps.contains(m.id)) qCritical("Same map ID dedected, replacing...");
if (maps.contains(m.id)) qCritical("Same map ID detected, replacing...");
m.name = mn.namedItem("name").nodeValue();
m.imgType = mn.namedItem("imageType").nodeValue().toInt();
m.maxPlayers = mn.namedItem("maxPlayers").nodeValue().toInt();