Skip to content

Commit

Permalink
refactor: added pragmas to updateMapInfoCommand procedure
Browse files Browse the repository at this point in the history
FossilOrigin-Name: 65cf1055f5660140927e067bf0b0905d3e68f6cf3f67893ca108004bb7c1e2b1
  • Loading branch information
thindil committed Jan 20, 2024
1 parent eba4846 commit 12c2689
Showing 1 changed file with 20 additions and 10 deletions.
30 changes: 20 additions & 10 deletions nim/src/ui/mapsui.nim
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import coreui, dialogs, mapsuicommands, utilsui2, themes

var
centerX*, centerY*: Positive ## Coordinates of the center point on the map
startX, startY: int ## Coordinates of the top left point on the map
startX, startY: int ## Coordinates of the top left point on the map
generalAccelerators*: array[4, string] = ["Alt-a", "Alt-b", "Alt-c", "Alt-d"]
## The list of keyboard shortcuts used in some places
mapView = ".gameframe.paned.mapframe.map"
Expand Down Expand Up @@ -785,19 +785,29 @@ proc updateMapInfo*(x: Positive = playerShip.skyX;
var mapX, mapY = 0

proc updateMapInfoCommand(clientData: cint; interp: PInterp; argc: cint;
argv: openArray[cstring]): TclResults =
argv: openArray[cstring]): TclResults {.sideEffect, raises: [], tags: [].} =
let
mapView = mainPaned & ".mapframe.map"
mapIndex = tclEval2(script = mapView & " index @" & $argv[1] & "," & $argv[2])
if startY + (mapIndex[0 .. mapIndex.find(".") - 1]).parseInt - 1 < 1:
return tclOk
mapY = startY + (mapIndex[0 .. mapIndex.find(".") - 1]).parseInt - 1
if mapY > 1_024:
return tclOk
if startX + (mapIndex[mapIndex.find(".") + 1 .. ^1]).parseInt < 1:
try:
if startY + (mapIndex[0 .. mapIndex.find(".") - 1]).parseInt - 1 < 1:
return tclOk
mapY = startY + (mapIndex[0 .. mapIndex.find(".") - 1]).parseInt - 1
if mapY > 1_024:
return tclOk
except:
tclEval(script = "bgerror {Can't set map Y coordinate. Reason: " &
getCurrentExceptionMsg() & "}")
return tclOk
mapX = startX + (mapIndex[mapIndex.find(".") + 1 .. ^1]).parseInt
if mapX > 1_024:
try:
if startX + (mapIndex[mapIndex.find(".") + 1 .. ^1]).parseInt < 1:
return tclOk
mapX = startX + (mapIndex[mapIndex.find(".") + 1 .. ^1]).parseInt
if mapX > 1_024:
return tclOk
except:
tclEval(script = "bgerror {Can't set map X coordinate. Reason: " &
getCurrentExceptionMsg() & "}")
return tclOk
updateMapInfo(x = mapX, y = mapY)
return tclOk
Expand Down

0 comments on commit 12c2689

Please sign in to comment.