Skip to content

Commit

Permalink
Add option to pre-fill new levels with empty floors
Browse files Browse the repository at this point in the history
  • Loading branch information
johnnovak committed Jul 21, 2024
1 parent ed482f6 commit 42226ae
Show file tree
Hide file tree
Showing 5 changed files with 53 additions and 25 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
via the numeric keypad or the YUBN keys (à la Rogue).
- [Open-ended excavate](https://gridmonger.johnnovak.net/manual/basic-editing.html#open-ended-excavate)
option to aid in exploring tunnel-style dungeons.
- Option to pre-fill new levels with empty floors (for wall-style maps).
- New [Arrow floor type](TODO) to represent moving floors and conveyor belts.
- Option to select whether the Left/Right cursor keys perform strafing or
turning in [Walk Mode](https://gridmonger.johnnovak.net/manual/moving-around.html#walk-mode).
Expand Down
1 change: 0 additions & 1 deletion TODO
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ TODO
====

- add unlink command
- prefill level with empty floor (for wall style maps)

- finish diagonal movement (numpad, YUBN)
- improve restoring the window's size on screen dimension changes
Expand Down
9 changes: 8 additions & 1 deletion src/actions.nim
Original file line number Diff line number Diff line change
Expand Up @@ -657,7 +657,7 @@ proc pasteSelection*(map; loc, undoLoc: Location, sb: SelectionBuffer,
# {{{ addNewLevel*()
proc addNewLevel*(map; loc: Location,
locationName, levelName: string, elevation: int,
rows, cols: Natural,
rows, cols: Natural, fillFloorColor: Option[Natural],
overrideCoordOpts: bool, coordOpts: CoordinateOptions,
regionOpts: RegionOptions,
notes: string;
Expand All @@ -677,6 +677,13 @@ proc addNewLevel*(map; loc: Location,
regionOpts,
notes)
newLevelId = newLevel.id

if fillFloorColor.isSome:
var cell: Cell
cell.floor = fBlank
cell.floorColor = fillFloorColor.get.uint8
newLevel.fill(cell)

m.setLevel(newLevel)

var usd = usd
Expand Down
8 changes: 8 additions & 0 deletions src/level.nim
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,14 @@ proc setWall*(l; r,c: Natural, dir: CardinalDir, w: Wall) =
proc canSetWall*(l; r,c: Natural, dir: CardinalDir): bool {.inline.} =
not l.isEmpty(r,c) or not l.isNeighbourCellEmpty(r,c, {dir})

# }}}
# {{{ fill*()
proc fill*(l; rect: Rect[Natural], cell: Cell) =
l.cellGrid.fill(rect, cell)

proc fill*(l; cell: Cell) =
l.cellGrid.fill(cell)

# }}}

# }}}
Expand Down
59 changes: 36 additions & 23 deletions src/main.nim
Original file line number Diff line number Diff line change
Expand Up @@ -813,32 +813,33 @@ type


LevelPropertiesDialogParams = object
activeTab: Natural
activeTab: Natural
activateFirstTextField: bool

# General tab
locationName: string
levelName: string
elevation: string
rows: string
cols: string
locationName: string
levelName: string
elevation: string
rows: string
cols: string
fillWithEmptyFloors: bool

# Coordinates tab
overrideCoordOpts: bool
origin: Natural
rowStyle: Natural
columnStyle: Natural
rowStart: string
columnStart: string
overrideCoordOpts: bool
origin: Natural
rowStyle: Natural
columnStyle: Natural
rowStart: string
columnStart: string

# Regions tab
enableRegions: bool
colsPerRegion: string
rowsPerRegion: string
perRegionCoords: bool
enableRegions: bool
colsPerRegion: string
rowsPerRegion: string
perRegionCoords: bool

# Notes tab
notes: string
notes: string


ResizeLevelDialogParams = object
Expand Down Expand Up @@ -4726,6 +4727,12 @@ proc newLevelDialog(dlg: var LevelPropertiesDialogParams; a) =
if dlg.activeTab == 0: # General
commonLevelFields(dimensionsDisabled=false)

group:
koi.label("Fill with empty floors", style=a.theme.labelStyle)

koi.nextItemHeight(DlgCheckBoxSize)
koi.checkBox(dlg.fillWithEmptyFloors, style=a.theme.checkBoxStyle)

elif dlg.activeTab == 1: # Coordinates
group:
koi.label("Override map settings", style=a.theme.labelStyle)
Expand Down Expand Up @@ -4763,16 +4770,23 @@ proc newLevelDialog(dlg: var LevelPropertiesDialogParams; a) =
rows = parseInt(dlg.rows)
cols = parseInt(dlg.cols)

var fillFloorColor: Option[Natural]

let cur = actions.addNewLevel(
a.doc.map,
a.ui.cursor,

locationName = dlg.locationName,
levelName = dlg.levelName,
elevation = parseInt(dlg.elevation),
rows = rows,
cols = cols,
dlg.overrideCoordOpts,
levelName = dlg.levelName,
elevation = parseInt(dlg.elevation),

rows = rows,
cols = cols,
fillFloorColor = if dlg.fillWithEmptyFloors:
a.ui.currFloorColor.Natural.some
else: Natural.none,

dlg.overrideCoordOpts,
coordOpts = CoordinateOptions(
origin: CoordinateOrigin(dlg.origin),
rowStyle: CoordinateStyle(dlg.rowStyle),
Expand Down Expand Up @@ -10776,7 +10790,6 @@ proc initApp(configFile: Option[string], mapFile: Option[string],
)
else: appEvents.disableAutoSave()

# TODO init from config
with a.ui.notesListState:
currFilter.noteType = NoteTypeFilter.fullSet
currFilter.orderBy = noType
Expand Down

0 comments on commit 42226ae

Please sign in to comment.