1/* (c) Magnus Auvinen. See licence.txt in the root of the distribution for more information. */
2/* If you are missing that file, acquire a complete release at teeworlds.com. */
3#include "layer_game.h"
4
5#include <game/editor/editor.h>
6
7CLayerGame::CLayerGame(CEditor *pEditor, int w, int h) :
8 CLayerTiles(pEditor, w, h)
9{
10 str_copy(dst&: m_aName, src: "Game");
11 m_Game = 1;
12}
13
14CLayerGame::~CLayerGame() = default;
15
16CTile CLayerGame::GetTile(int x, int y)
17{
18 if(m_pEditor->m_Map.m_pFrontLayer && m_pEditor->m_Map.m_pFrontLayer->GetTile(x, y).m_Index == TILE_THROUGH_CUT)
19 {
20 CTile through_cut = {.m_Index: TILE_THROUGH_CUT};
21 return through_cut;
22 }
23 else
24 {
25 return CLayerTiles::GetTile(x, y);
26 }
27}
28
29void CLayerGame::SetTile(int x, int y, CTile Tile)
30{
31 if(Tile.m_Index == TILE_THROUGH_CUT && m_pEditor->m_SelectEntitiesImage == "DDNet")
32 {
33 if(!m_pEditor->m_Map.m_pFrontLayer)
34 {
35 std::shared_ptr<CLayer> pLayerFront = std::make_shared<CLayerFront>(args&: m_pEditor, args&: m_Width, args&: m_Height);
36 m_pEditor->m_Map.MakeFrontLayer(pLayer: pLayerFront);
37 m_pEditor->m_Map.m_pGameGroup->AddLayer(pLayer: pLayerFront);
38 }
39 CTile nohook = {.m_Index: TILE_NOHOOK};
40 CLayerTiles::SetTile(x, y, Tile: nohook);
41 CTile through_cut = {.m_Index: TILE_THROUGH_CUT};
42 m_pEditor->m_Map.m_pFrontLayer->CLayerTiles::SetTile(x, y, Tile: through_cut); // NOLINT(bugprone-parent-virtual-call)
43 }
44 else
45 {
46 if(m_pEditor->m_SelectEntitiesImage == "DDNet" && m_pEditor->m_Map.m_pFrontLayer && m_pEditor->m_Map.m_pFrontLayer->GetTile(x, y).m_Index == TILE_THROUGH_CUT)
47 {
48 CTile air = {.m_Index: TILE_AIR};
49 m_pEditor->m_Map.m_pFrontLayer->CLayerTiles::SetTile(x, y, Tile: air); // NOLINT(bugprone-parent-virtual-call)
50 }
51 if(m_pEditor->m_AllowPlaceUnusedTiles || IsValidGameTile(Index: Tile.m_Index))
52 {
53 CLayerTiles::SetTile(x, y, Tile);
54 }
55 else
56 {
57 CTile air = {.m_Index: TILE_AIR};
58 CLayerTiles::SetTile(x, y, Tile: air);
59 ShowPreventUnusedTilesWarning();
60 }
61 }
62}
63
64CUi::EPopupMenuFunctionResult CLayerGame::RenderProperties(CUIRect *pToolbox)
65{
66 const CUi::EPopupMenuFunctionResult Result = CLayerTiles::RenderProperties(pToolbox);
67 m_Image = -1;
68 return Result;
69}
70
71const char *CLayerGame::TypeName() const
72{
73 return "game";
74}
75