MCPcopy Create free account
hub / github.com/ddnet/ddnet / BrushDraw

Method BrushDraw

src/game/editor/mapitems/layer_switch.cpp:80–176  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

78}
79
80void CLayerSwitch::BrushDraw(CLayer *pBrush, vec2 WorldPos)
81{
82 if(m_Readonly)
83 return;
84
85 CLayerSwitch *pSwitchLayer = static_cast<CLayerSwitch *>(pBrush);
86 int sx = ConvertX(WorldPos.x);
87 int sy = ConvertY(WorldPos.y);
88 if(str_comp(pSwitchLayer->m_aFilename, pSwitchLayer->Map()->m_aFilename))
89 {
90 Editor()->m_SwitchNumber = pSwitchLayer->m_SwitchNumber;
91 Editor()->m_SwitchDelay = pSwitchLayer->m_SwitchDelay;
92 }
93
94 bool Destructive = Editor()->m_BrushDrawDestructive || pSwitchLayer->IsEmpty();
95
96 for(int y = 0; y < pSwitchLayer->m_Height; y++)
97 for(int x = 0; x < pSwitchLayer->m_Width; x++)
98 {
99 int fx = x + sx;
100 int fy = y + sy;
101
102 if(fx < 0 || fx >= m_Width || fy < 0 || fy >= m_Height)
103 continue;
104
105 if(!Destructive && GetTile(fx, fy).m_Index)
106 continue;
107
108 const int SrcIndex = y * pSwitchLayer->m_Width + x;
109 const int TgtIndex = fy * m_Width + fx;
110
111 SSwitchTileStateChange::SData Previous{
112 m_pSwitchTile[TgtIndex].m_Number,
113 m_pSwitchTile[TgtIndex].m_Type,
114 m_pSwitchTile[TgtIndex].m_Flags,
115 m_pSwitchTile[TgtIndex].m_Delay,
116 m_pTiles[TgtIndex].m_Index};
117
118 if((Editor()->IsAllowPlaceUnusedTiles() || IsValidSwitchTile(pSwitchLayer->m_pTiles[SrcIndex].m_Index)) && pSwitchLayer->m_pTiles[SrcIndex].m_Index != TILE_AIR)
119 {
120 if(Editor()->m_SwitchNumber != pSwitchLayer->m_SwitchNumber || Editor()->m_SwitchDelay != pSwitchLayer->m_SwitchDelay)
121 {
122 m_pSwitchTile[TgtIndex].m_Number = Editor()->m_SwitchNumber;
123 m_pSwitchTile[TgtIndex].m_Delay = Editor()->m_SwitchDelay;
124 }
125 else if(pSwitchLayer->m_pSwitchTile[SrcIndex].m_Number)
126 {
127 m_pSwitchTile[TgtIndex].m_Number = pSwitchLayer->m_pSwitchTile[SrcIndex].m_Number;
128 m_pSwitchTile[TgtIndex].m_Delay = pSwitchLayer->m_pSwitchTile[SrcIndex].m_Delay;
129 }
130 else
131 {
132 m_pSwitchTile[TgtIndex].m_Number = Editor()->m_SwitchNumber;
133 m_pSwitchTile[TgtIndex].m_Delay = Editor()->m_SwitchDelay;
134 }
135
136 m_pSwitchTile[TgtIndex].m_Type = pSwitchLayer->m_pTiles[SrcIndex].m_Index;
137 m_pSwitchTile[TgtIndex].m_Flags = pSwitchLayer->m_pTiles[SrcIndex].m_Flags;

Callers

nothing calls this directly

Calls 8

str_compFunction · 0.85
IsValidSwitchTileFunction · 0.85
IsSwitchTileFlagsUsedFunction · 0.85
IsSwitchTileNumberUsedFunction · 0.85
IsSwitchTileDelayUsedFunction · 0.85
MapMethod · 0.45
IsEmptyMethod · 0.45

Tested by

no test coverage detected