2023-11-20 23:25:36 -06:00
# pragma region License
2023-11-14 18:11:32 -06:00
/*
License ( OLC - 3 )
~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~
2024-01-02 00:46:32 -06:00
Copyright 2024 Joshua Sigona < sigonasr2 @ gmail . com >
2023-11-14 18:11:32 -06:00
Redistribution and use in source and binary forms , with or without modification ,
are permitted provided that the following conditions are met :
1. Redistributions or derivations of source code must retain the above copyright
notice , this list of conditions and the following disclaimer .
2. Redistributions or derivative works in binary form must reproduce the above
copyright notice . This list of conditions and the following disclaimer must be
reproduced in the documentation and / or other materials provided with the distribution .
3. Neither the name of the copyright holder nor the names of its contributors may
be used to endorse or promote products derived from this software without specific
prior written permission .
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS " AS IS " AND ANY
EXPRESS OR IMPLIED WARRANTIES , INCLUDING , BUT NOT LIMITED TO , THE IMPLIED WARRANTIES
OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED . IN NO EVENT
SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT , INDIRECT ,
INCIDENTAL , SPECIAL , EXEMPLARY , OR CONSEQUENTIAL DAMAGES ( INCLUDING , BUT NOT LIMITED
TO , PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES ; LOSS OF USE , DATA , OR PROFITS ; OR
BUSINESS INTERRUPTION ) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY , WHETHER IN
CONTRACT , STRICT LIABILITY , OR TORT ( INCLUDING NEGLIGENCE OR OTHERWISE ) ARISING IN
ANY WAY OUT OF THE USE OF THIS SOFTWARE , EVEN IF ADVISED OF THE POSSIBILITY OF
SUCH DAMAGE .
2023-11-29 00:50:00 -06:00
2024-01-30 14:48:49 +00:00
Portions of this software are copyright © 2024 The FreeType
2023-11-29 00:50:00 -06:00
Project ( www . freetype . org ) . Please see LICENSE_FT . txt for more information .
All rights reserved .
2023-11-14 18:11:32 -06:00
*/
2023-11-20 23:25:36 -06:00
# pragma endregion
2023-06-21 14:30:14 -07:00
# pragma once
2023-06-22 23:28:16 -07:00
# include "olcUTIL_Geometry2D.h"
2023-09-15 01:02:10 -05:00
# include <set>
2023-11-11 17:31:53 -06:00
# include "TMXParser.h"
2024-02-27 03:16:35 -06:00
# include "safemap.h"
2023-06-22 22:09:11 -07:00
2023-06-23 20:42:55 -07:00
struct XMLTag ;
2024-01-09 04:50:01 -06:00
using MapName = std : : string ;
2023-11-11 17:31:53 -06:00
class MapHelper {
public :
static Map & MapFromString ( std : : string mapName ) ;
} ;
2023-06-23 20:42:55 -07:00
struct TileCollisionData {
2024-01-11 01:26:58 -06:00
geom2d : : rect < float > collision ;
2023-06-23 20:42:55 -07:00
} ;
2023-06-22 22:09:11 -07:00
struct TilesetData {
2023-09-06 23:07:15 -05:00
Renderable * tileset = nullptr ;
2023-11-27 02:38:12 -06:00
int tilewidth = 0 , tileheight = 0 ;
2024-01-10 03:11:03 -06:00
bool isTerrain = false ;
2024-04-13 17:37:37 -05:00
std : : unordered_map < int , ForegroundTileTag > foregroundTiles ;
std : : unordered_map < int , ForegroundTileTag > upperForegroundTiles ;
2024-02-27 03:16:35 -06:00
safemap < int , TileCollisionData > collision ;
2024-04-13 17:37:37 -05:00
std : : unordered_map < int , XMLTag > staircaseTiles ;
std : : unordered_map < int , std : : vector < int > > animationData ;
std : : unordered_map < int , vi2d > tileRepeatData ;
2023-09-15 01:02:10 -05:00
std : : set < int > reflectiveData ;
2024-04-02 21:14:19 -05:00
std : : vector < Pixel > tilecols ;
2023-09-13 18:57:46 -05:00
} ;
struct TilesheetData {
2024-04-19 02:45:43 -05:00
const TilesetData & tileset ;
2023-09-13 18:57:46 -05:00
int firstgid ;
2024-04-02 21:14:19 -05:00
Pixel tilecol ;
2024-04-19 02:45:43 -05:00
TilesheetData ( const TilesetData & tileset , const int firstgid , const Pixel tilecol )
: tileset ( tileset ) , firstgid ( firstgid ) , tilecol ( tilecol ) { } ;
TilesheetData ( const TilesheetData & ref ) = default ;
TilesheetData operator = ( const TilesheetData & ref ) {
return { ref . tileset , ref . firstgid , ref . tilecol } ;
} ;
2023-12-22 21:01:10 -06:00
bool operator = = ( const TilesheetData & rhs ) {
2024-04-19 02:45:43 -05:00
return & tileset = = & rhs . tileset & & firstgid = = rhs . firstgid ;
2023-12-22 21:01:10 -06:00
}
2023-06-22 22:09:11 -07:00
} ;
2024-02-27 03:16:35 -06:00
struct TileGroup ;
2023-06-22 22:09:11 -07:00
struct TileRenderData {
2023-09-13 18:57:46 -05:00
TilesheetData tileSheet ;
2024-01-11 01:26:58 -06:00
vf2d pos ;
2023-06-22 22:09:11 -07:00
vi2d tileSheetPos ;
2023-09-13 18:57:46 -05:00
int tileID ;
2023-09-12 03:09:21 -05:00
int layerID ;
2024-02-27 03:16:35 -06:00
TileGroup * group = nullptr ; //The group that is tied to this render data. Set during rendering phase.
2024-04-19 02:45:43 -05:00
float tileOpacity = 1.f ;
TileRenderData ( const TilesheetData & tileSheet , const vf2d pos , const vi2d tileSheetPos , const int tileID , const int layerID )
: tileSheet ( tileSheet ) , pos ( pos ) , tileSheetPos ( tileSheetPos ) , tileID ( tileID ) , layerID ( layerID ) { } ;
2023-12-22 21:01:10 -06:00
bool operator = = ( const TileRenderData & rhs ) {
return tileSheet = = rhs . tileSheet & & pos = = rhs . pos & & tileSheetPos = = rhs . tileSheetPos
& & tileID = = rhs . tileID & & layerID = = rhs . layerID ;
}
2023-06-22 23:28:16 -07:00
} ;
struct TileGroup {
private :
geom2d : : rect < int > range ;
2024-02-27 03:16:35 -06:00
geom2d : : rect < float > collisionRange = { { } , { } } ;
2023-06-22 23:28:16 -07:00
std : : vector < TileRenderData > tiles ;
2023-07-10 18:48:57 -05:00
int minX = 0 , minY = 0 , maxX = 0 , maxY = 0 ;
2023-06-22 23:28:16 -07:00
public :
2023-07-11 15:33:50 +00:00
static float FADE_TIME ;
//0-255. 255 indicates fully invisible.
static uint8_t FADE_AMT ;
2024-02-27 03:16:35 -06:00
geom2d : : rect < float > GetCollisionRange ( ) ;
2023-06-22 23:28:16 -07:00
geom2d : : rect < int > GetRange ( ) ;
2023-07-11 15:33:50 +00:00
//The fade range is the bounds in which this tile group will be considered "in range" of a player, one tile in each direction further than its actual range.
geom2d : : rect < int > GetFadeRange ( ) ;
2023-06-22 23:28:16 -07:00
std : : vector < TileRenderData > & GetTiles ( ) ;
void InsertTile ( TileRenderData tile ) ;
2023-07-11 15:33:50 +00:00
float fadeFactor = 0.f ;
2023-06-21 14:30:14 -07:00
} ;