Skip to content

Commit 721b984

Browse files
committed
[Engine V2] create a game with V2, show on game card, URL param
1 parent 5fcd64e commit 721b984

File tree

5 files changed

+49
-2
lines changed

5 files changed

+49
-2
lines changed

assets/app/lib/whats_this.rb

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,14 @@ def auto_route_whats_this
1010
end
1111
end
1212

13+
module EngineV2
14+
def engine_v2_whats_this
15+
h(Component,
16+
tooltip: 'Various work-in-progress changes to make the game Engine more efficient.',
17+
url: 'https://github.com/tobymao/18xx/wiki/Engine-V2')
18+
end
19+
end
20+
1321
class Component < Snabberb::Component
1422
needs :tooltip
1523
needs :url

assets/app/view/create_game.rb

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ class CreateGame < Form
1111
include GameManager
1212
include Lib::Settings
1313
include Lib::WhatsThis::AutoRoute
14+
include Lib::WhatsThis::EngineV2
1415

1516
needs :mode, default: :multi, store: true
1617
needs :flash_opts, default: {}, store: true
@@ -99,6 +100,7 @@ def render_content
99100
end
100101

101102
inputs << render_random_seed
103+
inputs << render_engine_v2 if should_render_engine_v2?
102104
inputs << render_optional if should_render_optional?
103105
inputs << render_game_info
104106
end
@@ -455,6 +457,7 @@ def submit
455457
title: game_params[:title],
456458
}
457459
game_data[:settings][:seed] = game_params[:seed] if game_params[:seed]
460+
game_data[:settings][:use_engine_v2] = game_params[:use_engine_v2] if game_params[:use_engine_v2]
458461

459462
when :json
460463
begin
@@ -711,5 +714,22 @@ def update_player_range(meta)
711714
title = meta.title
712715
@min_p[title], @max_p[title] = meta::PLAYER_RANGE
713716
end
717+
718+
def render_engine_v2
719+
render_input(
720+
'Use Engine V2 (experimental)',
721+
id: 'use_engine_v2',
722+
type: :checkbox,
723+
container_style: { paddingLeft: '0.5rem' },
724+
attrs: { checked: false },
725+
siblings: [engine_v2_whats_this],
726+
)
727+
end
728+
729+
def should_render_engine_v2?
730+
# for now, only available locally for any contributors
731+
# https://github.com/tobymao/18xx/issues/12193
732+
!@production
733+
end
714734
end
715735
end

assets/app/view/game_card.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ class GameCard < Snabberb::Component
1313
include GameManager
1414
include Lib::Settings
1515
include Lib::WhatsThis::AutoRoute
16+
include Lib::WhatsThis::EngineV2
1617
include Lib::ProfileLink
1718

1819
needs :user
@@ -242,6 +243,7 @@ def render_body
242243
if @gdata['status'] == 'new'
243244
children << h(:div, [h(:i, 'Invite only game')]) if @gdata.dig('settings', 'unlisted')
244245
children << h(:div, [h(:i, ['Auto Routing', auto_route_whats_this])]) if @gdata.dig('settings', 'auto_routing')
246+
children << h(:div, [h(:i, ['Engine V2', engine_v2_whats_this])]) if @gdata.dig('settings', 'use_engine_v2')
245247
end
246248
children << h(:div, [h(:strong, 'Description: '), @gdata['description']]) unless @gdata['description'].empty?
247249

assets/app/view/game_page.rb

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -80,9 +80,15 @@ def load_game
8080
LOGGER.debug do
8181
@_logger ||= {}
8282
@_logger[:process] = Time.now
83-
"Processing game actions, strict: #{strict}..."
83+
"Processing game actions, strict: #{strict}, use_engine_v2: #{use_engine_v2}..."
8484
end
85-
@game = Engine::Game.load(@game_data, at_action: cursor, user: @user&.dig('id'), strict: strict)
85+
@game = Engine::Game.load(
86+
@game_data,
87+
at_action: cursor,
88+
user: @user&.dig('id'),
89+
strict: strict,
90+
use_engine_v2: use_engine_v2
91+
)
8692
LOGGER.debug do
8793
"Done processing game actions: #{Time.now - @_logger[:process]} seconds"
8894
end
@@ -516,5 +522,15 @@ def strict
516522
@strict
517523
end
518524
end
525+
526+
# https://github.com/tobymao/18xx/issues/12193
527+
def use_engine_v2
528+
if (param = Lib::Params['v2'])
529+
return false if param.start_with?('f')
530+
return true if param.start_with?('t')
531+
end
532+
533+
@game_data.dig('settings', 'use_engine_v2')
534+
end
519535
end
520536
end

routes/game.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -207,6 +207,7 @@ class Api
207207
unlisted: r.params['unlisted'],
208208
optional_rules: r.params['optional_rules'],
209209
auto_routing: r.params['auto_routing'],
210+
use_engine_v2: r.params['use_engine_v2'],
210211
is_async: r.params['async'],
211212
},
212213
title: title,

0 commit comments

Comments
 (0)