Skip to content

Commit

Permalink
Encounters
Browse files Browse the repository at this point in the history
  • Loading branch information
myst6re committed May 26, 2022
1 parent 68e6f55 commit 6b76533
Show file tree
Hide file tree
Showing 15 changed files with 333 additions and 76 deletions.
6 changes: 6 additions & 0 deletions Deling.pro
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@ HEADERS += MainWindow.h \
BackgroundExporter.h \
EncounterExporter.h \
PreviewWidget.h \
game/worldmap/TexlFile.h \
game/worldmap/WmArchive.h \
game/worldmap/WmEncounter.h \
QLZ4.h \
ScriptExporter.h \
SearchAll.h \
Expand Down Expand Up @@ -127,6 +130,9 @@ SOURCES += MainWindow.cpp \
BackgroundExporter.cpp \
EncounterExporter.cpp \
PreviewWidget.cpp \
game/worldmap/TexlFile.cpp \
game/worldmap/WmArchive.cpp \
game/worldmap/WmEncounter.cpp \
QLZ4.cpp \
ScriptExporter.cpp \
SearchAll.cpp \
Expand Down
9 changes: 9 additions & 0 deletions files/TextureFile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,15 @@ const QImage &TextureFile::image() const
return _image;
}

QImage TextureFile::image(int colorTable) const
{
QImage ret = _image;

ret.setColorTable(_colorTables.at(colorTable));

return ret;
}

QImage *TextureFile::imagePtr()
{
return &_image;
Expand Down
1 change: 1 addition & 0 deletions files/TextureFile.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ class TextureFile : public File
bool isValid() const;
void clear();
const QImage &image() const;
QImage image(int colorTable) const;
QImage *imagePtr();
bool isPaletted() const;
const QList< QVector<QRgb> > &colorTables() const;
Expand Down
15 changes: 15 additions & 0 deletions game/worldmap/Map.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,18 @@ QList<WmEncounter> Map::encounters(quint8 region) const

return ret;
}

QList<QList<QImage> > Map::textureImages() const
{
QList<QList<QImage> > ret;

foreach (const TimFile &tim, _textures) {
QList<QImage> images;
for (int palID = 0; palID < tim.colorTableCount(); ++palID) {
images.append(tim.image(palID));
}
ret.append(images);
}

return ret;
}
11 changes: 11 additions & 0 deletions game/worldmap/Map.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#include <QtCore>
#include "game/worldmap/MapSegment.h"
#include "game/worldmap/WmEncounter.h"
#include "files/TimFile.h"

class Map
{
Expand Down Expand Up @@ -36,11 +37,21 @@ class Map
_encounterRegions = regions;
}

inline const QList<TimFile> &textures() const {
return _textures;
}

inline void setTextures(const QList<TimFile> &textures) {
_textures = textures;
}

QList<QList<QImage> > textureImages() const;

private:
QList<MapSegment> _segments;
QList<WmEncounter> _encounters;
QList<quint8> _encounterRegions;
QList<TimFile> _textures;
};

#endif // MAP_H
39 changes: 39 additions & 0 deletions game/worldmap/TexlFile.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
#include "TexlFile.h"

TexlFile::TexlFile(QIODevice *io) :
_io(io)
{
}

bool TexlFile::seekTexture(quint8 id)
{
return _io->seek(id * TEXLFILE_TEXTURE_SIZE);
}

bool TexlFile::readTexture(TimFile &tim)
{
QByteArray data = _io->read(TEXLFILE_TEXTURE_SIZE);

return tim.open(data);
}

bool TexlFile::readTextures(Map &map)
{
QList<TimFile> textures;

_io->reset();

for (int i = 0; i < TEXLFILE_TEXTURE_COUNT; ++i) {
TimFile tim;
if (!readTexture(tim)) {
qDebug() << "TexlFile::readTextures cannot read texture";
return false;
}

textures.append(tim);
}

map.setTextures(textures);

return true;
}
28 changes: 28 additions & 0 deletions game/worldmap/TexlFile.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
#ifndef TEXLFILE_H
#define TEXLFILE_H

