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

Method BrushDraw

src/game/editor/mapitems/layer_tune.cpp:81–158  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

79}
80
81void CLayerTune::BrushDraw(CLayer *pBrush, vec2 WorldPos)
82{
83 if(m_Readonly)
84 return;
85
86 CLayerTune *pTuneLayer = static_cast<CLayerTune *>(pBrush);
87 int sx = ConvertX(WorldPos.x);
88 int sy = ConvertY(WorldPos.y);
89 if(str_comp(pTuneLayer->m_aFilename, pTuneLayer->Map()->m_aFilename))
90 {
91 Editor()->m_TuningNumber = pTuneLayer->m_TuningNumber;
92 }
93
94 bool Destructive = Editor()->m_BrushDrawDestructive || pTuneLayer->IsEmpty();
95
96 for(int y = 0; y < pTuneLayer->m_Height; y++)
97 for(int x = 0; x < pTuneLayer->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 * pTuneLayer->m_Width + x;
109 const int TgtIndex = fy * m_Width + fx;
110
111 STuneTileStateChange::SData Previous{
112 m_pTuneTile[TgtIndex].m_Number,
113 m_pTuneTile[TgtIndex].m_Type,
114 m_pTiles[TgtIndex].m_Index};
115
116 if((Editor()->IsAllowPlaceUnusedTiles() || IsValidTuneTile(pTuneLayer->m_pTiles[SrcIndex].m_Index)) && pTuneLayer->m_pTiles[SrcIndex].m_Index != TILE_AIR)
117 {
118 if(Editor()->m_TuningNumber != pTuneLayer->m_TuningNumber)
119 {
120 m_pTuneTile[TgtIndex].m_Number = Editor()->m_TuningNumber;
121 }
122 else if(pTuneLayer->m_pTuneTile[SrcIndex].m_Number)
123 m_pTuneTile[TgtIndex].m_Number = pTuneLayer->m_pTuneTile[SrcIndex].m_Number;
124 else
125 {
126 if(!Editor()->m_TuningNumber)
127 {
128 m_pTuneTile[TgtIndex].m_Number = 0;
129 m_pTuneTile[TgtIndex].m_Type = 0;
130 m_pTiles[TgtIndex].m_Index = 0;
131 continue;
132 }
133 else
134 m_pTuneTile[TgtIndex].m_Number = Editor()->m_TuningNumber;
135 }
136
137 m_pTuneTile[TgtIndex].m_Type = pTuneLayer->m_pTiles[SrcIndex].m_Index;
138 m_pTiles[TgtIndex].m_Index = pTuneLayer->m_pTiles[SrcIndex].m_Index;

Callers

nothing calls this directly

Calls 5

str_compFunction · 0.85
IsValidTuneTileFunction · 0.85
MapMethod · 0.45
IsEmptyMethod · 0.45

Tested by

no test coverage detected