Skip to content

Commit

Permalink
Merge branch 'upstream'
Browse files Browse the repository at this point in the history
  • Loading branch information
ollybh committed Sep 11, 2023
2 parents ecc38e7 + 97ce9af commit 4b73946
Show file tree
Hide file tree
Showing 144 changed files with 10,970 additions and 3,231 deletions.
17 changes: 11 additions & 6 deletions assets/app/view/game/bid.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,18 @@ module Round
class Bid < Snabberb::Component
include Actionable
needs :entity
needs :corporation
needs :biddable

def render
step = @game.round.step_for(@entity, 'bid')

children = []
children << h(:div, [step.bid_description]) if step.respond_to?(:bid_description) && step.bid_description

min_increment = step.min_increment

min_bid = step.min_bid(@corporation)
max_bid = step.max_bid(@entity, @corporation)
min_bid = step.min_bid(@biddable)
max_bid = step.max_bid(@entity, @biddable)
price_input = h(:input, style: { marginRight: '1rem' }, props: {
value: min_bid,
step: min_increment,
Expand All @@ -28,15 +32,16 @@ def render
place_bid = lambda do
process_action(Engine::Action::Bid.new(
@entity,
corporation: @corporation.corporation? ? @corporation : nil,
company: @corporation.company? ? @corporation : nil,
corporation: @biddable.corporation? ? @biddable : nil,
company: @biddable.company? ? @biddable : nil,
price: Native(price_input)[:elm][:value].to_i,
))
end

bid_button = h(:button, { on: { click: place_bid } }, 'Place Bid')
children << h(:div, [price_input, bid_button])

h('div.center', [price_input, bid_button])
h('div.center', children)
end
end
end
Expand Down
12 changes: 10 additions & 2 deletions assets/app/view/game/buy_trains.rb
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,15 @@ def render

if (@step.can_buy_train?(@corporation, @active_shell) && @step.room?(@corporation, @active_shell)) ||
@must_buy_train
children << h(:div, "#{@corporation.name} must buy an available train") if @must_buy_train
if @must_buy_train
children << if @step.must_issue_before_ebuy?(@corporation)
h(:div, "#{@corporation.name} must buy a train from another corporation, "\
'or issue shares and then buy an available train ')
else
h(:div, "#{@corporation.name} must buy an available train")
end
end

if @should_buy_train == :liquidation
children << h(:div, "#{@corporation.name} must buy a train or it will be liquidated")
end
Expand Down Expand Up @@ -576,7 +584,7 @@ def remaining_trains
},
}

rows = @depot.upcoming.group_by(&:name).flat_map do |_, trains|
rows = @depot.upcoming.reject(&:reserved).group_by(&:name).flat_map do |_, trains|
[h(:div, @game.info_train_name(trains.first)),
h(:div, @game.info_train_price(trains.first)),
h(:div, trains.size)]
Expand Down
20 changes: 9 additions & 11 deletions assets/app/view/game/choose.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,15 @@ class Choose < Snabberb::Component
needs :entity, default: nil

def render
choices = if @game.round.active_step.respond_to?(:entity_choices)
@game.round.active_step.entity_choices(@entity)
step = @game.round.active_step
choices = if step.respond_to?(:entity_choices)
step.entity_choices(@entity)
else
@game.round.active_step.choices
step.choices
end

choice_is_amount = if @game.round.active_step.respond_to?(:choice_is_amount?)
@game.round.active_step.choice_is_amount?
choice_is_amount = if step.respond_to?(:choice_is_amount?)
step.choice_is_amount?
else
false
end
Expand Down Expand Up @@ -50,14 +51,11 @@ def render
h('button', props, label)
end

div_class = choice_buttons.size < 5 ? '.inline' : ''
children = []
children << h("div#{div_class}",
{ style: { marginTop: '0.5rem' } },
"#{@game.round.active_step.choice_name}: ")
div_class = choice_buttons.size < 5 ? '.inline' : ''
children << h("div#{div_class}", { style: { marginTop: '0.5rem' } }, "#{step.choice_name}: ") if step.choice_name
children << h(:div, choice_buttons)
if @game.round.active_step.respond_to?(:choice_explanation) &&
(explanation = @game.round.active_step.choice_explanation)
if step.respond_to?(:choice_explanation) && (explanation = step.choice_explanation)
paragraphs = explanation.map { |text_block| h(:p, text_block) }
children << h(:div, { style: { marginTop: '0.5rem' } }, paragraphs)
end
Expand Down
4 changes: 3 additions & 1 deletion assets/app/view/game/part/town_dot.rb
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,9 @@ def render_part
children << h(:circle, attrs: dot_attrs)
children << render_boom if @town.boom