#include <QtCore>
#include "game/worldmap/Map.h"
#include "files/TimFile.h"

#define TEXLFILE_TEXTURE_SIZE 0x12800
#define TEXLFILE_TEXTURE_COUNT 20

class TexlFile
{
public:
explicit TexlFile(QIODevice *io = Q_NULLPTR);
inline void setDevice(QIODevice *device) {
_io = device;
}

bool readTextures(Map &map);

private:
bool seekTexture(quint8 id);
bool readTexture(TimFile &tim);

QIODevice *_io;
};

#endif // TEXLFILE_H
90 changes: 90 additions & 0 deletions game/worldmap/WmArchive.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
#include "WmArchive.h"
#include "game/worldmap/WmsetFile.h"
#include "game/worldmap/WmxFile.h"
#include "game/worldmap/TexlFile.h"

WmArchive::WmArchive() :
_isOpen(false)
{
}

bool WmArchive::open(const QString &filename, Map &map, ArchiveObserver *progress)
{
if (progress) {
progress->setObserverMaximum(3);
}

QString archivePath = filename;
archivePath.chop(1);

if (!_fsArchive.open(archivePath)) {
_errorString = QObject::tr("Impossible d'ouvrir l'archive.");
return false;
}

if (!_fsArchive.fileExists("*world\\dat\\wmx.obj")) {
_errorString = QObject::tr("Pas une archive mappemonde.");
return false;
}

_isOpen = false;

WmxFile wmx;
WmsetFile wmset;
TexlFile texl;

QByteArray wmxData = _fsArchive.fileData("*world\\dat\\wmx.obj");
QBuffer wmxBuffer(&wmxData);
wmxBuffer.open(QIODevice::ReadOnly);
wmx.setDevice(&wmxBuffer);

if(!wmx.readSegments(map, 768)) {
_errorString = QObject::tr("Impossible de lire la mappemonde (1).");
return false;
}

wmxData.clear();

if (progress) {
progress->setObserverValue(1);
}

QByteArray wmsetData = _fsArchive.fileData("*world\\dat\\wmsetfr.obj");
QBuffer wmsetBuffer(&wmsetData);
wmsetBuffer.open(QIODevice::ReadOnly);
wmset.setDevice(&wmsetBuffer);

if (!wmset.readEncounterRegions(map)) {
_errorString = QObject::tr("Impossible de lire la mappemonde (2).");
return false;
}

if (!wmset.readEncounters(map)) {
_errorString = QObject::tr("Impossible de lire la mappemonde (3).");
return false;
}

wmsetData.clear();

if (progress) {
progress->setObserverValue(2);
}

QByteArray texlData = _fsArchive.fileData("*world\\dat\\texl.obj");
QBuffer texlBuffer(&texlData);
texlBuffer.open(QIODevice::ReadOnly);
texl.setDevice(&texlBuffer);

if (!texl.readTextures(map)) {
_errorString = QObject::tr("Impossible de lire la mappemonde (4).");
return false;
}

if (progress) {
progress->setObserverValue(3);
}

_isOpen = true;

return true;
}
22 changes: 22 additions & 0 deletions game/worldmap/WmArchive.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#ifndef WMARCHIVE_H
#define WMARCHIVE_H

#include "game/worldmap/Map.h"
#include "ArchiveObserver.h"
#include "FsArchive.h"

class WmArchive
{
public:
WmArchive();
bool open(const QString &filename, Map &map, ArchiveObserver *progress);
inline const QString &errorString() const {
return _errorString;
}
private:
bool _isOpen;
QString _errorString;
FsArchive _fsArchive;
};

