1 /*
2  * Copyright (C) 2015-2020, by Laszlo Szeremi under the Boost license.
3  *
4  * Pixel Perfect Engine, graphics.layers.base module
5  */
6 
7 module PixelPerfectEngine.graphics.layers.interfaces;
8 
9 import PixelPerfectEngine.graphics.layers.base;
10 
11 /**
12  * Tile interface, defines common functions.
13  */
14 public interface ITileLayer{
15 	/// Retrieves the mapping from the tile layer.
16 	/// Can be used to retrieve data, e.g. for editors, saving game states
17 	public MappingElement[] getMapping() @nogc @safe pure nothrow;
18 	/// Reads the mapping element from the given area.
19 	public MappingElement readMapping(int x, int y) @nogc @safe pure nothrow const;
20 	/// Writes the given element into the mapping at the given location.
21 	public void writeMapping(int x, int y, MappingElement w) @nogc @safe pure nothrow;
22 	/// Loads the mapping, primarily used for deserialization.
23 	public void loadMapping(int x, int y, MappingElement[] mapping) @safe pure;
24 	/// Removes the tile from the display list with the given ID.
25 	public void removeTile(wchar id) pure;
26 	/// Returns the tile ID from the location by pixel.
27 	public MappingElement tileByPixel(int x, int y) @nogc @safe pure nothrow const;
28 	/// Returns the width of the tiles.
29 	public int getTileWidth() @nogc @safe pure nothrow const;
30 	/// Returns the height of the tiles.
31 	public int getTileHeight() @nogc @safe pure nothrow const;
32 	/// Returns the width of the mapping.
33 	public int getMX() @nogc @safe pure nothrow const;
34 	/// Returns the height of the mapping.
35 	public int getMY() @nogc @safe pure nothrow const;
36 	/// Returns the total width of the tile layer.
37 	public size_t getTX() @nogc @safe pure nothrow const;
38 	/// Returns the total height of the tile layer.
39 	public size_t getTY() @nogc @safe pure nothrow const;
40 	/// Adds a tile.
41 	public void addTile(ABitmap tile, wchar id, ubyte paletteSh = 0) pure;
42 	/// Returns the tile.
43 	public ABitmap getTile(wchar id) @nogc @safe pure nothrow;
44 	/// Sets the warp mode.
45 	/// Returns the new warp mode that is being used.
46 	public WarpMode setWarpMode(WarpMode mode) @nogc @safe pure nothrow;
47 	/// Returns the currently used warp mode.
48 	public WarpMode getWarpMode() @nogc @safe pure nothrow const;
49 }
50 /**
51  *General SpriteLayer interface.
52  */
53 public interface ISpriteLayer{
54 	///Clears all sprite from the layer.
55 	public void clear() @safe nothrow;
56 	///Removes the sprite with the given ID.
57 	public void removeSprite(int n) @safe nothrow;
58 	///Moves the sprite to the given location.
59 	public void moveSprite(int n, int x, int y) @safe nothrow;
60 	///Relatively moves the sprite by the given values.
61 	public void relMoveSprite(int n, int x, int y) @safe nothrow;
62 	///Gets the coordinate of the sprite.
63 	public Coordinate getSpriteCoordinate(int n) @nogc @safe nothrow;
64 	///Adds a sprite to the layer.
65 	public void addSprite(ABitmap s, int n, Coordinate c, ushort paletteSel = 0, int scaleHoriz = 1024, 
66 			int scaleVert = 1024) @safe nothrow;
67 	///Adds a sprite to the layer.
68 	public void addSprite(ABitmap s, int n, int x, int y, ushort paletteSel = 0, int scaleHoriz = 1024, 
69 			int scaleVert = 1024) @safe nothrow;
70 	///Sets the rendering function for the sprite (defaults to the layer's rendering function)
71 	public void setSpriteRenderingMode(int n, RenderingMode mode) @safe nothrow;
72 	///Replaces the sprite. If the new sprite has a different dimension, the old sprite's upper-left corner will be used.
73 	public void replaceSprite(ABitmap s, int n) @safe nothrow;
74 	///Replaces the sprite and moves to the given position.
75 	public void replaceSprite(ABitmap s, int n, int x, int y) @safe nothrow;
76 	///Replaces the sprite and moves to the given position.
77 	public void replaceSprite(ABitmap s, int n, Coordinate c) @safe nothrow;
78 	///Returns the displayed portion of the sprite.
79 	public @nogc Coordinate getSlice(int n) @safe nothrow;
80 	///Writes the displayed portion of the sprite.
81 	///Returns the new slice, if invalid (greater than the bitmap, etc.) returns the old one.
82 	public Coordinate setSlice(int n, Coordinate slice) @safe nothrow;
83 	///Returns the selected paletteID of the sprite.
84 	public @nogc ushort getPaletteID(int n) @safe nothrow;
85 	///Sets the paletteID of the sprite. Returns the new ID, which is truncated to the possible values with a simple binary and operation
86 	///Palette must exist in the parent Raster, otherwise AccessError might happen
87 	public @nogc ushort setPaletteID(int n, ushort paletteID) @safe nothrow;
88 	///Scales bitmap horizontally
89 	public int scaleSpriteHoriz(int n, int hScl) @trusted nothrow;
90 	///Scales bitmap vertically
91 	public int scaleSpriteVert(int n, int vScl) @trusted nothrow;
92 	///Gets the sprite's current horizontal scale value
93 	public int getScaleSpriteHoriz(int n) @nogc @trusted nothrow;
94 	///Gets the sprite's current vertical scale value
95 	public int getScaleSpriteVert(int n) @nogc @trusted nothrow;
96 }