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

Method FillSelection

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

Source from the content-addressed store, hash-verified

236}
237
238void CLayerSwitch::FillSelection(bool Empty, CLayer *pBrush, CUIRect Rect)
239{
240 if(m_Readonly || (!Empty && pBrush->m_Type != LAYERTYPE_TILES))
241 return;
242
243 Snap(&Rect);
244
245 int sx = ConvertX(Rect.x);
246 int sy = ConvertY(Rect.y);
247 int w = ConvertX(Rect.w);
248 int h = ConvertY(Rect.h);
249
250 CLayerSwitch *pLt = static_cast<CLayerSwitch *>(pBrush);
251
252 bool Destructive = Editor()->m_BrushDrawDestructive || Empty || pLt->IsEmpty();
253
254 for(int y = 0; y < h; y++)
255 {
256 for(int x = 0; x < w; x++)
257 {
258 int fx = x + sx;
259 int fy = y + sy;
260
261 if(fx < 0 || fx >= m_Width || fy < 0 || fy >= m_Height)
262 continue;
263
264 if(!Destructive && GetTile(fx, fy).m_Index)
265 continue;
266
267 const int SrcIndex = Empty ? 0 : (y * pLt->m_Width + x % pLt->m_Width) % (pLt->m_Width * pLt->m_Height);
268 const int TgtIndex = fy * m_Width + fx;
269
270 SSwitchTileStateChange::SData Previous{
271 m_pSwitchTile[TgtIndex].m_Number,
272 m_pSwitchTile[TgtIndex].m_Type,
273 m_pSwitchTile[TgtIndex].m_Flags,
274 m_pSwitchTile[TgtIndex].m_Delay,
275 m_pTiles[TgtIndex].m_Index};
276
277 if(Empty || (!Editor()->IsAllowPlaceUnusedTiles() && !IsValidSwitchTile((pLt->m_pTiles[SrcIndex]).m_Index)))
278 {
279 m_pTiles[TgtIndex].m_Index = 0;
280 m_pSwitchTile[TgtIndex].m_Type = 0;
281 m_pSwitchTile[TgtIndex].m_Number = 0;
282 m_pSwitchTile[TgtIndex].m_Delay = 0;
283
284 if(!Empty)
285 ShowPreventUnusedTilesWarning();
286 }
287 else
288 {
289 m_pTiles[TgtIndex] = pLt->m_pTiles[SrcIndex];
290 m_pSwitchTile[TgtIndex].m_Type = m_pTiles[TgtIndex].m_Index;
291 if(pLt->m_HasSwitch && m_pTiles[TgtIndex].m_Index > 0)
292 {
293 if(!IsSwitchTileNumberUsed(m_pSwitchTile[TgtIndex].m_Type))
294 m_pSwitchTile[TgtIndex].m_Number = 0;
295 else if(pLt->m_pSwitchTile[SrcIndex].m_Number == 0 || Editor()->m_SwitchNumber != pLt->m_SwitchNumber)

Callers

nothing calls this directly

Calls 6

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

Tested by

no test coverage detected