#endif // WMARCHIVE_H
6 changes: 3 additions & 3 deletions game/worldmap/WmxFile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ bool WmxFile::seekSegment(int segment)

bool WmxFile::readSegments(Map &map, int segmentCount)
{
_collect.clear();
//_collect.clear();

QList<MapSegment> segments;
bool toTheEnd = segmentCount < 0;
Expand All @@ -89,9 +89,9 @@ bool WmxFile::readSegments(Map &map, int segmentCount)

map.setSegments(segments);

QList<int> collect = _collect.values();
/* QList<int> collect = _collect.values();
qSort(collect);
qDebug() << _collect << collect.last();
qDebug() << _collect << collect.last(); */

return true;
}
Expand Down
2 changes: 1 addition & 1 deletion game/worldmap/WmxFile.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ class WmxFile
bool writeVertex(const MapBlockVertex &polygon);

QIODevice *_io;
QMap<quint32, int> _collect;
//QMap<quint32, int> _collect;
};

#endif // WMXFILE_H
20 changes: 17 additions & 3 deletions main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@
#include "ProgressWidget.h"
#include "widgets/WorldmapWidget.h"
#include "game/worldmap/WmxFile.h"
#include "game/worldmap/TexlFile.h"
#include "QLZ4.h"

// Only for static compilation
//Q_IMPORT_PLUGIN(qjpcodecs) // jp encoding
Expand All @@ -39,7 +41,6 @@ int main(int argc, char *argv[])
#if (QT_VERSION < QT_VERSION_CHECK(5, 0, 0))
QTextCodec::setCodecForTr(QTextCodec::codecForName("UTF-8"));
#endif

/* QFile objFile("E:/Documents/Deling-build-desktop/wm/game/wmsetfr.obj");
WmsetFile obj(&objFile);
if (objFile.open(QIODevice::ReadOnly)) {
Expand Down Expand Up @@ -75,15 +76,25 @@ int main(int argc, char *argv[])
if(argc>1)
window->openFile(argv[1]);

/* QFile f1("E:/Documents/hyne/autres/ff8slot00_switch_version.dat");
f1.open(QIODevice::ReadOnly);
QFile f2("E:/Documents/hyne/autres/ff8slot00_switch_version.dat.dec");
f2.open(QIODevice::WriteOnly);
f2.write(QLZ4::decompressAll(f1.readAll()));
Map map1, map2;
WmxFile wmx;
WmsetFile wmset;
TexlFile texl;
QFile file("E:/Documents/Deling-build-desktop/wm/game/wmx.obj");
file.open(QIODevice::ReadOnly);
QFile file2("E:/Documents/Deling-build-desktop/wm/game/wmsetfr.obj");
file2.open(QIODevice::ReadOnly);
QFile file3("E:/Documents/Deling-build-desktop/wm/game/texl.obj");
file3.open(QIODevice::ReadOnly);
wmx.setDevice(&file);
wmset.setDevice(&file2);
texl.setDevice(&file3);
if(!wmx.readSegments(map1, 768)) {
qWarning() << "Cannot read segments 1";
} else {
Expand All @@ -93,10 +104,13 @@ int main(int argc, char *argv[])
if (!wmset.readEncounters(map1)) {
qWarning() << "Cannot read encounters";
}
if (!texl.readTextures(map1)) {
qWarning() << "Cannot read textures";
}
WorldmapWidget *wmWidget = new WorldmapWidget();
wmWidget->resize(640, 480);
wmWidget->show();
wmWidget->setMap(&map1);
wmWidget->setMap(&map1); */

// wmWidget->scene()->setLimits(QRect(10, 0, 1, 1));

Expand Down Expand Up @@ -141,7 +155,7 @@ int main(int argc, char *argv[])
// wmWidget->scene()->renderPixmap(scale, scale)
*/
}
//}


/* if(!wmx.readSegments(map2)) {
Expand Down
Loading

0 comments on commit 6b76533

Please sign in to comment.