1 #ifndef CORE_MAPS_MAP_HPP
2 #define CORE_MAPS_MAP_HPP
18 #include <BLIB/Audio.hpp>
19 #include <BLIB/ECS.hpp>
20 #include <BLIB/Events.hpp>
21 #include <BLIB/Resources.hpp>
22 #include <BLIB/Scripts.hpp>
23 #include <BLIB/Serialization.hpp>
25 #include <unordered_map>
49 class Map :
public bl::event::Listener<event::EntityMoved> {
68 static std::string
getMapFile(
const std::string& partialFile);
78 bool loadDev(std::istream& input);
88 bool loadProd(bl::serial::binary::InputStream& input);
97 bool save(
const std::string& file);
106 bool saveBundle(bl::serial::binary::OutputStream& output,
107 bl::resource::bundle::FileHandlerContext& ctx)
const;
120 const bl::tmap::Position& prevPlayerPos);
140 const std::string&
name()
const;
180 bool contains(
const bl::tmap::Position& position)
const;
190 bl::tmap::Position
adjacentTile(
const bl::tmap::Position& pos, bl::tmap::Direction dir)
const;
200 bool movePossible(
const bl::tmap::Position& position, bl::tmap::Direction dir)
const;
209 bool isLedgeHop(
const bl::tmap::Position& position, bl::tmap::Direction dir)
const;
224 bool interact(bl::ecs::Entity interactor,
const bl::tmap::Position& interactPos);
258 const std::string&
getLocationName(
const bl::tmap::Position& pos)
const;
286 return static_cast<bl::rc::scene::Scene2D*
>(
scene.get())->getLighting();
305 std::unordered_map<std::uint16_t, Spawn>
spawns;
340 void setupLayer(
unsigned int level,
unsigned int layer);
341 void setupTile(
unsigned int level,
unsigned int layer,
const sf::Vector2u& pos);
346 friend struct bl::serial::SerializableObject<
Map>;
357 struct SerializableObject<
core::map::Map> :
public SerializableObjectBase {
365 SerializableField<6, M, std::vector<core::map::LayerSet>>
levels;
367 SerializableField<8, M, std::unordered_map<std::uint16_t, core::map::Spawn>>
spawnField;
369 SerializableField<10, M, std::vector<core::map::Item>>
itemsField;
370 SerializableField<11, M, std::vector<core::map::Event>>
eventsField;
371 SerializableField<12, M, core::map::LightingSystem>
lighting;
372 SerializableField<14, M, bl::ctr::Vector2D<core::map::LevelTransition>>
transitionField;
374 SerializableField<16, M, std::vector<core::map::Town>>
townsField;
375 SerializableField<17, M, bl::ctr::Vector2D<std::uint8_t>>
townTiles;
378 : SerializableObjectBase(
"Map")
379 , nameField(
"name", *this, &
M::nameField, SerializableFieldBase::Required{})
380 , loadScriptField(
"loadScript", *this, &
M::loadScriptField, SerializableFieldBase::Required{})
381 , unloadScriptField(
"unloadScript", *this, &
M::unloadScriptField,
382 SerializableFieldBase::Required{})
383 , playlistField(
"playlist", *this, &
M::playlistField, SerializableFieldBase::Required{})
384 , weatherField(
"weather", *this, &
M::weatherField, SerializableFieldBase::Required{})
385 , levels(
"levels", *this, &
M::levels, SerializableFieldBase::Required{})
386 , tilesetField(
"tileset", *this, &
M::tilesetField, SerializableFieldBase::Required{})
387 , spawnField(
"spawns", *this, &
M::spawns, SerializableFieldBase::Required{})
388 , characterField(
"characters", *this, &
M::characterField, SerializableFieldBase::Required{})
389 , itemsField(
"items", *this, &
M::itemsField, SerializableFieldBase::Required{})
390 , eventsField(
"events", *this, &
M::eventsField, SerializableFieldBase::Required{})
391 , lighting(
"lighting", *this, &
M::lighting, SerializableFieldBase::Required{})
392 , transitionField(
"transitions", *this, &
M::transitionField, SerializableFieldBase::Required{})
393 , catchRegionsField(
"catchZones", *this, &
M::catchRegionsField,
394 SerializableFieldBase::Required{})
395 , townsField(
"towns", *this, &
M::towns, SerializableFieldBase::Required{})
396 , townTiles(
"townTiles", *this, &
M::townTiles, SerializableFieldBase::Required{}) {}
Core classes and functionality for both the editor and game.
Fired after an entity begins moving from one position to another.
Represents a class of catchable peoplemon.
System for handling lighting in Maps. Manages all the lights and performs rendering....
The primary map class that represents a usable map in the game.
float getMinDepth() const
Returns the maximum depth possible for this map. Maximum is always 0.f. Minimum is negative,...
virtual void observe(const event::EntityMoved &moveEvent) override
Event listener for moving entities. Used to trigger map events.
bool enter(system::Systems &systems, std::uint16_t spawnId, const std::string &prevMap, const bl::tmap::Position &prevPlayerPos)
Initializes runtime data structures and spawns entities into the game. Also runs the on-load script.
bl::ctr::Grid< const Event * > eventRegions
bl::tmap::Position adjacentTile(const bl::tmap::Position &pos, bl::tmap::Direction dir) const
Returns the adjacent position to the given position when moving in the given direction....
std::vector< Item > itemsField
bool isLedgeHop(const bl::tmap::Position &position, bl::tmap::Direction dir) const
Test whether the given movement will be a ledge hop or not.
std::unordered_map< std::uint16_t, Spawn > spawns
const CatchRegion * getCatchRegion(const bl::tmap::Position &position) const
Returns the catch region at the given position if the position is on a catch tile.
std::vector< LayerSet > levels
bool loadDev(std::istream &input)
Loads the map from the given file. Will try to determine if the extension or path need to be added in...
Town * getTown(const glm::i32vec2 &pos)
void setupCamera(system::Systems &systems)
Configures the game camera for the player in the map.
const std::string & getLocationName(const bl::tmap::Position &pos) const
Returns the name of the town or route at the given position.
virtual ~Map()
Destroy the Map.
std::string unloadScriptField
void enterTown(Town *town)
bool save(const std::string &file)
Saves the map to the given file. The path should be relative to the maps directory and include the ....
static std::vector< Town > flymapTowns
std::vector< Event > eventsField
bool saveBundle(bl::serial::binary::OutputStream &output, bl::resource::bundle::FileHandlerContext &ctx) const
Saves the data from this object to the given bundle and registers dependency files.
float getDepthForPosition(unsigned int level, unsigned int y, int layer=-1) const
Computes the depth to use at the given y position, taking into account the map size,...
Map()
Creates an empty Map.
std::string loadScriptField
Weather::Type weatherField
LightingSystem & lightingSystem()
Returns a reference to the lighting system in this map.
const bl::tmap::Position * getSpawnPosition(unsigned int spawnId) const
Returns the position of the given player spawn, or nullptr if not found.
bool canFlyFromHere() const
Returns whether or not the player can fly from this map.
bl::resource::Ref< Tileset > tileset
bool contains(const bl::tmap::Position &position) const
Returns whether or not the map contains the given position.
bool interact(bl::ecs::Entity interactor, const bl::tmap::Position &interactPos)
Lets entities interact with the map itself. This is called by the Interaction system.
std::unique_ptr< bl::script::Script > onEnterScript
std::uint8_t levelCount() const
Returns the number of levels in the map.
void setupTile(unsigned int level, unsigned int layer, const sf::Vector2u &pos)
std::unique_ptr< bl::script::Script > onExitScript
static const std::vector< Town > & FlyMapTowns()
Returns the set of towns that can be flown to.
void exit(system::Systems &systems, const std::string &newMap)
Removes spawned entities and runs the on-unload script.
std::vector< Town > towns
bl::ctr::Vector2D< std::uint8_t > townTiles
const sf::Vector2i & sizeTiles() const
Returns the size of the map in tiles.
std::vector< CharacterSpawn > characterField
bl::ctr::Vector2D< LevelTransition > transitionField
void triggerAnimation(const bl::tmap::Position &position)
bl::audio::AudioSystem::Handle playlistHandle
void setupLayer(unsigned int level, unsigned int layer)
bl::rc::lgt::Scene2DLighting & getSceneLighting()
Returns the scene lighting for this map. Only valid after enter() is called.
bl::rc::SceneRef getScene()
Returns the scene for this map.
std::string playlistField
static std::string getMapFile(const std::string &partialFile)
Returns the full path to the map file from the given partial file. Accounts for missing extension.
Weather & weatherSystem()
Returns a reference to the weather system in this map.
bool loadProd(bl::serial::binary::InputStream &input)
Loads the map from the given file. Will try to determine if the extension or path need to be added in...
void setupEntityPosition(bl::ecs::Entity entity)
Performs the final setup of the position components for the given entity. Must already have a bl::tma...
std::vector< CatchRegion > catchRegionsField
static void loadFlymapTowns()
void update(float dt)
Updates internal logic over the elapsed time.
system::Systems * systems
bool movePossible(const bl::tmap::Position &position, bl::tmap::Direction dir) const
Returns whether or not a particular movement is possible. Does not take into account entities blockin...
void setupLevel(unsigned int level)
const std::string & name() const
Returns the name of the map.
sf::Vector2f sizePixels() const
Returns the size of the map in pixels.
std::list< RenderLevel > renderLevels
SerializableField< 6, M, std::vector< core::map::LayerSet > > levels
SerializableField< 14, M, bl::ctr::Vector2D< core::map::LevelTransition > > transitionField
SerializableField< 16, M, std::vector< core::map::Town > > townsField
SerializableField< 1, M, std::string > nameField
SerializableField< 9, M, std::vector< core::map::CharacterSpawn > > characterField
SerializableField< 2, M, std::string > loadScriptField
SerializableField< 4, M, std::string > playlistField
SerializableField< 17, M, bl::ctr::Vector2D< std::uint8_t > > townTiles
SerializableField< 15, M, std::vector< core::map::CatchRegion > > catchRegionsField
SerializableField< 11, M, std::vector< core::map::Event > > eventsField
SerializableField< 10, M, std::vector< core::map::Item > > itemsField
SerializableField< 8, M, std::unordered_map< std::uint16_t, core::map::Spawn > > spawnField
SerializableField< 3, M, std::string > unloadScriptField
SerializableField< 7, M, std::string > tilesetField
SerializableField< 5, M, core::map::Weather::Type > weatherField
SerializableField< 12, M, core::map::LightingSystem > lighting
Represents a town, route, or region within a map. Maps may have many towns. Individual tiles are asso...
Parent weather system for maps. Manages active weather.
Owns all primary systems and a reference to the engine.