-
-
Notifications
You must be signed in to change notification settings - Fork 72
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feature: adds the single move tool (#218)
* feature: move tool adds the move tool that allows you to move single objects * prettify * removes unused
- Loading branch information
Showing
11 changed files
with
1,209 additions
and
979 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
package tools | ||
|
||
import ( | ||
"sdmm/internal/dmapi/dm" | ||
"sdmm/internal/dmapi/dmmap" | ||
"sdmm/internal/dmapi/dmmap/dmminstance" | ||
"sdmm/internal/util" | ||
) | ||
|
||
// ToolPick can be used move a single object. | ||
type ToolMove struct { | ||
tool | ||
instance *dmminstance.Instance | ||
lastTile *dmmap.Tile | ||
} | ||
|
||
func (ToolMove) Name() string { | ||
return TNMove | ||
} | ||
|
||
func newMove() *ToolMove { | ||
return &ToolMove{} | ||
} | ||
|
||
func (t *ToolMove) Stale() bool { | ||
return t.instance == nil | ||
} | ||
|
||
func (ToolMove) AltBehaviour() bool { | ||
return false | ||
} | ||
|
||
func (t *ToolMove) onStart(util.Point) { | ||
if hoveredInstance := ed.HoveredInstance(); hoveredInstance != nil { | ||
ed.InstanceSelect(hoveredInstance) | ||
t.instance = hoveredInstance | ||
} | ||
} | ||
|
||
func (t *ToolMove) onMove(coord util.Point) { | ||
if t.instance != nil { | ||
prefab := t.instance.Prefab() | ||
if t.lastTile != nil { | ||
t.lastTile.InstancesRegenerate() //should stop some issues | ||
} | ||
t.lastTile = ed.Dmm().GetTile(coord) | ||
ed.InstanceDelete(t.instance) | ||
t.lastTile.InstancesAdd(prefab) | ||
t.lastTile.InstancesRegenerate() | ||
for _, found := range t.lastTile.Instances() { | ||
if found.Prefab().Id() == prefab.Id() { | ||
t.instance = found | ||
break | ||
} | ||
} | ||
ed.UpdateCanvasByCoords([]util.Point{coord}) | ||
} | ||
} | ||
|
||
func (t *ToolMove) onStop(util.Point) { | ||
if t.instance != nil { | ||
//remove other turfs if we moved a turf | ||
if dm.IsPath(t.instance.Prefab().Path(), "/turf") { | ||
for _, found := range t.lastTile.Instances() { | ||
if dm.IsPath(found.Prefab().Path(), "/turf") && found != t.instance { | ||
ed.InstanceDelete(found) | ||
} | ||
} | ||
} | ||
t.instance = nil | ||
t.lastTile = nil | ||
go ed.CommitChanges("Moved Prefab") | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -38,4 +38,5 @@ const ( | |
KoFi = "\ue91d" | ||
Repeat = "\ue91e" | ||
AccessTime = "\ue91f" | ||
Shrink = "\ue98a" | ||
) |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file not shown.
Binary file not shown.
Oops, something went wrong.