8 // Originally, this was pragma(inline, true) pure final void pline(T...)(string s, T args)
9 // But the opportunity was too good to pass up
11 //pragma(inline, true) pure const static inout shared ref nothrow override @property @nogc @safe public final void
12 // in all its glory. But after about a year, I found out that this didn't actually work, which brings you to the state you see today :<<
13 pragma(inline
, true) inout ref @property @trusted public final void pline(T
...)(T args
) {
15 import std
.string
: format
;
16 if (args
.length
== 1) {
17 this.pline(to
!string(args
[0]));
19 this.pline(format(args
));
29 private struct startendspec
{ int startx
, starty
, endx
, endy
, cursx
, cursy
; }
31 // Find the x-y coordinates to start drawing from in the map so the camera is centred on the player
32 // FUN FACT while coding this, I had no idea what it did or how
33 // it worked. I still have no idea how it works. But it does!
34 private @nogc @safe final startendspec
focuscamera(int width
, int height
, int x
, int y
) {
35 import std
.math
: round
;
37 int startx
, starty
, endx
, endy
;
38 int offsetx
, offsety
; // offsets are distance from top edge, left edge to centre
42 offsetx
= cast(int)round(width
/ 2.0);
43 offsety
= cast(int)round(height
/ 2.0);
45 // Don't keep the map centred when we're near an edge,
46 // actually move the @ closer to the edge
62 endx
= startx
+ width
;
63 endy
= starty
+ height
;
69 cursx
= width
- (map_x
- x
) - 1;
74 cursy
= height
- (map_y
- y
) - 1;
87 class Default_chargfx(G0type
: CharGfx0
): Graphics1
{
91 this(Game g
, string title
="") {
93 this.graphics0
= new G0type();
95 graphics0
.settitle(title
);
97 void close() { graphics0
.close(); }
100 auto lens
= focuscamera(maxx(), maxy(), game
.u
.x
, game
.u
.y
);
101 int tmpx
= 0, tmpy
= 0;
105 foreach (uint i
; lens
.starty
..lens
.endy
) {
107 foreach (uint j
; lens
.startx
..lens
.endx
) {
109 if ((mon
= game
.mon_at(i
, j
)) is null) {
112 if (!game
.map
[i
][j
].visible
)
115 /* x and y both start at 1, so we want to get them to 0
116 * in order to align them with the edges of the terminal.
117 * But it's okay to "add" 1 to y, because we want to leave
118 * an extra line up to for messages.
121 graphics0
.mvaddch(mon
.glyph
, tmpy
, tmpx
-1, mon
.fgcolour
, mon
.bgcolour
, bold
, italic
, underline
, reverse
);
127 int tmpx
= 0, tmpy
= 0;
129 auto lens
= focuscamera(maxx(), maxy(), game
.u
.x
, game
.u
.y
);
131 foreach (uint i
; lens
.starty
..lens
.endy
) {
133 foreach (uint j
; lens
.startx
..lens
.endx
) {
136 /* x and y both start at 1, so we want to get them to 0
137 * in order to align them with the edges of the terminal.
138 * But it's okay to "add" 1 to y, because we want to leave
139 * an extra line up to for messages.
141 // import std.conv: to;
142 // curses.mvprint(tmpy, tmpx-1, to!string(to!string(game.map[i][j].dijkstra)[0]));
143 if (game
.map
[i
][j
].blocks_light
) {
144 with (game
.map
[i
][j
].attrs
)
145 graphics0
.mvaddch(game
.map
[i
][j
].glyph
, tmpy
, tmpx
-1, game
.map
[i
][j
].visible ? game
.map
[i
][j
].fgcolour
.lighten(20) : game
.map
[i
][j
].fgcolour
.darken(20), game
.map
[i
][j
].bgcolour
, bold
, italic
, underline
, reverse
);
147 with (game
.map
[i
][j
].attrs
)
148 graphics0
.mvaddch(game
.map
[i
][j
].glyph
, tmpy
, tmpx
-1, game
.map
[i
][j
].visible ? game
.map
[i
][j
].fgcolour
.lighten(20) : game
.map
[i
][j
].fgcolour
.darken(20), game
.map
[i
][j
].bgcolour
, bold
, italic
, underline
, reverse
); //game.map[i][j].glyph);
155 void pline(string msg
) {
156 if (msg
.length
== 0) {
160 // TODO chop stuff up based on words, not character counts
161 pure string
[] chopupmsg(string msgtext
, int x
) {
164 immutable uint maxlen
= x
- cast(int)" --More--".length
;
165 while (msgtext
.length
> x
) {
166 buf
~= (msgtext
[tmp
..tmp
+maxlen
] ~ " --More--");
168 msgtext
= msgtext
[tmp
..$];
174 graphics0
.printext(fillstr(maxx()), 0, 0);
177 if (msg
.length
<= maxx()) {
179 graphics0
.printext(msg
, 0, 0);
182 string
[] buffer
= chopupmsg(msg
, /*cast(int)*/maxx());
184 loop: foreach (lineindex
; 0..buffer
.length
) {
185 graphics0
.printext(buffer
[lineindex
], 0, 0);
188 c
= graphics0
.getch();
191 graphics0
.printext(buffer
[$-1], 0, 0);
194 if (lineindex
< buffer
.length
-1) {
195 while ((c
!= '\n') && (c
!= ' ')) {
198 graphics0
.printext(buffer
[$-1], 0, 0);
209 int maxx() { return graphics0
.maxx(); }
210 int maxy() { return graphics0
.maxy(); }
217 char getch() { return graphics0
.getch
; }