children << render_revenue if @show_revenue
if @show_revenue && (rendered = render_revenue)
children << rendered
end
children << h(HitBox, click: -> { touch_node(@town) }, transform: translate) unless @town.solo?
h(:g, { key: "#{@town.id}-d" }, children)
end
Expand Down
2 changes: 1 addition & 1 deletion assets/app/view/game/round/merger.rb
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ def render
if auctioning_corporation && !actions.include?('merge')
inner = []
inner << h(Corporation, corporation: auctioning_corporation || corporation_to_merge_into, selectable: false)
inner << h(Bid, entity: entity, corporation: auctioning_corporation) if actions.include?('bid')
inner << h(Bid, entity: entity, biddable: auctioning_corporation) if actions.include?('bid')
children << h(:div, props, inner)

if @step.respond_to?(:show_bidding_corporation?) && @step.show_bidding_corporation?
Expand Down
17 changes: 13 additions & 4 deletions assets/app/view/game/round/stock.rb
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ def render
end

children.concat(render_buttons)
children << render_bid if @current_actions.include?('bid')
children << h(SpecialBuy) if @current_actions.include?('special_buy')
children.concat(render_failed_merge) if @current_actions.include?('failed_merge')
children.concat(render_bank_companies) if @bank_first
Expand Down Expand Up @@ -203,7 +204,7 @@ def render_pre_ipo(corporation)
when :par
children << h(Par, corporation: corporation) if @current_actions.include?('par')
when :bid
children << h(Bid, entity: @current_entity, corporation: corporation) if @current_actions.include?('bid')
children << h(Bid, entity: @current_entity, biddable: corporation) if @current_actions.include?('bid')
when :form
children << h(FormCorporation, corporation: corporation) if @current_actions.include?('par')
when String
Expand Down Expand Up @@ -330,7 +331,7 @@ def render_bank_companies
if @selected_company == company
inputs = []
inputs.concat(render_buy_input(company)) if @current_actions.include?('buy_company')
inputs.concat(render_bid_input(company)) if @current_actions.include?('bid')
inputs.concat(render_company_bid_input(company)) if @current_actions.include?('bid')
children << h('div.margined_bottom', { style: { width: '20rem' } }, inputs)
end
h(:div, props, children)
Expand Down Expand Up @@ -384,10 +385,10 @@ def render_buy_input_interval(company)
])]
end

def render_bid_input(company)
def render_company_bid_input(company)
return [] if !@step.respond_to?(:can_bid_company?) || !@step.can_bid_company?(@current_entity, company)

[h(Bid, entity: @current_entity, corporation: company)]
[h(Bid, entity: @current_entity, biddable: company)]
end

def render_bank
Expand Down Expand Up @@ -423,6 +424,14 @@ def render_payoff_loan
end
[h(:button, { on: { click: payoff_loan } }, "Payoff Loan (#{@game.format_currency(@game.loan_amount)})")]
end

def render_bid
children = []
if @step.respond_to?(:can_bid?) && @step.can_bid?(@current_entity)
children << h(Bid, entity: @current_entity, biddable: @step.bid_entity)
end
h(:div, children)
end
end
end
end
Expand Down
25 changes: 14 additions & 11 deletions assets/app/view/game/scrap_trains.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,21 +10,21 @@ class ScrapTrains < Snabberb::Component

def render
@corporation ||= @game.round.active_step.current_entity
step = @game.round.step_for(@corporation, 'scrap_train')
@step = @game.round.step_for(@corporation, 'scrap_train')

scrappable_trains = step.scrappable_trains(@corporation)
scrappable_trains = @step.scrappable_trains(@corporation)
return nil if scrappable_trains.empty?

if step.respond_to?(:scrap_trains_button_only?) && step.scrap_trains_button_only?
if @step.respond_to?(:scrap_trains_button_only?) && @step.scrap_trains_button_only?
render_buttons(scrappable_trains)
else
render_section(scrappable_trains)
end
end

def render_buttons(scrappable_trains)
h(:div, generate_scrap_train_actions(scrappable_trains) do |scrap, train, step|
h(:button, { on: { click: scrap } }, step.scrap_info(train))
h(:div, generate_scrap_train_actions(scrappable_trains) do |scrap, train|
h(:button, { on: { click: scrap } }, @step.scrap_info(train))
end)
end

Expand All @@ -38,29 +38,32 @@ def render_section(scrappable_trains)
},
}
h(:div,
[h(:h3, 'Trains to Scrap'),
[h(:h3, scrap_trains_header_text),
h(:div, div_props, scrap_trains(scrappable_trains))])
end

def scrap_trains_header_text
@step.respond_to?(:scrap_header_text) ? @step.scrap_header_text : 'Trains to Scrap'
end

def scrap_trains(scrappable_trains)
generate_scrap_train_actions(scrappable_trains) do |scrap, train, step|
generate_scrap_train_actions(scrappable_trains) do |scrap, train|
[h(:div, train.name),
h('div.nowrap', train.owner.name),
h('div.right', step.scrap_info(train)),
h('button.no_margin', { on: { click: scrap } }, step.scrap_button_text(train))]
h('div.right', @step.scrap_info(train)),
h('button.no_margin', { on: { click: scrap } }, @step.scrap_button_text(train))]
end
end

