Skip to content

Commit

Permalink
Merge branch 'upstream' into 18bf
Browse files Browse the repository at this point in the history
  • Loading branch information
ollybh committed Jul 6, 2023
2 parents 27f2343 + fcdfd1d commit 1f51095
Show file tree
Hide file tree
Showing 143 changed files with 31,504 additions and 8,832 deletions.
15 changes: 14 additions & 1 deletion .github/ISSUE_TEMPLATE/bug_report.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,18 @@ labels: needs triage
assignees: ''

---
DO NOT PASTE THE GAME JSON! Please use [gist](https://gist.github.com/) instead.

<!--
Please fill out the bug report title with the game name and description
e.g. "[18Chesapeake] Incorrect revenue for route from Baltimore to DC"
-->

**What's your Game ID?**

<!--
DO NOT PASTE THE GAME JSON! Please use [gist](https://gist.github.com/) instead.
If your game is "Multiplayer", provide the link to the game. Copy the link from your browser which will look something like `https://18xx.games/game/31337`
- (optional) Provide a link to the specific action that triggered the bug using the `Game` tab and `History` navigation arrows. Copy the resulting link from your browser which will look something like `https://18xx.games/game/31337?action=42`
Expand All @@ -22,8 +26,11 @@ If your game is "Hotseat", provide a link to your raw game data by using the `To
Paste that data [into a github gist](https://gist.github.com/) and share the resulting link which will look something like `https://gist.github.com/[your_name]/[some_letters]`.
-->

**How to Reproduce the Bug?**

<!--
What steps cause the unexpected behavior?
e.g.
Expand All @@ -33,9 +40,15 @@ e.g.
Please include screenshots (you can drag and drop or upload them into this issue)
-->

**Which Browser / Platform?**

<!--
- Browser Version
- On Chrome, see [chrome://version](chrome://version)
- On Firefox, see [about:support](about:support)
- On Safari, see [these methods](https://www.lifewire.com/check-the-version-number-of-safari-446563)
- Platform (Mobile, Tablet, Desktop)
-->
8 changes: 6 additions & 2 deletions .github/PULL_REQUEST_TEMPLATE.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
Fixes #[PUT_ISSUE_NUMBER_HERE]

> Please minimize the amount of changes to shared `lib/engine` code, if possible
<!--
> If you are implementing a new game, please break up the changes into multiple PRs for ease of review.
Please minimize the amount of changes to shared `lib/engine` code, if possible
If you are implementing a new game, please break up the changes into multiple PRs for ease of review.
-->

### Before clicking "Create"

Expand Down
6 changes: 6 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -52,3 +52,9 @@ prod_deploy : clean
$(CONTAINER_COMPOSE) run rack rake precompile && \
rsync --verbose --checksum public/assets/*.js public/assets/*.js.gz public/assets/version.json deploy@18xx:~/18xx/public/assets/ && \
ssh -l deploy 18xx "source ~/.profile && cd ~/18xx/ && git pull && make prod_rack_up_b_d"

style:
$(CONTAINER_COMPOSE) exec rack rubocop -A

test:
$(CONTAINER_COMPOSE) exec rack rake
13 changes: 8 additions & 5 deletions assets/app/view/create_game.rb
Original file line number Diff line number Diff line change
Expand Up @@ -392,10 +392,14 @@ def submit
return if !selected_game_or_variant && @mode != :json

game_params = params
game_params[:seed] = game_params[:seed].to_i
game_params[:seed] = nil if (game_params[:seed]).zero?

return create_game(game_params) if @mode == :multi
if @mode == :multi
title = selected_game_or_variant.title
game_params[:max_players] = @max_p[title] if game_params[:max_players].to_i <= 0
game_params[:seed] = game_params[:seed].to_i
game_params[:seed] = nil if (game_params[:seed]).zero?
return create_game(game_params)
end

players = game_params
.select { |k, _| k.start_with?('player_') }
Expand Down Expand Up @@ -499,13 +503,12 @@ def update_inputs(title_change: false)
max_players = (val = max_players_elm&.value.to_i).zero? ? nil : val
min_players = (val = min_players_elm&.value.to_i).zero? ? nil : val
end

if max_players
max_players = [max_players, max_p].min
max_players = [max_players, min_p].max
if selected_game_or_variant.respond_to?(:min_players)
min_p = selected_game_or_variant.min_players(@optional_rules, max_players)
end
max_players_elm&.value = max_players
end

if min_players
Expand Down
63 changes: 63 additions & 0 deletions assets/app/view/game/abilities.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,12 @@ class Abilities < Snabberb::Component
include Actionable

needs :show_other_abilities, default: false, store: true
needs :combo_checkboxes, default: {}, store: false
needs :combos_only, default: false

def render
return render_ability_combos(@game.round.current_entity) if @combos_only

companies = @game.companies.select do |company|
company.owner &&
!company.closed? &&
Expand Down Expand Up @@ -56,6 +60,9 @@ def render_companies(companies)
props = {
on: {
click: lambda do
@combo_checkboxes.each { |_, checkbox| Native(checkbox)&.elm&.checked = false }
store(:selected_combos, [], skip: true)

store(:tile_selector, nil, skip: true)
store(:selected_company, @selected_company == company ? nil : company)
end,
Expand All @@ -80,6 +87,7 @@ def render_actions
views << render_sell_company_button if actions.include?('sell_company')
views << render_close_company_button if actions.include?('manual_close_company')
views << render_ability_choice_buttons if actions.include?('choose_ability')
views << render_ability_combos(@selected_company) if actions.include?('lay_tile')
views << h(Exchange) if actions.include?('buy_shares')
views << h(Map, game: @game) if !@game.round.is_a?(Engine::Round::Operating) &&
(actions & %w[lay_tile place_token]).any?
Expand Down Expand Up @@ -158,6 +166,61 @@ def render_ability_choice_buttons
end
h(:div, [*ability_choice_buttons])
end

def render_ability_combos(entity)
return '' unless entity&.company?
return '' unless @game.abilities(entity, :tile_lay)

@selected_combos ||= []

rendered_combos = @game.ability_combo_entities(entity).map do |company|
id = company.sym
elm_id = "#{company.id}-combine-with-#{company.sym}"

checked = @selected_combos.include?(id)

label_props = {
attrs: { for: elm_id },
style: { cursor: 'pointer' },
}
input_props = {
attrs: {
id: elm_id,
type: 'checkbox',
checked: checked,
disabled: checked ? false : !@game.valid_combos?([company, entity, *@selected_combos]),
},
on: {
click: lambda {
if @selected_combos.include?(id)
@selected_combos.delete(id)
else
@selected_combos << id
end

store(:selected_combos, @selected_combos, skip: false)
},
},
}

h(
:div,
{},
[
(@combo_checkboxes[elm_id] = h('input', input_props)),
h(:label, label_props, company.name.to_s),
],
)
end

return '' if rendered_combos.empty?

h(:div, {}, [
h(:br),
h('h4.inline', {}, 'Combine with:'),
*rendered_combos,
])
end
end
end
end
2 changes: 2 additions & 0 deletions assets/app/view/game/actionable.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ def self.included(base)
base.needs :user, store: true, default: nil
base.needs :tile_selector, default: nil, store: true
base.needs :selected_company, default: nil, store: true
base.needs :selected_combos, default: [], store: true
base.needs :selected_corporation, default: nil, store: true
base.needs :app_route, default: nil, store: true
base.needs :round_history, default: nil, store: true
Expand Down Expand Up @@ -155,6 +156,7 @@ def process_action(action)

def clear_ui_state
store(:selected_company, nil, skip: true)
store(:selected_combos, [], skip: true)
store(:selected_corporation, nil, skip: true)
store(:tile_selector, nil, skip: true)
store(:selected_action_id, nil, skip: true)
Expand Down
5 changes: 4 additions & 1 deletion assets/app/view/game/button/buy_share.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,10 @@ def render
show_percentage = @percentages_available > 1 ||
(bundle.percent != bundle.corporation.share_percent && !bundle.presidents_share)
reduced_price = @game.format_currency(bundle.price - @swap_share.price) if @swap_share
modified_price = step.respond_to?(:modify_purchase_price) && step.modify_purchase_price(bundle)
if step.respond_to?(:modify_purchase_price)
modified_price = step.modify_purchase_price(bundle)
modified_price = nil if bundle.price == modified_price
end

text = @prefix.to_s
text += " #{@partial_percent}% of" if @partial_percent
Expand Down
16 changes: 16 additions & 0 deletions assets/app/view/game/buy_sell_shares.rb
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ def render_buy_shares
children.concat(render_treasury_shares)
children.concat(render_market_shares)
children.concat(render_corporate_shares)
children.concat(render_other_player_shares)
children.concat(render_shares_for_others)
children.concat(render_price_protection)
children.concat(render_reduced_price_shares(@ipo_shares, source: @game.ipo_name(@corporation)))
Expand Down Expand Up @@ -133,6 +134,21 @@ def render_corporate_shares
end
end

def render_other_player_shares
@corporation.player_share_holders.keys.reject { |sh| sh == @current_entity }.flat_map do |sh|
shares = sh.shares_of(@corporation).select(&:buyable).group_by(&:percent).values.map(&:first)
shares.sort_by(&:percent).reverse.map do |share|
next unless @step.can_buy?(@current_entity, share.to_bundle)

h(Button::BuyShare,
share: share,
entity: @current_entity,
percentages_available: shares.group_by(&:percent).size,
source: sh.name)
end
end
end

def render_shares_for_others
return [] unless @step.respond_to?(:can_buy_for)

Expand Down
95 changes: 95 additions & 0 deletions assets/app/view/game/buy_token.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
# frozen_string_literal: true

require 'view/game/actionable'

module View
module Game
module Round
class BuyToken < Snabberb::Component
include Actionable
needs :entity
needs :selected_token, default: nil, store: true

def render
step = @game.active_step
max_price = step.max_price(@entity)

children = []

children << h(:h3, 'Select token on map to purchase')

corp_name = '<select token>'
hexid = '<select token>'
corp_name = @selected_token.corporation.name if @selected_token
hexid = @selected_token.city.hex.id if @selected_token

other_owner = nil
if @selected_token && (real_owner(@entity) != real_owner(@selected_token.corporation))
other_owner = real_owner(@selected_token.corporation)
end

children << h(:table, [
h(:tbody, [
h(:tr, [
h(:td, ['Corporation:']),
h(:td, [corp_name]),
]),
h(:tr, [
h(:td, ['Hex:']),
h(:td, [hexid]),
]),
]),
])

price_input = h(:input, style: { marginRight: '1rem' }, props: {
value: 1,
step: 1,
min: 1,
max: max_price,
type: 'number',
size: max_price.to_s.size,
})

button_click = lambda do
city = @selected_token.city
slot = city.tokens.index(@selected_token)
price = Native(price_input)[:elm][:value].to_i
buy_token = lambda do
process_action(Engine::Action::BuyToken.new(
@entity,
city: city,
slot: slot,
price: price,
))
end

if other_owner
check_consent(@entity, other_owner, buy_token)
else
buy_token.call
end
end

button_props = {
attrs: {
disabled: !@selected_token,
type: :button,
},
on: { click: button_click },
}
buy_button = h(:button, button_props, 'Buy Token')

children << h('div.center', ['Price: ', price_input, buy_button])

children << h(:h3, 'WARNING! token owned by a different player. Ask for permission to purchase.') if other_owner

h(:div, children)
end

def real_owner(corp)
@step.respond_to?(:real_owner) ? @step.real_owner(corp) : corp.owner
end
end
end
end
end
Loading

0 comments on commit 1f51095

Please sign in to comment.