Skip to content

Commit 2867f7d

Browse files
committed
Merge origin/tmm-dev into tmm-dev
2 parents 62c4395 + d74333d commit 2867f7d

7 files changed

+162
-174
lines changed

source/GM-TE/GMTEBrush.class.st

Lines changed: 97 additions & 97 deletions
Original file line numberDiff line numberDiff line change
@@ -46,18 +46,18 @@ GMTEBrush >> currentMatrixIndex: anObject [
4646

4747
{
4848
#category : #'as yet unclassified',
49-
#'squeak_changestamp' : 'Valentin Teutschbein 7/9/2024 08:47'
49+
#'squeak_changestamp' : 'JS 7/11/2024 13:59'
5050
}
5151
GMTEBrush >> executeWithMatrixIndex: anIndex andLayer: aLayer [
5252

5353
self currentMatrixIndex: anIndex.
5454
self layer: aLayer.
55-
^ self currentBrush value.
55+
^ self currentBrush value
5656
]
5757

5858
{
5959
#category : #forms,
60-
#'squeak_changestamp' : 'Valentin Teutschbein 7/9/2024 22:04'
60+
#'squeak_changestamp' : 'JS 7/11/2024 14:07'
6161
}
6262
GMTEBrush >> fillBrush [
6363

@@ -67,27 +67,27 @@ GMTEBrush >> fillBrush [
6767

6868
visited := Matrix rows: (self layer rowCount) columns: self layer columnCount.
6969
collection := OrderedCollection new.
70-
startTile := layer at: self currentMatrixIndex y at: self currentMatrixIndex x.
70+
startTile := self layer at: self currentMatrixIndex y at: self currentMatrixIndex x.
7171

72-
collection add: currentMatrixIndex.
72+
collection add: self currentMatrixIndex.
7373
visited at: self currentMatrixIndex y at: self currentMatrixIndex x put: true.
7474

7575
self fillDfsWithVisited: visited andIndex: self currentMatrixIndex andOriginTile: startTile andCollection: collection.
7676
self outputSet: collection asSet.
7777

78-
^ self outputSet.
78+
^ self outputSet
7979
]
8080

8181
{
8282
#category : #forms,
83-
#'squeak_changestamp' : 'JS 7/6/2024 16:46'
83+
#'squeak_changestamp' : 'JS 7/11/2024 13:58'
8484
}
8585
GMTEBrush >> fillDfsWithVisited: aVisitedMatrix andIndex: anIndex andOriginTile: anOriginTile andCollection: aCollection [
8686

8787
| borderingOffsets |
8888
self flag: 'REFACTOR!'.
8989
borderingOffsets := {(-1)@0. 0@(-1). 1@0. 0@1}.
90-
borderingOffsets do: [: offset|
90+
borderingOffsets do: [:offset |
9191
| newIndex newTile |
9292
newIndex := offset + anIndex.
9393
((self layer inBounds: newIndex) and: [(aVisitedMatrix at: newIndex y at: newIndex x) isNil]) ifTrue:[
@@ -97,10 +97,10 @@ GMTEBrush >> fillDfsWithVisited: aVisitedMatrix andIndex: anIndex andOriginTile:
9797
aVisitedMatrix at: newIndex y at: newIndex x put: true.
9898
self fillDfsWithVisited: aVisitedMatrix andIndex: newIndex andOriginTile: anOriginTile andCollection: aCollection]]
9999
ifNotNil: [
100-
(newTile isNil not and: [anOriginTile imageForm bits hash = newTile imageForm bits hash])
101-
ifTrue: [aCollection add: newIndex.
102-
aVisitedMatrix at: newIndex y at: newIndex x put: true.
103-
self fillDfsWithVisited: aVisitedMatrix andIndex: newIndex andOriginTile: anOriginTile andCollection: aCollection]]]]
100+
(newTile isNil not and: [anOriginTile imageForm bits hash = newTile imageForm bits hash]) ifTrue: [
101+
aCollection add: newIndex.
102+
aVisitedMatrix at: newIndex y at: newIndex x put: true.
103+
self fillDfsWithVisited: aVisitedMatrix andIndex: newIndex andOriginTile: anOriginTile andCollection: aCollection]]]]
104104
]
105105

