Class: Sc2::Cli
- Inherits:
-
Thor
- Object
- Thor
- Sc2::Cli
- Defined in:
- lib/sc2ai/cli/cli.rb,
lib/sc2ai/cli/new.rb,
lib/sc2ai/cli/ladderzip.rb,
lib/sc2ai/cli/versus_bot.rb
Overview
Command line utilities
Defined Under Namespace
Classes: Ladderzip, New, VersusBot
Class Method Summary collapse
Instance Method Summary collapse
-
#download_ladder_version ⇒ Object
downloads and install SC2 “ladder” as pinned in versions.json.
- #ladderconfig ⇒ Object
- #laddermatch ⇒ Object
- #setup410 ⇒ Object
Class Method Details
.exit_on_failure? ⇒ Boolean
13 14 15 |
# File 'lib/sc2ai/cli/cli.rb', line 13 def exit_on_failure? true end |
Instance Method Details
#download_ladder_version ⇒ Object
downloads and install SC2 “ladder” as pinned in versions.json
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 |
# File 'lib/sc2ai/cli/cli.rb', line 29 def download_ladder_version require "sc2ai" Async do Sc2.logger.level = :fatal say " " say "This script sets up SC2 at the same version use competitively." say "SC2 will launch a blank window, be unresponsive, but download about 100mb in the background." say "" say "It will appear to hang as it updates. This is normal." say "Let it finish and close itself." say "" say "" say "This will only take a minute..." Sc2.config.version = nil client = Sc2::ClientManager.obtain(0) if Gem.win_platform? sleep(10) end observer = Sc2::Player::Observer.new observer.connect(host: client.host, port: client.port) setup_replay = Sc2::Paths.gem_root.join("data", "setup", "setup.SC2Replay") observer.api.replay_info( replay_data: File.binread(setup_replay), download_data: true ) # Auto-detect executable path and ensure it matched exactly base_build = "" Sc2::Client.versions_json.each do |node| if node["label"] == "ladder" base_build = node["base-version"].to_s break end end path = Sc2::Paths.executable(base_build: base_build) if path.include?(base_build) && Pathname(path).exist? say " " say "Success. Download complete.", :green say " " else say "Error. Slightly worrying, but no fear.", :red say "To manually setup, grab the latest ladder maps and add them to your map folder." say "Grab the latest maps from https://aiarena.net/wiki/maps/" say "Detected map folder: #{Sc2::Paths.maps_dir}" say "Then, download any recent replay from https://aiarena.net/ and double click to launch" end observer.api.quit observer.disconnect say "Generating sc2ai.yml to always use version 'ladder'..." Sc2.config.config_file.write({"version" => "ladder"}.to_yaml.to_s) say "" say "Done. You're good to go." say "To run an example match, execute:" say "" say "ruby run_example_match.rb", :cyan say "" ensure Sc2::ClientManager.stop(0) end end |
#ladderconfig ⇒ Object
94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 |
# File 'lib/sc2ai/cli/cli.rb', line 94 def ladderconfig require "sc2ai" unless Pathname("./boot.rb").exist? raise Sc2::Error, "boot.rb not found. Bot started from wrong directory." end require "./boot" # Debug Sc2.logger.info "Bot class: #{$bot.class}" Sc2.logger.info "Config:" Sc2.logger.info " in-game name: #{$bot.name}" Sc2.logger.info " race: #{Api::Race.lookup($bot.race)}" Sc2.logger.info " realtime: #{$bot.realtime}" Sc2.logger.info " step_count: #{$bot.step_count}" Sc2.logger.info " enable_feature_layer: #{$bot.enable_feature_layer}" Sc2.logger.info " interface_options: #{$bot.interface_options}" end |
#laddermatch ⇒ Object
118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 |
# File 'lib/sc2ai/cli/cli.rb', line 118 def laddermatch require "sc2ai" unless Sc2.ladder? raise Sc2::Error, "This command is only for competing on aiarena.net" end unless Pathname("./boot.rb").exist? raise Sc2::Error, "boot.rb not found. Bot started from wrong directory." end Sc2.logger.level = :info require "./boot" # Ladder specific overrides $bot.realtime = true if [:RealTime] $bot.opponent_id = [:OpponentId] if [:OpponentId] Async do $bot.connect(host: [:LadderServer], port: [:GamePort]) $bot.join_game( server_host: [:LadderServer], port_config: Sc2::Ports.port_config_basic(start_port: [:StartPort], num_players: 2) ) $bot.add_listener($bot, klass: Sc2::Connection::StatusListener) $bot.play end.wait end |
#setup410 ⇒ Object
23 24 25 |
# File 'lib/sc2ai/cli/cli.rb', line 23 def setup410 download_ladder_version end |