Skip to content

Commit c543471

Browse files
committed
Improve mugs-tool new-ui-type handling of base class file
1 parent 03c91c3 commit c543471

File tree

1 file changed

+31
-6
lines changed

1 file changed

+31
-6
lines changed

lib/MUGS/App/DevTool.rakumod

Lines changed: 31 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -85,11 +85,12 @@ multi MAIN('new-ui-type', Str:D $ui-type) is export {
8585
.put, .IO.mkdir for « docs lib/MUGS/App $lib-dir
8686
"$lib-dir/Game" "$lib-dir/Genre" »;
8787

88-
$tool.additional-step('Adding MUGS-specific files');
88+
$tool.additional-step('Adding/updating MUGS-specific files');
8989

9090
my $MUGS-version = $?DISTRIBUTION.meta<version>;
9191
my $bin-file = 'bin/mugs-' ~ $ui-type.lc.subst(/^ 'web' /, 'web-');
9292
my $app-file = "lib/MUGS/App/{$ui-type}.rakumod";
93+
my $class-file = "lib/MUGS/UI/{$ui-type}.rakumod";
9394
my $test-file = "t/00-use.rakutest";
9495

9596
put $bin-file;
@@ -115,9 +116,10 @@ multi MAIN('new-ui-type', Str:D $ui-type) is export {
115116
%PROCESS::SUB-MAIN-OPTS = :named-anywhere;
116117
117118
118-
#| \qq[$ui-type] App
119+
#| \qq[$ui-type] app
119120
class \qq[$app] is MUGS::App::LocalUI {
120-
# XXXX: Add attributes for app-wide state here
121+
has MUGS::UI::Pop::Game $.current-game;
122+
# XXXX: Add additional app-wide state attributes here
121123
122124
method ui-type() { '\qq[$ui-type]' }
123125
@@ -142,9 +144,15 @@ multi MAIN('new-ui-type', Str:D $ui-type) is export {
142144
await $.session.authenticate(:$username, :$password);
143145
}
144146
147+
#| Create and initialize a new game UI for a given game type and client
148+
method launch-game-ui(Str:D :$game-type, MUGS::Client::Game:D :$client, *%ui-opts) {
149+
$!current-game = callsame;
150+
}
151+
145152
#| Start actively playing current game UI
146153
method play-current-game() {
147-
# XXXX: Enter \qq[$ui-type] main loop here
154+
# XXXX: Enter \qq[$ui-type] main loop here, or (by default) hand to game UI
155+
$!current-game.main-loop;
148156
}
149157
}
150158
@@ -172,6 +180,23 @@ multi MAIN('new-ui-type', Str:D $ui-type) is export {
172180
}
173181
APP_MODULE
174182

183+
put $class-file;
184+
my $skip-first-line = $class-file.IO.lines(:!chomp)[1..*].join;
185+
spurt($class-file, q:to/BASE_CLASS/ ~ $skip-first-line);
186+
# ABSTRACT: \qq[$ui-type] UI for MUGS, including App and game UIs
187+
188+
unit module \qq[$class]:ver<0.0.1>;
189+
190+
use MUGS::UI;
191+
192+
193+
# Base class for \qq[$ui-type] game UIs
194+
class Game is MUGS::UI::Game {
195+
method ui-type() { '\qq[$ui-type]' }
196+
}
197+
198+
BASE_CLASS
199+
175200
put $test-file;
176201
spurt($test-file, q:to/USE_TEST/);
177202
use v6.d;
@@ -197,9 +222,9 @@ multi MAIN('new-ui-type', Str:D $ui-type) is export {
197222
$tool.run-or-exit($_, :force) for
198223
« chmod +x $bin-file »,
199224
« mi6 build »,
200-
« git add $bin-file $app-file $test-file META6.json »,
225+
« git add $bin-file $app-file $class-file $test-file META6.json »,
201226
« git rm t/01-basic.rakutest », # Redundant with 00-use
202-
« git commit -m "Add MUGS-specific files" »,
227+
« git commit -m "Add MUGS-specific files and tweaks" »,
203228
« git status »,
204229
;
205230

0 commit comments

Comments
 (0)