1#include <game/editor/editor.h>
2
3CLayerFront::CLayerFront(CEditorMap *pMap, int w, int h) :
4 CLayerTiles(pMap, w, h)
5{
6 str_copy(dst&: m_aName, src: "Front");
7 m_HasFront = true;
8}
9
10void CLayerFront::SetTile(int x, int y, CTile Tile)
11{
12 if(Tile.m_Index == TILE_THROUGH_CUT)
13 {
14 Map()->m_pGameLayer->CLayerTiles::SetTile(x, y, Tile: CTile{.m_Index: TILE_NOHOOK}); // NOLINT(bugprone-parent-virtual-call)
15 }
16 else if(Tile.m_Index == TILE_AIR && CLayerTiles::GetTile(x, y).m_Index == TILE_THROUGH_CUT)
17 {
18 Map()->m_pGameLayer->CLayerTiles::SetTile(x, y, Tile: CTile{.m_Index: TILE_AIR}); // NOLINT(bugprone-parent-virtual-call)
19 }
20 if(Editor()->IsAllowPlaceUnusedTiles() || IsValidFrontTile(Index: Tile.m_Index))
21 {
22 CLayerTiles::SetTile(x, y, Tile);
23 }
24 else
25 {
26 CLayerTiles::SetTile(x, y, Tile: CTile{.m_Index: TILE_AIR});
27 ShowPreventUnusedTilesWarning();
28 }
29}
30
31void CLayerFront::Resize(int NewW, int NewH)
32{
33 // resize tile data
34 CLayerTiles::Resize(NewW, NewH);
35
36 // resize gamelayer too
37 if(Map()->m_pGameLayer->m_Width != NewW || Map()->m_pGameLayer->m_Height != NewH)
38 Map()->m_pGameLayer->Resize(NewW, NewH);
39}
40
41bool CLayerFront::IsEmpty() const
42{
43 for(int y = 0; y < m_Height; y++)
44 {
45 for(int x = 0; x < m_Width; x++)
46 {
47 const int Index = GetTile(x, y).m_Index;
48 if(Index == 0)
49 {
50 continue;
51 }
52 if(Editor()->IsAllowPlaceUnusedTiles() || IsValidFrontTile(Index))
53 {
54 return false;
55 }
56 }
57 }
58 return true;
59}
60
61const char *CLayerFront::TypeName() const
62{
63 return "front";
64}
65