def generate_scrap_train_actions(scrappable_trains)
step = @game.round.step_for(@corporation, 'scrap_train')
scrappable_trains.flat_map do |train|
scrap = lambda do
process_action(Engine::Action::ScrapTrain.new(
@corporation,
train: train,
))
end
yield(scrap, train, step)
yield(scrap, train)
end
end
end
Expand Down
10 changes: 10 additions & 0 deletions assets/app/view/game/spreadsheet.rb
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ def render_player_table
h(:thead),
h('tbody#player_details', [
render_player_cash,
render_player_loans,
render_player_value,
render_player_liquidity,
render_player_shares,
Expand Down Expand Up @@ -649,6 +650,15 @@ def render_player_cert_count(player, cert_limit, props)
h('td.padded_number', num_certs > cert_limit ? props : '', num_certs)
end

def render_player_loans
return '' unless @game.respond_to?(:player_loans)

h(:tr, tr_default_props, [
h('th.left', 'Loans'),
*@game.players.map { |p| h('td.padded_number', @game.player_loans(p)) },
])
end

def tr_default_props
{
style: {
Expand Down
2 changes: 1 addition & 1 deletion assets/app/view/game/train_schedule.rb
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ def render
trs = if @game.depot.upcoming.empty?
'No Upcoming Trains'
else
@game.depot.upcoming.group_by(&:name).map do |name, trains|
@game.depot.upcoming.reject(&:reserved).group_by(&:name).map do |name, trains|
events = []
events << h('div.left', "rusts #{rust_schedule[name].join(', ')}") if rust_schedule[name]
events << h('div.left', "obsoletes #{obsolete_schedule[name].join(', ')}") if obsolete_schedule[name]
Expand Down
1 change: 1 addition & 0 deletions assets/app/view/game_page.rb
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,7 @@ def render

if n_id == o_id + 1
game_data['actions'] << data
store(:selected_company, nil, skip: true)
store(:game_data, game_data, skip: true)
store(:game, game.process_action(data))
else
Expand Down
3 changes: 2 additions & 1 deletion assets/app/view/welcome.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ def render

def render_notification
message = <<~MESSAGE
<p><a href='https://boardgamegeek.com/thread/3131296/1822africa-design-diary'>1822Africa</a> is now in alpha.</p>
<p>1840 is now (finally) in production.</p>
<p>1868 Wyoming is now in alpha.</p>
<p>Learn how to get <a href='https://github.com/tobymao/18xx/wiki/Notifications'>notifications</a> by email, Slack, Discord, and Telegram.</p>
<p>Please submit problem reports and make suggestions for improvements on
<a href='https://github.com/tobymao/18xx/issues'>GitHub</a>. Join the
Expand Down
23 changes: 7 additions & 16 deletions lib/engine/game/base.rb
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,7 @@ class Base
# operate -- after operation
# p_any_operate -- pres any time, share holders after operation
# any_time -- at any time
# round -- after the stock round the share was purchased in
SELL_AFTER = :first

# down_share -- down one row per share
Expand Down Expand Up @@ -1057,8 +1058,9 @@ def check_sale_timing(entity, bundle)
when :p_any_operate
corporation.operated? || corporation.president?(entity)
when :round
@round.stock? &&
corporation.share_holders[entity] - @round.players_bought[entity][corporation] >= bundle.percent
(@round.stock? &&
corporation.share_holders[entity] - @round.players_bought[entity][corporation] >= bundle.percent) ||
@round.operating?
when :any_time
true
else
Expand Down Expand Up @@ -1202,9 +1204,8 @@ def log_share_price(entity, from, steps = nil, log_steps: false)
return unless from != to

jumps = ''
if steps
steps = share_jumps(steps)
jumps = " (#{steps} step#{steps == 1 ? '' : 's'})" if (steps > 1) || log_steps
if steps && ((steps > 1) || log_steps)
jumps = " (#{steps} step#{steps == 1 ? '' : 's'})"
end

r1, c1 = from.coordinates
Expand All @@ -1220,16 +1221,6 @@ def log_share_price(entity, from, steps = nil, log_steps: false)
"to #{format_currency(to_price)}#{jumps}"
end

def share_jumps(steps)
return steps unless @stock_market.zigzag

if steps > 1
steps / 2
else
steps
end
end

# A hook to allow a game to request a consent check for a share exchange
# or purchase. If consent is needed then this method should return the
# player that needs to consent to this action. Returning nil or false
Expand Down Expand Up @@ -2247,7 +2238,7 @@ def init_bank
cash = self.class::BANK_CASH
cash = cash[players.size] if cash.is_a?(Hash)

Bank.new(cash, log: @log)
Bank.new(cash, log: @log, check: game_end_check_values.include?(:bank))
end

def init_cert_limit
Expand Down
Loading

0 comments on commit 4b73946

Please sign in to comment.