From a770dd88e6c55ac7fd67c243ad30f04425e3e175 Mon Sep 17 00:00:00 2001 From: Holden Rohrer Date: Sun, 8 Aug 2021 23:59:29 -0400 Subject: featureful saving and loading --- source/app.d | 21 ++++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) (limited to 'source/app.d') diff --git a/source/app.d b/source/app.d index 943b9d0..52074b1 100644 --- a/source/app.d +++ b/source/app.d @@ -75,10 +75,13 @@ void main() try { auto file = File(filename, "wb"); - + file.writefln!"%s %s"(disp.y, disp.x); + file.writefln!"%d"(rocks); + overlay.save(file); } - catch (ErrnoException e) + catch (Exception e) { + // TODO: log the error in a user-visible way } disp.print(); break; @@ -86,10 +89,22 @@ void main() auto filename = stdscr.readquery("Load:"); try { + import std.algorithm.iteration : splitter, map; + import std.conv : to; + import std.bigint; + auto file = File(filename); + auto coord = file.readln.splitter().map!(to!BigInt); + disp.y = coord.front; + coord.popFront; + disp.x = coord.front; + file.readf!"%d\n"(rocks); + disp.status = format("%d", rocks); + overlay.load(file); } - catch (ErrnoException e) + catch (Exception e) { + printw("exception!"); } disp.print(); break; -- cgit