Skip to content
Snippets Groups Projects
Commit de5f358c authored by Frederik Alexander Keens's avatar Frederik Alexander Keens
Browse files

Merge branch 'leveleditor' into 'main'

Leveleditor

See merge request !57
parents 9d7ecb3f 1febbab8
No related branches found
No related tags found
1 merge request!57Leveleditor
Showing
with 770 additions and 426 deletions
......@@ -128,6 +128,7 @@ else()
include_directories(${SDL2_IMG_INCLUDE_DIR})
include_directories(${SDL2_TTF_INCLUDE_DIR})
include_directories(${HDF5_INCLUDE_DIRS})
target_include_directories(advanced_wars PRIVATE ${highfive_SOURCE_DIR}/include)
target_link_libraries(advanced_wars
${HDF5_LIBRARIES}
......@@ -160,19 +161,6 @@ target_include_directories(editor
${highfive_SOURCE_DIR}/include
)
# writelevel
add_executable(writelevel ${PROJECT_SOURCE_DIR}/src/util/writelevel.cpp)
target_include_directories(writelevel
PRIVATE
${highfive_SOURCE_DIR}/include
)
target_link_libraries(writelevel
${HDF5_LIBRARIES}
)
target_include_directories(advanced_wars PRIVATE ${highfive_SOURCE_DIR}/include)
# Ressourcen kopieren (plattformübergreifend)
foreach(FONT ${FONT_FILES})
add_custom_command(
......
......@@ -12,25 +12,20 @@ To receive Events from EventHandler a class needs to inherit from EventHandler a
The available event methods, as well as the info on which class emits which event method and which class overwrites which event method can be seen in the below diagramm.
The formless diagramm below demonstrates how the classes form the Application.
For more details on the individual classes, take a look at the documentation in their header files.
![Formless System Architecture Diagramm](./architecture.svg)
![Formless System Architecture Diagramm](./system-architecture.svg)
## Level Specification
The level is stored in two datasets named 'metadata', 'tilesarray' in the level hdf5 file (level.h5).
The metadata dataset is in XML format. It provides the level height, width and name.
The level is stored in a dataset called 'tilesarray' in the level hdf5 file.
The tilesarray dataset is a giant array<uint8_t> which defines the level map through an array of tile ids.
The attached attributes of the dataset define the level metadata.
### 1. metadata dataset (XML)
```xml
<?xml version="1.0" encoding="ASCII"?>
<level>
<width>20</width> <!-- Breite des Levels -->
<height>20</height> <!-- Hoehe des Levels -->
<name>Geiles Level<name><!-- Name des Levels -->
</level>
```
### 1. tilesarray attributes
- width (int) The width of the level in number of tiles.
- height (int) The height of the level in number of tiles.
- name (string) The name of the level.
### 2. tilesarray dataset
### 2. tilesarray data
The length of the tiles array is level width x level height (see level metadata).
From the individual values inside the tiles array you can determine the IDs of the buildings and terrains.
0 - 29 are terrain IDs => Mapping see enum in src/game/Tile.hpp
......
This diff is collapsed.
This diff is collapsed.
# Levelspezifikation
Das Level wird ueber 2 Datasets in der HDF5-Datei repraesentiert.
Ein Dataset in XML Format, das die Level Metadaten (Breite, Hoehe, Dataset ID Tiles Array) angibt.
Ein weiters Dataset, das letztlich ein array<uint8_t> ist, welches die Levelmap ueber ein Array von Tile IDs definiert.
## 1. XML Dataset mit Level Metadaten
```xml
<?xml version="1.0" encoding="ASCII"?>
<level>
<width>20</width> <!-- Breite des Levels -->
<height>20</height> <!-- Hoehe des Levels -->
<name>Geiles Level<name><!-- Name des Levels -->
</level>
```
## 2. Tiles Array
Das Tiles Array wird als array<uint8_t> in einem Dataset in der HDF5-Datei gespeichert.
Die Laenge des Arrays ist Breite X Hoehe (kann man aus XML Leveldefinition entnehmen).
Aus den einzelnen Werte in dem Array lassen sich die IDs der entsprechenden Gebaudes/Terrains ableiten.
0 - 29 sind Terrain IDs => Zuordnung siehe entsprechendes Enum in Tile.hpp
30-49 sind undefiniert
50-79 sind Gebaeude IDs:
50 => Faction ID 0, Gebaeude ID 0
51 => Faction ID 0, Gebaeude ID 1
...
55 => Faction ID 1, Gebaeude ID 0
56 => Faction ID 1, Gebaeude ID 1
57 => Faction ID 1, Gebaeude ID 2
...
Allgemein:
Sei t ein Wert im Tiles Array, dann gillt
falls t < 30: Terrain ID = t
falls t >= 50: Faction ID = (t - 50) / 5 Gebaeude ID = (t - 50) % 5
t wird ermittelt mit entweder t = Terrain ID fuer Terrains
oder t = 50 + 5*Faction Id + Gebaeude ID fuer Gebaeude
\ No newline at end of file
No preview for this file type
No preview for this file type
/**
* TileSelector.cpp
* AdvancedPlacementSwitch.cpp
*
* @date 06.02.2025
* @author Nils Jonathan Friedrich Eckardt implementation
* @author Jonathan Dueck (jonathan.dueck@informatik.hs-fulda.de) small changes
*/
#include "AutomateButton.hpp"
#include "AdvancedPlacementSwitch.hpp"
#include "EventHandler.hpp"
#include <QEvent>
#include <QMessageBox>
#include <iostream>
namespace editor
{
AutomateButton::AutomateButton(const QString text, QWidget* parent) : QCheckBox(text, parent)
AdvancedPlacementSwitch::AdvancedPlacementSwitch(
const QString text, const bool doesPlacement, QWidget* parent)
: QCheckBox(text, parent), isPlacement(doesPlacement)
{
setChecked(false);
}
void AutomateButton::mousePressEvent(QMouseEvent* event)
void AdvancedPlacementSwitch::mousePressEvent(QMouseEvent* event)
{
QCheckBox::mousePressEvent(event);
EventHandler::send([](EventHandler* e) { e->onCheckBoxToggled(); });
if (isPlacement)
{
EventHandler::send([](EventHandler* e) { e->onAdvancedPlacementToggled(); });
}
else
{
EventHandler::send([](EventHandler* e) { e->onSymmetryToggled(); });
}
}
} // namespace editor
\ No newline at end of file
/**
* AdvancedPlacementSwitch.hpp
*
* @date 06.02.2025
* @author Nils Jonathan Friedrich Eckardt implementation
* @author Jonathan Dueck (jonathan.dueck@informatik.hs-fulda.de) small changes, doc comments
*/
#pragma once
#include <QCheckBox>
#include <QEvent>
#include <QString>
namespace editor
{
/**
* The AdvancedPlacementSwitch is displayed in the TopBar and allows the user to switch between
* regular tile placement and advanced tile placement.
*/
class AdvancedPlacementSwitch : public QCheckBox
{
public:
/**
* Creates an AdvancedPlacementSwitch as QCheckBox using the provided text and parent.
* @param text The description to display next to the CheckBox.
* @param doesPlacement Which of the 2 checkboxes this one is: symetry or placement
* @param parent The parent for this widget.
*/
AdvancedPlacementSwitch(const QString text, bool doesPlacement, QWidget* parent = nullptr);
protected:
/**
* Receives a QMouseEvent when the QCheckBox is pressed and subsequently emits
* the onAdvancedPlacementToggled event method.
* @param event The QMouseEvent for the CheckBox Pressing.
*/
void mousePressEvent(QMouseEvent* event) override;
private:
/**
* Set at creation, controlls if the switch is used for Placement or Symmetry
*/
bool isPlacement;
};
} // namespace editor
\ No newline at end of file
/**
* TileSelector.hpp
*
* @date 06.02.2025
* @author Nils Jonathan Friedrich Eckardt implementation
*/
#pragma once
#include <QCheckBox>
#include <QString>
#include <QEvent>
namespace editor
{
class AutomateButton : public QCheckBox {
public:
AutomateButton(const QString text, QWidget *parent = nullptr);
protected:
void mousePressEvent(QMouseEvent *event) override;
};
} // namespace editor
\ No newline at end of file
/**
* EventHandler.cpp
* EventHandler.hpp
*
* @date 29.01.2025
* @author Jonathan Dueck (jonathan.dueck@informatik.hs-fulda.de)
* @author Nils Jonathan Friedrich Eckardt onCheckBoxToggle added
* @author Nils Jonathan Friedrich Eckardt onAdvancedPlaement, onSymmetryToggled added
*/
#pragma once
......@@ -18,9 +18,6 @@
namespace editor
{
// forward declaration of Tile
class Tile;
/**
* EventHandler is the backbone in the architecture that makes interaction possible.
*
......@@ -66,9 +63,8 @@ class EventHandler
/**
* Overwrite this event method to handle the dispatch of a request to write
* the level to disk by the save button.
* @param file_path The path to the file into which the level should be written.
*/
virtual void onLevelWriteRequested(QString /*filePath*/){};
virtual void onLevelWriteRequested(){};
/**
* Overwrite this event method to handle the dispatch of a new tile index due
......@@ -100,10 +96,15 @@ class EventHandler
/**
* Overwrite this event method to handle the change of tile placement method due
* to the user selecting automatic tile placement assisstance.
* @param isToggled Boolean that enables tile placing assisstment.
* to the user toggling advanced palacement on or off.
*/
virtual void onAdvancedPlacementToggled(){};
/**
* Overwrite this event method to handle the change of symmetric tile placement
* due to the user toggling map symmetry on or off.
*/
virtual void onCheckBoxToggled() {};
virtual void onSymmetryToggled(){};
/**
* Overwrite this event method to handle the dispatch of a new delta due to
......
/**
* EventHandler.cpp
* LevelNameEdit.cpp
*
* @date 29.01.2025
* @author Jonathan Dueck (jonathan.dueck@informatik.hs-fulda.de)
......
/**
* EventHandler.cpp
* LevelNameEdit.hpp
*
* @date 29.01.2025
* @author Jonathan Dueck (jonathan.dueck@informatik.hs-fulda.de)
......@@ -22,12 +22,17 @@ class LevelNameEdit : public QLineEdit
/**
* Creates a LevelNameEdit Widget prefilling the provided level_name.
* The parent of the LevelNameEdit Widget is set to the provided parent.
* @param level_name The initial name of the level.
* @param levelName The initial name of the level.
* @param parent The Widget that should be set as the parent of this Widget.
*/
LevelNameEdit(const std::string& levelName, QWidget* parent = nullptr);
protected:
/**
* Receives a QKeyEvent when the user presses a key to change the content of the QLineEdit.
* The onLevelNameUpdated event method is subsequently emitted.
* @param event The QKeyEvent for the Key Press.
*/
void keyPressEvent(QKeyEvent* event) override;
};
......
This diff is collapsed.
......@@ -3,60 +3,301 @@
*
* @date 28.01.2025
* @author Jonathan Dueck (jonathan.dueck@informatik.hs-fulda.de)
* @author Nils Jonathan Friedrich Eckardt minor changes
* @author Nils Jonathan Friedrich Eckardt implementing symmetry, advanced placement
* (and onTileClicked, setTile, placeCliff, placeRoad, calcDir)
*/
#pragma once
#include <QGraphicsPixmapItem>
#include <QGraphicsRectItem>
#include <QGraphicsScene>
#include <QGraphicsSceneMouseEvent>
#include <QMouseEvent>
#include <QWidget>
#include "EventHandler.hpp"
#include "Tile.hpp"
namespace editor
{
/**
* The LevelScene is a Container for all of the individual tiles (QGraphicsPixmapItems)
* of the level map.
* LevelScene is responsible for rendering/updating the map on user actions.
* It also privdes the static factory methods empty, fromFile for creating empty level maps,
* laoding a level map from a hdf5 file.
*
* LevelScene inherits from EventHandler overwriting many event methods:
* - onLevelNameUpdated
* To keep the current level name for when the level map should be saved.
* - onLevelWriteRequested
* To write the level map to a hdf5 file when the save button is pressed.
* - onTileEntered
* To render the currently selected tile from the tile selector on the entered tile.
* - onTileExited
* To render the old tile again if the currently selected tile id was not set on this tile.
* - onTileClicked
* To set the currently selected tile id on that tile. Maybe do advanced placement changes.
* - onNewTileIdSelected
* To update the currently selected tile id.
* - onAdvancedPlacmentToggled
* To toggle advanced placement on or off.
*
* How does the rendering work?
* LevelScene implements a two layer approach.
* The bottom layer is static. It is created out of Tile (Tile.cpp) objects. These Tile objects
* inherit from QGraphicsPixmapItems to override onmouse enter, exit and press.
* LevelScene receives those events in onTileEntered, onTileExited, onTileClicked.
* The bottom layer is only grass and water cliffs on the borders.
* The bottom layer always gets a z value of 0.
* For non grass tile ids, QGraphicsPixmapItems are created on the second layer with a z value of 1
* for terrain tiles and 2 + index for building tiles.
* These Items are also saved in m_tileOccupants. The second layer is dynamic, by keeping pointers
* to its Pixmap Items we can remove them and switch them around.
*/
class LevelScene : public QGraphicsScene, public EventHandler
{
public:
/**
* It builds a LevelScene from the provided vector of tile ids and width and height.
* It creates the bottom layer of Tile objects and builds a second layer of
* QGraphicsPixmapItems on top, if the tile id is > 0 and the tile is not on the border.
* @param name The name of the level.
* @param width The width of the level. Unit: number of tiles
* @param height The height of the level. Unit: number of tiles
* @param tileIds A vector of tile ids that define the level map.
* @param filePath The path to the file from which the level was loaded, empty string if
* level was just created.
* @param parent The parent to set for the LevelScene.
*/
LevelScene(
const std::string& name, int width, int height, std::vector<uint8_t> tileIds,
const std::string& filePath, QWidget* parent = nullptr);
/**
* Uses the LevelScene constructor internally to create an empty LevelScene (only grass,
* water cliffs on the borders).
* @param name The name of the new level.
* @param width The width of the new level. Unit: number of tiles
* @param height The height of the new level. Unit: number of tiles
* @param parent The parent to set for the newly created LevelScene.
* @return An empty LevelScene.
*/
static LevelScene*
empty(const std::string& name, int width, int height, QWidget* parent = nullptr);
/**
* Uses the LevelScene constructor internally to create a LevelScene from an hdf5 file.
* @param filePath The path to the hdf5 file from which the LevelScene should be loaded.
* @param parent The parent to set for the newly created LevelScene.
* @return A LevelScene that was loaded from a file.
*/
static LevelScene* fromFile(const std::string& filePath, QWidget* parent = nullptr);
/**
* Gets the name of the level.
* @return The current name of the level.
*/
std::string getName();
/**
* Gets the width of the level.
* @return The width of the level. Unit: number of tiles.
*/
int getWidth();
/**
* Gets the height of the level.
* @return The height of the level. Unit: number of tiles.
*/
int getHeight();
private:
/**
* Checks if the given index corresponds to a border tile.
* @param index The position of an individual tile if you linearized the level map.
* @return True or False if the given index corresponds to a border tile.
*/
bool isBorder(int index);
/**
* Checks if the tile id corresponds to a water tile.
* @param id The tile id to check.
* @return True or false if the given tile id corresponds to a water tile.
*/
bool isWaterTile(uint8_t id);
bool isntIdentical(int16_t id, int index);
/**
* Updates the level name stored in LevelScene to newName.
* The onLevelNameUpdated event method is emitted by the LevelNameEdit Widget.
* @param newName The new name of the level.
*/
void onLevelNameUpdated(std::string newName) override;
void onLevelWriteRequested(QString filePath) override;
/**
* Writes the level to the file from which it was loaded initially.
* If it was created from scratch, a path to the desired location is
* obtained from the QT file save dialog.
* The onLevelWriteRequested event method is emitted by the SaveButton.
*/
void onLevelWriteRequested() override;
/**
* Renders the currently selcted tile (m_selectedTileId) on the provided index.
* The onTileEntered event method is emitted by the Tile object.
* @param index The position of an individual tile if you were to linearized the level map.
*/
void onTileEntered(int index) override;
/**
* Renders the old tile id from m_tileIds at index again if the selected tile id was
* not set onto that tile.
* The onTileExited event method is emitted by the Tile object.
* @param index The position of an individual tile if you were to linearized the level map.
*/
void onTileExited(int index) override;
/**
* Evaluates how to procede once a tile has been placed by clicking on it.
* On the border only water tiles can be placed.
* If the option for advanced tile placement is checked, it will be executed from here.
* If the option for symmetric tile placement is checked, it will also be executed from
* here. When a red building is selected, symmetric tile placement will turn the mirrored
* building into a blue one and vice versa.
* @param index The index of the placed tile. Used to calculate both the previous id
* and the position on the map.
*/
void onTileClicked(int index) override;
/**
* Evaluates what tile has been placed, then calls the corresponding function.
* When this function is called advanced placement of tiles is enabled.
* If any street tile except bridges were placed placeRoad is called.
* If any Water or Land tiles are placed placeCliff is called.
* If any building is placed setTile is called.
*/
void placeAdvancedTiles(int index);
/**
* Saves the newly selected tileId inside LevelScene.
* The onNewTileIdSelected event method is emitted by the TileButton which
* is part of the TileSelector on the right of the level editor.
* @param tileId The newly selected tile id.
*/
void onNewTileIdSelected(uint8_t tileId) override;
void onCheckBoxToggled() override;
/**
* Toggles LevelScene's internal m_advancedTilePlacement member.
* This event method is emitted by the Advanced Placement CheckBox in the TopBar.
*/
void onAdvancedPlacementToggled() override;
/**
* Toggles LevelScene's internal m_symmetricTilePlacement member.
* This event method is emitted by the Advanced Placement CheckBox in the TopBar.
*/
void onSymmetryToggled() override;
/**
* This places a tile on the map.
* @param index Position on the map where the Tile is placed.
* @param id Id of the placed tile.
*/
void setTile(int index, uint8_t id);
/**
* A function of advanced placement used to determain whether the 8 surrounding tiles
* change when any land or water is placed. In this case it automaticly calculates the
* correct shape of the new cliffs and places them.
* @param placedLand If Land was placed - not water. Needed to evaluate if land should
* be added or removed around the placed tile.
* @param index Position of the tile water or land is placed on. The placed cliffs are the
* surrounding 8 tiles.
*/
void placeCliff(bool placedLand, int index);
/**
* A recursive function of advanced placement used to adjust the roads around the placed
* one. The surrounding roads above, bellow, to the left and right are detected and used to
* calculate the shape the newly placed road should have. After that the function is again
* called for those up to 4 roads around.
* @param index The position of the newly placed road.
* @param updateFlag Used in the recursion. When true it calls itself on the 4 surrounding
* tiles. When false the recursion ends and it doesnt call itself again.
*/
void placeRoad(int index, bool updateFlag);
/**
* A technical helper function for placeCliff. When calculating the Direction of the
* surrounding 8 tiles different calculations have to be done due to the map being
* represented as a 1D array rather then a 2D one. As a result it would not be easily
* possible to iterate through index of the 8 surrounding tiles, starting with the one
* above, then turning clockwise. This function is used for this to prevent code
* duplication.
*/
int calcDir(int i, int index);
/**
* A technical helper function for placeCliff. When evaluating whether land or water has
* been placed trees and mountains are treated as terrain, while reefs are treated as water.
* However once the placement of new cliffs has been determained reefs should not be
* replaced by water when there should not be made any change to the cell. This function
* fixes a bug where this would happen.
* @param id The id of a tile, this bug could trigger on.
* @param index The position the old tile is sitting on, possibly to be replaced by a new
* one.
*/
bool isntIdentical(int16_t id, int index);
/**
* Places a new QGraphicsPixmapItem using the given tileId at the given index.
* It correclty sets its position and z value (1 -> terrain tile, 2 + index -> building
* tile)
* @param index The position of an individual tile if you were to linearized the level map.
* @param tileId The id that corresponds to a type of tile to use.
* @return A pointer to the QGraphicsPixmapItem, that was added to the level scene.
*/
QGraphicsPixmapItem* occupyTile(int index, uint8_t tileId);
uint8_t m_selected_tile_id;
/**
* The name of the level.
*/
std::string m_name;
bool m_advanced_tile_placement;
/**
* The width of the level. Unit: number of tiles.
*/
int m_width;
/**
* The height of the level. Unit: number of tiles.
*/
int m_height;
std::vector<uint8_t> m_tile_ids;
std::vector<QGraphicsPixmapItem*> m_tile_occupants;
std::string m_file_path;
/**
* The tile id of every tile. (linearized representation)
*/
std::vector<uint8_t> m_tileIds;
/**
* The path from which the LevelScene was loaded (empty if created from scratch).
*/
std::string m_filePath;
/**
* The currently selected tile id. Tells the LevelScene which tiles need to be set
* if a tile is clicked.
*/
uint8_t m_selectedTileId;
/**
* Activates/deactivates adavanced placement.
*/
bool m_advancedTilePlacement;
/**
* Activates/deactivates adavanced placement.
*/
bool m_symmetricTilePlacement;
/**
* Holds pointers to all of the QGraphicsPixmapItems of the top layer.
* It holds nullptrs in places at which just the bottom layer is present.
* The length of m_tileOccupants is the same as m_tileIds.
*/
std::vector<QGraphicsPixmapItem*> m_tileOccupants;
};
} // namespace editor
\ No newline at end of file
......@@ -15,14 +15,42 @@
namespace editor
{
/**
* MainWindow is the top level Widget of the LevelEditor.
* All other Widgets are children of MainWindow.
* MainWindow is instantiated on the stack in main.cpp.
* Thus, MainWindow is freed automatically at application exit together
* with all of the other widgets (descendants), because of the way memory management works in QT.
* MainWindow inherits from EventHandler so that it can override onLevelNameUpadated in order
* to change the window title when the level name is changed.
*/
class MainWindow : public QMainWindow, public EventHandler
{
public:
/**
* Creates a MainWindow from the given LevelScene and parent.
* @param level The LevelScene of the level that should be edited.
* @param parent The parent widget for the MainWindow.
*/
MainWindow(LevelScene* level, QWidget* parent = nullptr);
private:
/**
* Updates the Window Title with the new_name.
* @param new_name The new level name.
*/
void onLevelNameUpdated(std::string newName) override;
/**
* The widht of the level that is being edited.
* Unit: number of tiles.
*/
int m_levelWidth;
/**
* The height of the level that is being edited.
* Unit: number of tiles.
*/
int m_levelHeight;
};
......
......@@ -19,15 +19,9 @@ SaveButton::SaveButton(const std::string& title, QWidget* parent)
{
}
void SaveButton::mousePressEvent(QMouseEvent* event)
void SaveButton::mousePressEvent(QMouseEvent*)
{
QPushButton::mousePressEvent(event);
QString filePath = QFileDialog::getSaveFileName(
this, "Level Speichern", QDir::currentPath(), "HDF5 Files (*.h5)");
if (!filePath.isEmpty())
{
EventHandler::send([filePath](EventHandler* e) { e->onLevelWriteRequested(filePath); });
}
EventHandler::send([](EventHandler* e) { e->onLevelWriteRequested(); });
}
} // namespace editor
\ No newline at end of file
......@@ -12,11 +12,30 @@
namespace editor
{
class SaveButton : public QPushButton {
/**
* The Save Button is displayed on the top right in the TopBar.
* Clicking it opens the file save dialog.
* It is not responsible for writing the level itself.
* Instead it collects the desired file path from the file save dialog and
* emits the onLevelWriteRequested event method which is overwritten by the LevelScene.
*/
class SaveButton : public QPushButton
{
public:
/**
* Creates a SaveButton with the given title and parent.
* @param title The title to display inside the SaveButton.
* @param parent The parent that should be set for the SaveButton.
*/
SaveButton(const std::string& title, QWidget* parent = nullptr);
protected:
void mousePressEvent(QMouseEvent* event) override;
/**
* When a mouse press event is received,
* it emits the onLevelWriteRequested event method.
* onLevelWriteRequested is overwritten by LevelScene.
*/
void mousePressEvent(QMouseEvent*) override;
};
} // namespace editor
\ No newline at end of file
......@@ -36,19 +36,64 @@ void SpriteProvider::initialize(const std::string& path)
return;
}
/**
* Provides all terrain tile names.
* They are necessary to create the correct path to
* the hdf5 dataset that contains the pixels for a given terrain tile.
*/
const std::vector<std::string> tileNames(
{"plain",
"water",
"forest",
"mountain",
"bridge_horizontal",
"bridge_vertical",
"street_horizontal",
"street_vertical",
"street_crossing",
"street_junction_right",
"street_junction_left",
"street_junction_down",
"street_junction_up",
"street_corner_top_left",
"street_corner_top_right",
"street_corner_bottom_left",
"street_corner_bottom_right",
"riff",
"cliff_top",
"cliff_bottom",
"cliff_left",
"cliff_right",
"cliff_corner_top_left",
"cliff_corner_top_right",
"cliff_corner_bottom_left",
"cliff_corner_bottom_right",
"cliff_inverse_corner_top_left",
"cliff_inverse_corner_top_right",
"cliff_inverse_corner_bottom_left",
"cliff_inverse_corner_bottom_right"});
/**
* Provides the names for all factions in the game.
* The names can be used to create the path to the hdf5 dataset
* containing the buildings for a given faction.
*/
const std::vector<std::string> factionNames(
{"red", "blue", "green", "yellow", "purple", "neutral"});
HighFive::File file(path, HighFive::File::ReadOnly);
sprites.reserve(60); // we now that we will load 60 sprites
// load terrains
for (size_t i = 0; i < TILE_NAMES.size(); i++)
for (size_t i = 0; i < tileNames.size(); i++)
{ // size_t?
std::vector<std::vector<std::vector<uint32_t>>> pixels;
file.getDataSet("tiles/" + TILE_NAMES[i]).read(pixels);
file.getDataSet("tiles/" + tileNames[i]).read(pixels);
sprites.push_back(SpriteProvider::loadPixmap(pixels, 0));
}
// load buildings
for (const std::string& factionName : FACTION_NAMES)
for (const std::string& factionName : factionNames)
{
std::vector<std::vector<std::vector<uint32_t>>> pixels;
file.getDataSet("buildings/" + factionName).read(pixels);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment