Skip to content

Commit

Permalink
Use Unix Style Line Endings
Browse files Browse the repository at this point in the history
  • Loading branch information
sithlord48 committed Mar 9, 2023
1 parent ce5b246 commit 9566d43
Show file tree
Hide file tree
Showing 20 changed files with 2,720 additions and 2,720 deletions.
154 changes: 77 additions & 77 deletions src/formats/TblFile.cpp
Original file line number Diff line number Diff line change
@@ -1,77 +1,77 @@
/****************************************************************************/
// copyright 2009 - 2022 Arzel Jérôme <[email protected]> //
// //
// This file is part of FF7tk //
// //
// FF7tk is free software: you can redistribute it and/or modify //
// it under the terms of the GNU General Public License as published by //
// the Free Software Foundation, either version 3 of the License, or //
// (at your option) any later version. //
// //
// FF7tk is distributed in the hope that it will be useful, //
// but WITHOUT ANY WARRANTY; without even the implied warranty of //
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the //
// GNU General Public License for more details. //
/****************************************************************************/
#include <TblFile.h>

TblFile::TblFile()
{
}

bool TblFile::open(const QByteArray &data)
{
if (data.size() % 24 != 0)
return false;
qsizetype entryCount = data.size() / 24;
const char *constData = data.constData();
for (int i = 0; i < entryCount; ++i) {
TblFileEntry entry;
for (int j = 0; j < 2; ++j) {
memcpy(entry.wm2Field + j, constData, sizeof(WorldToField));
constData += 12;
}
_entries.append(entry);
}
return true;
}

QByteArray TblFile::save() const
{
QByteArray data;
for (const TblFileEntry &entry : _entries) {
for (int i = 0; i < 2; ++i) {
const WorldToField &wm2Field = entry.wm2Field[i];
data.append((const char *)&wm2Field.x, 2);
data.append((const char *)&wm2Field.y, 2);
data.append((const char *)&wm2Field.z, 2);
data.append((const char *)&wm2Field.fieldId, 2);
data.append(char(wm2Field.dir));
data.append(char(wm2Field.dir)); // padding
data.append(char(wm2Field.dir)); // padding
data.append(char(wm2Field.dir)); // padding
}
}
return data;
}

QString TblFile::toString() const
{
QString ret;
int mapId = 0;
for (const TblFileEntry &entry : _entries) {
ret.append(QString("WM%1: ").arg(mapId++));
QStringList entriesStr;
for (int i = 0; i < 2; ++i) {
const WorldToField &wm2Field = entry.wm2Field[i];
if (wm2Field.fieldId != 0) {
entriesStr.append(QString("At (x=%1, y=%2, z=%3) => field %4 (direction=%5)")
.arg(wm2Field.x).arg(wm2Field.y).arg(wm2Field.z)
.arg(wm2Field.fieldId).arg(wm2Field.dir));
}
}
ret.append(entriesStr.join(" | "));
ret.append("\n");
}
return ret;
}
/****************************************************************************/
// copyright 2009 - 2022 Arzel Jérôme <[email protected]> //
// //
// This file is part of FF7tk //
// //
// FF7tk is free software: you can redistribute it and/or modify //
// it under the terms of the GNU General Public License as published by //
// the Free Software Foundation, either version 3 of the License, or //
// (at your option) any later version. //
// //
// FF7tk is distributed in the hope that it will be useful, //
// but WITHOUT ANY WARRANTY; without even the implied warranty of //
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the //
// GNU General Public License for more details. //
/****************************************************************************/
#include <TblFile.h>

TblFile::TblFile()
{
}

bool TblFile::open(const QByteArray &data)
{
if (data.size() % 24 != 0)
return false;
qsizetype entryCount = data.size() / 24;
const char *constData = data.constData();
for (int i = 0; i < entryCount; ++i) {
TblFileEntry entry;
for (int j = 0; j < 2; ++j) {
memcpy(entry.wm2Field + j, constData, sizeof(WorldToField));
constData += 12;
}
_entries.append(entry);
}
return true;
}

