Skip to content

Commit

Permalink
refactor: redesigned minutesToDate procedure
Browse files Browse the repository at this point in the history
FossilOrigin-Name: 71cb1141a1788885e7a39adb91a98f7ec2bb928fbc5b4a065875cd4efad56f0b
  • Loading branch information
thindil committed Jan 18, 2024
1 parent 8e0c89f commit 10bccec
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 10 deletions.
22 changes: 13 additions & 9 deletions nim/src/ui/utilsui.nim
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ import ../[bases, config, crew2, crewinventory, events2, game, game2,
maps, messages, missions2, shipscargo, shipscrew, tk, types]
import combatui, coreui, dialogs, mapsui, shipsuicrew, shipsuimodules

proc minutesToDate*(minutes: cint; infoText: var cstring) {.exportc, gcsafe,
sideEffect, raises: [], tags: [].} =
proc minutesToDate*(minutes: int; infoText: var string) {.sideEffect, raises: [],
tags: [].} =
## Convert the game minutes to the game time in days, hours, etc
##
## * minutes - the amount of minutes to convert
Expand Down Expand Up @@ -67,18 +67,16 @@ proc minutesToDate*(minutes: cint; infoText: var cstring) {.exportc, gcsafe,
minutesDiff = 0
if travelTime.year == 4_000_000:
break
var timeText: string = $infoText
if travelTime.year > 0:
timeText = timeText & " " & $travelTime.year & "y"
infoText = infoText & " " & $travelTime.year & "y"
if travelTime.month > 0:
timeText = timeText & " " & $travelTime.month & "m"
infoText = infoText & " " & $travelTime.month & "m"
if travelTime.day > 0:
timeText = timeText & " " & $travelTime.day & "d"
infoText = infoText & " " & $travelTime.day & "d"
if travelTime.hour > 0:
timeText = timeText & " " & $travelTime.hour & "h"
infoText = infoText & " " & $travelTime.hour & "h"
if travelTime.minutes > 0:
timeText = timeText & " " & $travelTime.minutes & "mins"
infoText = timeText.cstring
infoText = infoText & " " & $travelTime.minutes & "mins"

proc resizeCanvasCommand(clientData: cint; interp: PInterp; argc: cint;
argv: openArray[cstring]): TclResults {.sideEffect, raises: [], tags: [].} =
Expand Down Expand Up @@ -331,3 +329,9 @@ proc addAdaUtilsCommands() {.raises: [], tags: [], exportc.} =
proc deleteAdaWidgets*(startIndex, endIndex: cint; frame: cstring) {.exportc,
gcsafe, sideEffect, raises: [], tags: [].} =
deleteWidgets(startIndex, endIndex, $frame)

proc minutesAdaToDate*(minutes: cint; infoText: var cstring) {.exportc, gcsafe,
sideEffect, raises: [], tags: [].} =
var nimText = $infoText
minutesToDate(minutes, nimText)
infoText = nimText.cstring
2 changes: 1 addition & 1 deletion src/ui/utils-ui.adb
Original file line number Diff line number Diff line change
Expand Up @@ -449,7 +449,7 @@ package body Utils.UI is
procedure Min_To_Date(Mins: Natural; Info: in out chars_ptr) with
Import => True,
Convention => C,
External_Name => "minutesToDate";
External_Name => "minutesAdaToDate";
New_Text: chars_ptr := New_String(Str => To_String(Source => Info_Text));
begin
Min_To_Date(Mins => Minutes, Info => New_Text);
Expand Down

0 comments on commit 10bccec

Please sign in to comment.