Skip to content

Commit

Permalink
Note list scopes & grouping, support for regions in progress
Browse files Browse the repository at this point in the history
  • Loading branch information
johnnovak committed Mar 24, 2024
1 parent 4f84cf4 commit cdf1211
Show file tree
Hide file tree
Showing 5 changed files with 271 additions and 155 deletions.
21 changes: 11 additions & 10 deletions src/actions.nim
Original file line number Diff line number Diff line change
Expand Up @@ -290,7 +290,7 @@ proc setLink*(map; src, dest: Location, floorColor: Natural; um) =
elif srcFloor == fExitDoor: destFloor = fEntranceDoor
elif srcFloor in LinkStairs:
let
srcElevation = m.levels[src.level].elevation
srcElevation = m.levels[src.level].elevation
destElevation = m.levels[dest.level].elevation

if srcElevation < destElevation:
Expand All @@ -317,6 +317,7 @@ proc setLink*(map; src, dest: Location, floorColor: Natural; um) =
m.links.set(dest, src)
else:
m.links.set(src, dest)

m.levels[dest.level].reindexNotes()
result = usd

Expand Down Expand Up @@ -740,17 +741,17 @@ proc deleteLevel*(map; loc: Location; um): Location =
let restoredLevel = undoLevel.deepCopy

if loc.level > m.levels.high:
m.levels.add(restoredLevel)
m.addLevel(restoredLevel)
else:
# Move to the end
let lastLevel = m.levels[loc.level]
m.levels.add(lastLevel)
m.addLevel(lastLevel)
m.setLevel(idx=loc.level, restoredLevel)
m.sortLevels()

m.levels[loc.level] = restoredLevel
m.links.remapLevelIndex(oldIndex = loc.level, newIndex = m.levels.high)
m.links.debugSanitise()

m.sortLevels()
m.links.addAll(oldLinks)
m.links.debugSanitise()

Expand Down Expand Up @@ -822,7 +823,7 @@ proc resizeLevel*(map; loc: Location, newRows, newCols: Natural,
oldRegions = map.levels[loc.level].regions

let undoAction = proc (m: var Map): UndoStateData =
m.levels[loc.level] = undoLevel.deepCopy
m.setLevel(idx=loc.level, undoLevel.deepCopy)

for src in newLinks.sources: m.links.delBySrc(src)
m.links.addAll(oldLinks)
Expand Down Expand Up @@ -856,7 +857,7 @@ proc cropLevel*(map; loc: Location, cropRect: Rect[Natural]; um): Location =
newLevelRect, wraparound=false)

let action = proc (m: var Map): UndoStateData =
m.levels[loc.level] = m.newLevelFrom(loc.level, cropRect)
m.setLevel(idx=loc.level, m.newLevelFrom(loc.level, cropRect))

# Adjust links
for src in oldLinks.sources: m.links.delBySrc(src)
Expand All @@ -875,7 +876,7 @@ proc cropLevel*(map; loc: Location, cropRect: Rect[Natural]; um): Location =
oldRegions = map.levels[loc.level].regions

let undoAction = proc (m: var Map): UndoStateData =
m.levels[loc.level] = undoLevel.deepCopy
m.setLevel(idx=loc.level, undoLevel.deepCopy)

for src in newLinks.sources: m.links.delBySrc(src)
m.links.addAll(oldLinks)
Expand Down Expand Up @@ -931,7 +932,7 @@ proc nudgeLevel*(map; loc: Location, rowOffs, colOffs: int,
discard l.paste(rowOffs, colOffs, sb.level, sb.selection,
pasteTrail=true)

m.levels[loc.level] = l
m.setLevel(idx=loc.level, l)

for src in oldLinks.sources: m.links.delBySrc(src)
m.links.addAll(newLinks)
Expand All @@ -947,7 +948,7 @@ proc nudgeLevel*(map; loc: Location, rowOffs, colOffs: int,
let undoLevel = sb.level.deepCopy

let undoAction = proc (m: var Map): UndoStateData =
m.levels[loc.level] = undoLevel.deepCopy
m.setLevel(idx=loc.level, undoLevel.deepCopy)

for src in newLinks.sources: m.links.delBySrc(src)
m.links.addAll(oldLinks)
Expand Down
3 changes: 2 additions & 1 deletion src/common.nim
Original file line number Diff line number Diff line change
Expand Up @@ -86,8 +86,9 @@ type
notes*: string

levels*: seq[Level]
coordOpts*: CoordinateOptions
levelsDirty*: bool

coordOpts*: CoordinateOptions
links*: Links

sortedLevelNames*: seq[string]
Expand Down
14 changes: 14 additions & 0 deletions src/level.nim
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import std/math
import std/options
import std/strformat

import annotations
import common
Expand Down Expand Up @@ -263,6 +264,19 @@ proc initRegionsFrom*(srcLevel: Option[Level] = Level.none, destLevel: Level,

# }}}

# {{{ getDetailedName*()
proc getDetailedName*(l; short = false): string =
let elevation = if l.elevation == 0: "G" else: $l.elevation
if l.levelName == "":
fmt"{l.locationName} ({elevation})"
else:
if short:
fmt"{l.levelName} ({elevation})"
else:
fmt"{l.locationName} {EnDash} {l.levelName} ({elevation})"

# }}}

# {{{ hasTrail*()
proc hasTrail*(l; r,c: Natural): bool {.inline.} =
l.cellGrid.hasTrail(r,c)
Expand Down
Loading

0 comments on commit cdf1211

Please sign in to comment.