QByteArray TblFile::save() const
{
QByteArray data;
for (const TblFileEntry &entry : _entries) {
for (int i = 0; i < 2; ++i) {
const WorldToField &wm2Field = entry.wm2Field[i];
data.append((const char *)&wm2Field.x, 2);
data.append((const char *)&wm2Field.y, 2);
data.append((const char *)&wm2Field.z, 2);
data.append((const char *)&wm2Field.fieldId, 2);
data.append(char(wm2Field.dir));
data.append(char(wm2Field.dir)); // padding
data.append(char(wm2Field.dir)); // padding
data.append(char(wm2Field.dir)); // padding
}
}
return data;
}

QString TblFile::toString() const
{
QString ret;
int mapId = 0;
for (const TblFileEntry &entry : _entries) {
ret.append(QString("WM%1: ").arg(mapId++));
QStringList entriesStr;
for (int i = 0; i < 2; ++i) {
const WorldToField &wm2Field = entry.wm2Field[i];
if (wm2Field.fieldId != 0) {
entriesStr.append(QString("At (x=%1, y=%2, z=%3) => field %4 (direction=%5)")
.arg(wm2Field.x).arg(wm2Field.y).arg(wm2Field.z)
.arg(wm2Field.fieldId).arg(wm2Field.dir));
}
}
ret.append(entriesStr.join(" | "));
ret.append("\n");
}
return ret;
}
90 changes: 45 additions & 45 deletions src/formats/TblFile.h
Original file line number Diff line number Diff line change
@@ -1,45 +1,45 @@
/****************************************************************************/
// copyright 2009 - 2022 Arzel Jérôme <[email protected]> //
// //
// This file is part of FF7tk //
// //
// FF7tk is free software: you can redistribute it and/or modify //
// it under the terms of the GNU General Public License as published by //
// the Free Software Foundation, either version 3 of the License, or //
// (at your option) any later version. //
// //
// FF7tk is distributed in the hope that it will be useful, //
// but WITHOUT ANY WARRANTY; without even the implied warranty of //
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the //
// GNU General Public License for more details. //
/****************************************************************************/
#pragma once

#include <QtCore>
#include <ff7tkformats_export.h>

struct FF7TKFORMATS_EXPORT WorldToField
{
qint16 x;
qint16 y;
qint16 z;
quint16 fieldId;
quint8 dir;
quint8 _pad;
};

struct FF7TKFORMATS_EXPORT TblFileEntry
{
WorldToField wm2Field[2]; // 0= default, 1= alternate
};

class FF7TKFORMATS_EXPORT TblFile
{
public:
TblFile();
bool open(const QByteArray &data);
QByteArray save() const;
QString toString() const;
private:
QList<TblFileEntry> _entries;
};
/****************************************************************************/
// copyright 2009 - 2022 Arzel Jérôme <[email protected]> //
// //
// This file is part of FF7tk //
// //
// FF7tk is free software: you can redistribute it and/or modify //
// it under the terms of the GNU General Public License as published by //
// the Free Software Foundation, either version 3 of the License, or //
// (at your option) any later version. //
// //
// FF7tk is distributed in the hope that it will be useful, //
// but WITHOUT ANY WARRANTY; without even the implied warranty of //
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the //
// GNU General Public License for more details. //
/****************************************************************************/
#pragma once

#include <QtCore>
#include <ff7tkformats_export.h>

struct FF7TKFORMATS_EXPORT WorldToField
{
qint16 x;
qint16 y;
qint16 z;
quint16 fieldId;
quint8 dir;
quint8 _pad;
};

struct FF7TKFORMATS_EXPORT TblFileEntry
{
WorldToField wm2Field[2]; // 0= default, 1= alternate
};

class FF7TKFORMATS_EXPORT TblFile
{
public:
TblFile();
bool open(const QByteArray &data);
QByteArray save() const;
QString toString() const;
private:
QList<TblFileEntry> _entries;
};
Loading

0 comments on commit 9566d43

Please sign in to comment.