106106
{
@@ -121,12 +121,21 @@ GMTEBrush >> firstMatrixIndex: anObject [
121121

122122
{
123123
#category : #forms,
124-
#'squeak_changestamp' : 'Valentin Teutschbein 7/9/2024 21:33'
124+
#'squeak_changestamp' : 'JS 7/11/2024 13:59'
125125
}
126126
GMTEBrush >> initialize [
127127

128128
super initialize.
129-
self resetOutputSet.
129+
self resetOutputSet
130+
]
131+
132+
{
133+
#category : #forms,
134+
#'squeak_changestamp' : 'JS 7/11/2024 14:04'
135+
}
136+
GMTEBrush >> isPointInRadius: aPoint [
137+
self flag: 'to long? - refactor with lineBrush in mind'.
138+
^(( self currentMatrixIndex x - aPoint x) squared + ( self currentMatrixIndex y - aPoint y) squared <= (self radius - 1) squared)
130139
]
131140

132141
{
@@ -147,56 +156,50 @@ GMTEBrush >> layer: anObject [
147156

148157
{
149158
#category : #forms,
150-
#'squeak_changestamp' : 'Valentin Teutschbein 7/9/2024 22:53'
159+
#'squeak_changestamp' : 'JS 7/11/2024 14:09'
151160
}
152161
GMTEBrush >> lineBrush [
153-
| radius collection start end deltaX deltaY stepX stepY error error2 x y offsets |
154-
162+
| radius collection start end deltaX deltaY stepX stepY error error2 x y offsets |
163+
self flag: 'refactor - do instead of collect or select'.
155164
radius := self radius - 1.
156165
self resetOutputSet.
157166
self flag: 'todo: method extraction'.
158-
"Helper method to generate radius offsets"
159-
offsets := OrderedCollection new.
160-
(0-radius to: radius) do: [:dx |
161-
(0-radius to: radius) do: [:dy |
162-
(dx * dx + dy * dy <= (radius * radius)) ifTrue: [
163-
offsets add: dx @ dy.
164-
].
165-
].
166-
].
167-
168-
self resetOutputSet.
169-
(self currentMatrixIndex isNil or: [self firstMatrixIndex isNil]) ifTrue: [^nil].
170-
171-
start := self firstMatrixIndex.
172-
end := self currentMatrixIndex.
173-
deltaX := (end x - start x) abs.
174-
deltaY := (end y - start y) abs.
175-
stepX := (start x < end x) ifTrue: [1] ifFalse: [-1].
176-
stepY := (start y < end y) ifTrue: [1] ifFalse: [-1].
177-
error := deltaX - deltaY.
178-
x := start x.
179-
y := start y.
180-
181-
collection := OrderedCollection new.
182-
183-
[
184-
| point |
185-
point := x @ y.
186-
offsets do: [:offset | collection add: (point + offset)].
187-
(x = end x and: [y = end y]) ifTrue: [
188-
self outputSet: collection asSet.
189-
^ self outputSet.].
190-
error2 := 2 * error.
191-
(error2 > (0 - deltaY)) ifTrue: [
192-
error := error - deltaY.
193-
x := x + stepX.
194-
].
195-
(error2 < deltaX) ifTrue: [
196-
error := error + deltaX.
197-
y := y + stepY.
198-
].
199-
] repeat.
167+
"Helper method to generate radius offsets"
168+
offsets := OrderedCollection new.
169+
(0-radius to: radius) do: [:dx |
170+
(0-radius to: radius) do: [:dy |
171+
((dx * dx) + (dy * dy) <= (radius * radius)) ifTrue: [offsets add: dx @ dy]]].
172+
173+
self resetOutputSet.
174+
(self currentMatrixIndex isNil or: [self firstMatrixIndex isNil]) ifTrue: [^nil].
175+
176+
start := self firstMatrixIndex.
177+
end := self currentMatrixIndex.
178+
deltaX := (end x - start x) abs.
179+
deltaY := (end y - start y) abs.
180+
stepX := (start x < end x) ifTrue: [1] ifFalse: [-1].
181+
stepY := (start y < end y) ifTrue: [1] ifFalse: [-1].
182+
error := deltaX - deltaY.
183+
x := start x.
184+
y := start y.
185+
186+
collection := OrderedCollection new.
187+
188+
[
189+
| point |
190+
point := x @ y.
191+
offsets do: [:offset | collection add: (point + offset)].
192+
(x = end x and: [y = end y]) ifTrue: [
193+
self outputSet: collection asSet.
194+
^ self outputSet].
195+
error2 := 2 * error.
196+
(error2 > (0 - deltaY)) ifTrue: [
197+
error := error - deltaY.
198+
x := x + stepX].
199+
(error2 < deltaX) ifTrue: [
200+
error := error + deltaX.
201+
y := y + stepY]
202+
] repeat
200203

201204
]
202205

@@ -234,71 +237,68 @@ GMTEBrush >> radius: anObject [
234237

235238
{
236239
#category : #forms,
237-
#'squeak_changestamp' : 'Valentin Teutschbein 7/10/2024 12:37'
240+
#'squeak_changestamp' : 'JS 7/11/2024 14:06'
238241
}
239242
GMTEBrush >> radiusBrush [
240243

241-
| collection xMin xMax yMin yMax |
242-
self currentMatrixIndex ifNil: [^nil].
244+
| collection xMin xMax yMin yMax |
245+
self currentMatrixIndex ifNil: [^nil].
243246

244-
collection := OrderedCollection new.
247+
collection := OrderedCollection new.
245248
self flag: 'radius offset is bad'.
246-
xMin := self currentMatrixIndex x - (self radius - 1).
247-
xMax := self currentMatrixIndex x + (self radius - 1).
248-
yMin := self currentMatrixIndex y - (self radius - 1).
249-
yMax := self currentMatrixIndex y + (self radius - 1).
249+
xMin := self currentMatrixIndex x - (self radius - 1).
250+
xMax := self currentMatrixIndex x + (self radius - 1).
251+
yMin := self currentMatrixIndex y - (self radius - 1).
252+
yMax := self currentMatrixIndex y + (self radius - 1).
250253

251-
(xMin to: xMax) do: [:x |
252-
(yMin to: yMax) do: [:y |
253-
(( self currentMatrixIndex x - x) squared + ( self currentMatrixIndex y - y) squared <= (self radius - 1) squared) ifTrue: [
254-
collection add: x@y
255-
].
256-
].
257-
].
254+
self flag: 'select instead of do?'.
255+
(xMin to: xMax) do: [:x |
256+
(yMin to: yMax) do: [:y |
257+
(self isPointInRadius: x @ y) ifTrue: [collection add: x @ y]]].
258258

259-
collection do: [:i | self outputSet add: i].
259+
collection do: [:i |
260+
self outputSet add: i].
260261

261-
^ self outputSet.
262+
^ self outputSet
262263

263264
]
264265

265266
{
266267
#category : #forms,
267-
#'squeak_changestamp' : 'Valentin Teutschbein 7/9/2024 22:04'
268+
#'squeak_changestamp' : 'JS 7/11/2024 13:49'
268269
}
269270
GMTEBrush >> rectangleBrush [
270271

271-
| collection startRow endRow startCol endCol |
272+
| collection startRow endRow startCol endCol |
272273
self resetOutputSet.
273-
(self currentMatrixIndex isNil or: [self firstMatrixIndex isNil]) ifTrue: [^nil].
274-
collection := OrderedCollection new.
275-
276-
"Determine the starting and ending rows and columns"
277-
278-
startRow := (self currentMatrixIndex x min: self firstMatrixIndex x).
279-
endRow := (self currentMatrixIndex x max: self firstMatrixIndex x).
280-
startCol := (self currentMatrixIndex y min: self firstMatrixIndex y).
281-
endCol := (self currentMatrixIndex y max: self firstMatrixIndex y).
282-
283-
"Fill the collection with all indices within the rectangle"
284-
startRow to: endRow do: [:row |
285-
startCol to: endCol do: [:col |
286-
collection add: (row@col)
287-
].
288-
].
274+
(self currentMatrixIndex isNil or: [self firstMatrixIndex isNil]) ifTrue: [^nil].
275+
collection := OrderedCollection new.
276+
277+
"Determine the starting and ending rows and columns"
278+
self flag: 'method extraction'.
279+
startRow := (self currentMatrixIndex x min: self firstMatrixIndex x).
280+
endRow := (self currentMatrixIndex x max: self firstMatrixIndex x).
281+
startCol := (self currentMatrixIndex y min: self firstMatrixIndex y).
282+
endCol := (self currentMatrixIndex y max: self firstMatrixIndex y).
283+
284+
"Fill the collection with all indices within the rectangle"
285+
startRow to: endRow do: [:row |
286+
startCol to: endCol do: [:col |
287+
collection add: (row @ col)]].
288+
289289
self outputSet: collection asSet.
290290

291-
^ self outputSet.
291+
^ self outputSet
292292

293293
]
294294

295295
{
296296
#category : #select,
297-
#'squeak_changestamp' : 'Valentin Teutschbein 7/9/2024 21:26'
297+
#'squeak_changestamp' : 'JS 7/11/2024 13:43'
298298
}
299299
GMTEBrush >> resetOutputSet [
300300

301-
self outputSet: Set new.
301+
self outputSet: Set new
302302
]
303303

304304
{

source/GM-TE/GMTEDeleteLayersCommand.class.st

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
Class {
22
#name : #GMTEDeleteLayersCommand,
3-
#superclass : #GMTETilemapSizeCommand,
3+
#superclass : #GMTEEditTilesCommand,
44
#instVars : [
55
'layers'
66
],

source/GM-TE/GMTEEditTilesCommand.class.st

Lines changed: 26 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -40,18 +40,38 @@ GMTEEditTilesCommand >> currentSprites: anObject [
4040

4141
{
4242
#category : #execution,
43-
#'squeak_changestamp' : 'TW 7/2/2024 17:54'
43+
#'squeak_changestamp' : 'Alex M 7/10/2024 13:42'
4444
}
4545
GMTEEditTilesCommand >> do [
46+
47+
self placeTilesFromList: self currentSprites
48+
]
49+
50+
{
51+
#category : #initialization,
52+
#'squeak_changestamp' : 'Alex M 6/28/2024 02:45'
53+
}
54+
GMTEEditTilesCommand >> initialize [
55+
56+
self
57+
previousSprites: Dictionary new;
58+
currentSprites: Dictionary new
59+
]
60+
61+
{
62+
#category : #execution,
63+
#'squeak_changestamp' : 'Alex M 7/10/2024 13:44'
64+
}
65+
GMTEEditTilesCommand >> placeTilesFromList: aList [
4666
| tile sprite layer x y |
4767

48-
self currentSprites keysDo: [ :coordinates |
68+
aList keysDo: [ :coordinates |
4969
x := coordinates at: 1.
5070
y := coordinates at: 2.
5171
layer := coordinates at: 3.
5272

5373
tile := self tileMap tileMatrixStack layer: layer at: y at: x.
54-
sprite := self currentSprites at: coordinates.
74+
sprite := aList at: coordinates.
5575
tile
5676
ifNil: [sprite
5777
ifNotNil: [
@@ -61,18 +81,7 @@ GMTEEditTilesCommand >> do [
6181
ifNil: [
6282
self tileMap tileMatrixStack layer: layer at: y at: x put: nil.
6383
tile abandon]
64-
ifNotNil: [tile updateSprite: (self currentSprites at: coordinates)]]]
65-
]
66-
67-
{
68-
#category : #initialization,
69-
#'squeak_changestamp' : 'Alex M 6/28/2024 02:45'
70-
}
71-
GMTEEditTilesCommand >> initialize [
72-
73-
self
74-
previousSprites: Dictionary new;
75-
currentSprites: Dictionary new
84+
ifNotNil: [tile updateSprite: (aList at: coordinates)]]]
7685
]
7786

7887
{
@@ -109,26 +118,9 @@ GMTEEditTilesCommand >> tileMap: anObject [
109118

110119
{
111120
#category : #execution,
112-
#'squeak_changestamp' : 'TW 7/2/2024 17:54'
121+
#'squeak_changestamp' : 'Alex M 7/10/2024 13:43'
113122
}
114123
GMTEEditTilesCommand >> undo [
115-
| tile sprite layer x y |
116124

117-
self previousSprites keysDo: [ :coordinates |
118-
x := coordinates at: 1.
119-
y := coordinates at: 2.
120-
layer := coordinates at: 3.
121-
122-
tile := self tileMap tileMatrixStack layer: layer at: y at: x.
123-
sprite := self previousSprites at: coordinates.
124-
tile
125-
ifNil: [sprite
126-
ifNotNil: [
127-
tile := tileMap generateTileAtlayer: layer x: x y: y stack: self tileMap tileMatrixStack tileType: GMTETile.
128-
tile updateSprite: sprite]]
129-
ifNotNil: [sprite
130-
ifNil: [
131-
self tileMap tileMatrixStack layer: layer at: y at: x put: nil.
132-
tile abandon]
133-
ifNotNil: [tile updateSprite: (self previousSprites at: coordinates)]]]
125+
self placeTilesFromList: self previousSprites
134126
]

0 commit comments

Comments
 (0)