Class Map
- java.lang.Object
-
- com.bombinggames.wurfelengine.core.map.Map
-
-
Field Summary
Fields Modifier and Type Field Description static java.lang.Integer
MAPVERSION
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description void
addEntities(AbstractEntity... ent)
Adds entities.void
addEntities(java.util.Collection<AbstractEntity> ent)
Adds entities.void
addLogic(AbstractBlockLogicExtension block)
Add a logicblock to the map.void
createSaveSlot(int slot)
static void
createSaveSlot(java.io.File path, int slot)
void
dispose(boolean save)
disposes every chunkvoid
disposeEntities()
Disposes every entity on the map and clears the list.com.badlogic.gdx.ai.pfa.DefaultGraphPath<PfNode>
findPath(Coordinate start, Coordinate goal)
int
getBlock(int x, int y, int z)
int
getBlock(Coordinate coord)
id, value and healthstatic BlockConfig
getBlockConfig()
Get the currently set block config.byte
getBlockId(int x, int y, int z)
Returns a block without checking the parameters first.byte
getBlockId(Coordinate coord)
If the block can not be found returns null pointer.Point
getCenter()
Returns a coordinate pointing to the absolute center of the map.Point
getCenter(float height)
Returns a coordinate pointing to middle of a 3x3 chunk map.Chunk
getChunk(int chunkX, int chunkY)
get the chunk with the given chunk coords.
Runtime: O(1)Chunk
getChunkContaining(int x, int y)
get the chunk where the coordinates are onChunk
getChunkContaining(Coordinate coord)
get the chunk where the coordinates are on.Chunk
getChunkContaining(Point point)
com.badlogic.gdx.utils.Array<com.badlogic.gdx.ai.pfa.Connection<PfNode>>
getConnections(PfNode fromNode)
int
getCurrentSaveSlot()
CVarSystemMap
getCVars()
java.util.HashMap<java.lang.Integer,Chunk>
getData()
Get the data of the map.static Generator
getDefaultGenerator()
Get the default set generator.java.util.ArrayList<AbstractEntity>
getEntities()
Returns a copy of the entityList.java.util.ArrayList<AbstractEntity>
getEntitiesOnChunk(int xChunk, int yChunk)
Get every entity on a chunk.java.util.ArrayList<AbstractEntity>
getEntitiesOnChunkSavedOnly(int xChunk, int yChunk)
Get every entity on a chunk which should be saved<T> java.util.LinkedList<T>
getEntitys(java.lang.Class<T> filter)
Find every instance of a special class.java.util.LinkedList<AbstractEntity>
getEntitysOnCoord(Coordinate coord)
Get every entity on a coord.<T> java.util.LinkedList<T>
getEntitysOnCoord(Coordinate coord, java.lang.Class<T> filter)
Get every entity on a coord of the wanted typeGenerator
getGenerator()
byte
getHealth(Coordinate coord)
java.util.LinkedList<Chunk>
getLoadedChunks()
AbstractBlockLogicExtension
getLogic(Coordinate coord)
int
getNodeCount()
java.io.File
getPath()
The name of the map on the file.CVarSystemSave
getSaveCVars()
int
getSavesCount()
checks a map for the amount of save filesstatic int
getSavesCount(java.io.File path)
Get the amount of save files for this map.boolean
hasSaveSlot(int saveSlot)
Check if the save slot exists.boolean
isLoading(int chunkX, int chunkY)
check wether a chunk is currently being loaded.boolean
isModified()
True if some block has changed in loaded chunks.void
loadChunk(int chunkX, int chunkY)
loads a chunk from disk if not already loaded.void
loadChunk(Coordinate coord)
loads a chunk from disk if not already loaded.void
modificationCheck()
should be executed after the update method.int
newSaveSlot()
Uses a new save slot as the save slotstatic int
newSaveSlot(java.io.File path)
void
postUpdate(float dt)
Called after the view update to catch changes caused by the viewboolean
save()
save every chunk using the current active save slot.boolean
save(int saveSlot)
saves every chunk on the mapvoid
setBlock(Coordinate coord, byte id)
Set a block at this coordinate.void
setBlock(Coordinate coord, byte id, byte value)
Set id and value at a coordinate in the map.void
setBlock(Coordinate coord, int block)
Set id, value and health at a coordinate in the map.static void
setBlockConfig(BlockConfig blockConfig)
Set the currently set block config.static void
setDefaultGenerator(Generator generator)
void
setGenerator(Generator generator)
Set the generator used for generating mapsvoid
setHealth(Coordinate coord, byte health)
Set health of a cell.void
setModified()
set the modified flag to true. usually not manually called.void
setValue(Coordinate coord, byte value)
void
update(float dt)
Updates amostly the entities.void
useSaveSlot(int slot)
uses a specific save slot for loading and saving the map.
-
-
-
Constructor Detail
-
Map
public Map(java.io.File name, int saveslot) throws java.io.IOException
Loads a map using the default generator.- Parameters:
name
- if available on disk it will be loadsaveslot
-- Throws:
java.io.IOException
- thrown if there is no full read/write access to the map file
-
Map
public Map(java.io.File name, int saveSlot, Generator generator) throws java.io.IOException
Loads a map. Loads map and save cVars.- Parameters:
name
- if available on disk it will load the meta filegenerator
- the generator used for generating new chunkssaveSlot
-- Throws:
java.io.IOException
- thrown if there is no full read/write access to the map file
-
-
Method Detail
-
setDefaultGenerator
public static void setDefaultGenerator(Generator generator)
- Parameters:
generator
-
-
getDefaultGenerator
public static Generator getDefaultGenerator()
Get the default set generator.- Returns:
- See Also:
setDefaultGenerator(Generator)
-
newSaveSlot
public static int newSaveSlot(java.io.File path)
- Parameters:
path
- the directory of the map- Returns:
-
createSaveSlot
public static void createSaveSlot(java.io.File path, int slot)
- Parameters:
path
- the directory of the mapslot
-
-
getSavesCount
public static int getSavesCount(java.io.File path)
Get the amount of save files for this map.- Parameters:
path
-- Returns:
-
getBlockConfig
public static BlockConfig getBlockConfig()
Get the currently set block config.- Returns:
-
setBlockConfig
public static void setBlockConfig(BlockConfig blockConfig)
Set the currently set block config.- Parameters:
blockConfig
-
-
getCVars
public CVarSystemMap getCVars()
- Returns:
-
getSaveCVars
public CVarSystemSave getSaveCVars()
- Returns:
-
update
public void update(float dt)
Updates amostly the entities.- Parameters:
dt
- time in ms
-
postUpdate
public void postUpdate(float dt)
Called after the view update to catch changes caused by the view- Parameters:
dt
-
-
loadChunk
public void loadChunk(int chunkX, int chunkY)
loads a chunk from disk if not already loaded.- Parameters:
chunkX
-chunkY
-
-
loadChunk
public void loadChunk(Coordinate coord)
loads a chunk from disk if not already loaded.- Parameters:
coord
-
-
getData
public java.util.HashMap<java.lang.Integer,Chunk> getData()
Get the data of the map. From range in X [-chunkDim/2,chunkDim/2]- Returns:
-
getLoadedChunks
public java.util.LinkedList<Chunk> getLoadedChunks()
- Returns:
-
getBlockId
public byte getBlockId(int x, int y, int z)
Returns a block without checking the parameters first. Good for debugging and also faster. O(n)- Parameters:
x
- coordinatey
- coordinatez
- coordinate- Returns:
- the single block you wanted
-
getBlockId
public byte getBlockId(Coordinate coord)
If the block can not be found returns null pointer.- Parameters:
coord
-- Returns:
-
getBlock
public int getBlock(Coordinate coord)
id, value and health- Parameters:
coord
-- Returns:
- first byte id, second value, third is health.
-
getBlock
public int getBlock(int x, int y, int z)
- Parameters:
x
-y
-z
-- Returns:
-
getHealth
public byte getHealth(Coordinate coord)
- Parameters:
coord
-- Returns:
-
setBlock
public void setBlock(Coordinate coord, byte id)
Set a block at this coordinate. This creates aAbstractBlockLogicExtension
instance if the block has logic.- Parameters:
coord
-id
-- See Also:
setBlock(Coordinate, int)
-
setBlock
public void setBlock(Coordinate coord, int block)
Set id, value and health at a coordinate in the map. This creates aAbstractBlockLogicExtension
instance if the block has logic.- Parameters:
coord
-block
- id (bit 0-7), value (bit 8-15) and health (bit 16-23)
-
setBlock
public void setBlock(Coordinate coord, byte id, byte value)
Set id and value at a coordinate in the map. This creates aAbstractBlockLogicExtension
instance if the block has logic.- Parameters:
coord
-id
-value
-
-
setValue
public void setValue(Coordinate coord, byte value)
- Parameters:
coord
-value
-
-
setHealth
public void setHealth(Coordinate coord, byte health)
Set health of a cell.- Parameters:
coord
-health
-
-
getChunkContaining
public Chunk getChunkContaining(Coordinate coord)
get the chunk where the coordinates are on. Usese hashmap so O(1).- Parameters:
coord
- not altered- Returns:
- can return null if not loaded
-
getChunkContaining
public Chunk getChunkContaining(int x, int y)
get the chunk where the coordinates are on- Parameters:
x
- grid coordinatey
- grid coordinate- Returns:
- can return null if not loaded
-
getChunk
public Chunk getChunk(int chunkX, int chunkY)
get the chunk with the given chunk coords.
Runtime: O(1)- Parameters:
chunkX
- chunk coordinatechunkY
- chunk coordinate- Returns:
- if not in memory returns null
-
getEntitiesOnChunk
public java.util.ArrayList<AbstractEntity> getEntitiesOnChunk(int xChunk, int yChunk)
Get every entity on a chunk.- Parameters:
xChunk
-yChunk
-- Returns:
-
getEntitiesOnChunkSavedOnly
public java.util.ArrayList<AbstractEntity> getEntitiesOnChunkSavedOnly(int xChunk, int yChunk)
Get every entity on a chunk which should be saved- Parameters:
xChunk
-yChunk
-- Returns:
-
save
public boolean save(int saveSlot)
saves every chunk on the map- Parameters:
saveSlot
-- Returns:
-
save
public boolean save()
save every chunk using the current active save slot. Saves position of the sun and moon at origin.- Returns:
-
getLogic
public AbstractBlockLogicExtension getLogic(Coordinate coord)
- Parameters:
coord
-- Returns:
-
addLogic
public void addLogic(AbstractBlockLogicExtension block)
Add a logicblock to the map.- Parameters:
block
-
-
useSaveSlot
public void useSaveSlot(int slot)
uses a specific save slot for loading and saving the map. Loads the save cVars.- Parameters:
slot
- slot number
-
newSaveSlot
public int newSaveSlot()
Uses a new save slot as the save slot- Returns:
- the new save slot number
-
hasSaveSlot
public boolean hasSaveSlot(int saveSlot)
Check if the save slot exists.- Parameters:
saveSlot
-- Returns:
-
createSaveSlot
public void createSaveSlot(int slot)
- Parameters:
slot
-
-
getSavesCount
public int getSavesCount()
checks a map for the amount of save files- Returns:
- the amount of saves for this map
-
modificationCheck
public void modificationCheck()
should be executed after the update method. Dispatches a message if a change occured.
-
getGenerator
public Generator getGenerator()
- Returns:
-
getCurrentSaveSlot
public int getCurrentSaveSlot()
- Returns:
-
setGenerator
public void setGenerator(Generator generator)
Set the generator used for generating maps- Parameters:
generator
-
-
getPath
public java.io.File getPath()
The name of the map on the file.- Returns:
-
setModified
public void setModified()
set the modified flag to true. usually not manually called.
-
getCenter
public Point getCenter()
Returns a coordinate pointing to the absolute center of the map. Height is half the map's height.- Returns:
-
getCenter
public Point getCenter(float height)
Returns a coordinate pointing to middle of a 3x3 chunk map.- Parameters:
height
- You custom height.- Returns:
-
getEntities
public java.util.ArrayList<AbstractEntity> getEntities()
Returns a copy of the entityList.- Returns:
- every item on the map
-
addEntities
public void addEntities(AbstractEntity... ent)
Adds entities.- Parameters:
ent
- entities should be already spawned
-
addEntities
public void addEntities(java.util.Collection<AbstractEntity> ent)
Adds entities.- Parameters:
ent
- entities should be already spawned
-
disposeEntities
public void disposeEntities()
Disposes every entity on the map and clears the list.
-
getEntitys
public <T> java.util.LinkedList<T> getEntitys(java.lang.Class<T> filter)
Find every instance of a special class. E.g. find every AbstractCharacter. They must be spawned to appear in the results.- Type Parameters:
T
- the class you want to filter.- Parameters:
filter
- the class you want to filter.- Returns:
- a list with the entitys
-
getEntitysOnCoord
public java.util.LinkedList<AbstractEntity> getEntitysOnCoord(Coordinate coord)
Get every entity on a coord.- Parameters:
coord
-- Returns:
- a list with the entitys
-
getEntitysOnCoord
public <T> java.util.LinkedList<T> getEntitysOnCoord(Coordinate coord, java.lang.Class<T> filter)
Get every entity on a coord of the wanted type- Type Parameters:
T
- the class you want to filter.- Parameters:
coord
- the coord where you want to get every entity fromfilter
- the class you want to filter.- Returns:
- a list with the entitys of the wanted type
-
isModified
public boolean isModified()
True if some block has changed in loaded chunks.- Returns:
- returns the modified flag
-
getConnections
public com.badlogic.gdx.utils.Array<com.badlogic.gdx.ai.pfa.Connection<PfNode>> getConnections(PfNode fromNode)
- Specified by:
getConnections
in interfacecom.badlogic.gdx.ai.pfa.Graph<PfNode>
-
findPath
public com.badlogic.gdx.ai.pfa.DefaultGraphPath<PfNode> findPath(Coordinate start, Coordinate goal)
- Parameters:
start
-goal
-- Returns:
-
getNodeCount
public int getNodeCount()
- Specified by:
getNodeCount
in interfacecom.badlogic.gdx.ai.pfa.indexed.IndexedGraph<PfNode>
-
isLoading
public boolean isLoading(int chunkX, int chunkY)
check wether a chunk is currently being loaded.- Parameters:
chunkX
-chunkY
-- Returns:
-
dispose
public void dispose(boolean save)
disposes every chunk- Parameters:
save
-
-
-