mirror of
https://github.com/TimeCrafters/timecrafters_configuration_tool_desktop.git
synced 2025-12-16 13:52:34 +00:00
Compare commits
11 Commits
v0.4.2_bet
...
v0.5.1
| Author | SHA1 | Date | |
|---|---|---|---|
| 9b505b8201 | |||
| c609734357 | |||
| fd6eb64232 | |||
| 7bfc404413 | |||
| 870a3e4e8b | |||
| aa6d53dd5e | |||
| 0f0009bcf0 | |||
| 7b7efabaf6 | |||
| 2948b02f12 | |||
| 44523b0bf2 | |||
| 7d2d44c52f |
6
.gitignore
vendored
6
.gitignore
vendored
@@ -3,3 +3,9 @@ data/**/*.json
|
||||
data/settings.json
|
||||
data/simulator.rb
|
||||
data/*.csv
|
||||
media/sounds/*
|
||||
!media/sounds/.gitkeep
|
||||
media/particles/*
|
||||
!media/particles/.gitkeep
|
||||
media/music/*
|
||||
!media/music/.gitkeep
|
||||
1
Gemfile
1
Gemfile
@@ -7,4 +7,5 @@ gem "clipboard"
|
||||
|
||||
group :packaging do
|
||||
gem "ocra"
|
||||
gem "releasy"
|
||||
end
|
||||
37
Gemfile.lock
Normal file
37
Gemfile.lock
Normal file
@@ -0,0 +1,37 @@
|
||||
GEM
|
||||
remote: https://rubygems.org/
|
||||
specs:
|
||||
clipboard (1.3.6)
|
||||
cri (2.1.0)
|
||||
cyberarm_engine (0.19.1)
|
||||
clipboard (~> 1.3.5)
|
||||
excon (~> 0.78.0)
|
||||
gosu (~> 1.1)
|
||||
gosu_more_drawables (~> 0.3)
|
||||
excon (0.78.1)
|
||||
ffi (1.15.4-x64-mingw32)
|
||||
gosu (1.2.0)
|
||||
gosu_more_drawables (0.3.1)
|
||||
gosu_notifications (0.1.0)
|
||||
ocra (1.3.11)
|
||||
rake (13.0.6)
|
||||
releasy (0.2.3)
|
||||
bundler (>= 1.2.1)
|
||||
cri (~> 2.1.0)
|
||||
ocra (~> 1.3.0)
|
||||
rake (>= 0.9.2.2)
|
||||
|
||||
PLATFORMS
|
||||
x64-mingw32
|
||||
x86_64-linux
|
||||
|
||||
DEPENDENCIES
|
||||
clipboard
|
||||
cyberarm_engine
|
||||
ffi
|
||||
gosu_notifications
|
||||
ocra
|
||||
releasy
|
||||
|
||||
BUNDLED WITH
|
||||
2.2.28
|
||||
12
Rakefile
12
Rakefile
@@ -7,7 +7,17 @@ Releasy::Project.new do
|
||||
version TAC::VERSION
|
||||
|
||||
executable "timecrafters_configuration_tool.rb"
|
||||
files ["lib/**/*.*", "media/**/*.*", "data"]
|
||||
files [
|
||||
"lib/**/*.*",
|
||||
"data/.gitkeep",
|
||||
"data/configs/.gitkeep",
|
||||
"media/*.*",
|
||||
"media/icons/*.*",
|
||||
"media/fonts/*.*",
|
||||
"media/sounds/.gitkeep",
|
||||
"media/music/.gitkeep",
|
||||
"media/particles/.gitkeep"
|
||||
]
|
||||
exclude_encoding # Applications that don't use advanced encoding (e.g. Japanese characters) can save build size with this.
|
||||
verbose
|
||||
|
||||
|
||||
@@ -7,9 +7,8 @@ module TAC
|
||||
|
||||
color = @dangerous ? Palette::DANGEROUS : Palette::ALERT
|
||||
|
||||
|
||||
@dialog_root.style.border_color = [ color, darken(color, 50) ]
|
||||
@titlebar.style.background = [ color, darken(color, 50) ]
|
||||
@dialog_root.style.default[:border_color] = [ color, darken(color, 50) ]
|
||||
@titlebar.style.default[:background] = [ color, darken(color, 50) ]
|
||||
|
||||
background Gosu::Color::GRAY
|
||||
label @options[:message]
|
||||
|
||||
@@ -2,8 +2,8 @@ module TAC
|
||||
class Dialog
|
||||
class TACNETDialog < Dialog
|
||||
def build
|
||||
@dialog_root.style.border_color = [ Palette::TACNET_PRIMARY, Palette::TACNET_SECONDARY ]
|
||||
@titlebar.style.background = [ Palette::TACNET_PRIMARY, Palette::TACNET_SECONDARY ]
|
||||
@dialog_root.style.default[:border_color] = [ Palette::TACNET_PRIMARY, Palette::TACNET_SECONDARY ]
|
||||
@titlebar.style.default[:background] = [ Palette::TACNET_PRIMARY, Palette::TACNET_SECONDARY ]
|
||||
|
||||
background Gosu::Color::GRAY
|
||||
label @options[:message], width: 1.0
|
||||
|
||||
70
lib/game_clock/clock.rb
Normal file
70
lib/game_clock/clock.rb
Normal file
@@ -0,0 +1,70 @@
|
||||
module TAC
|
||||
class PracticeGameClock
|
||||
class Clock
|
||||
CLOCK_SIZE = Gosu.screen_height
|
||||
TITLE_SIZE = 128
|
||||
|
||||
attr_reader :title, :controller
|
||||
|
||||
def initialize
|
||||
@title = CyberarmEngine::Text.new("FIRST TECH CHALLENGE", size: TITLE_SIZE, text_shadow: true, y: 10, color: Gosu::Color::GRAY)
|
||||
@title.x = $window.width / 2 - @title.width / 2
|
||||
|
||||
@text = CyberarmEngine::Text.new(":1234567890", size: CLOCK_SIZE, text_border: true, border_size: 2, border_color: Gosu::Color::GRAY)
|
||||
@text.width # trigger font-eager loading
|
||||
|
||||
@title.z, @text.z = -1, -1
|
||||
|
||||
@controller = nil
|
||||
end
|
||||
|
||||
def controller=(controller)
|
||||
@controller = controller
|
||||
end
|
||||
|
||||
def draw
|
||||
@title.draw
|
||||
@text.draw
|
||||
end
|
||||
|
||||
def update
|
||||
@title.x = $window.width / 2 - @title.width / 2
|
||||
|
||||
if @controller
|
||||
@text.color = @controller.display_color
|
||||
@text.text = clock_time(@controller.time_left)
|
||||
else
|
||||
@text.color = Gosu::Color::WHITE
|
||||
@text.text = "0:00"
|
||||
end
|
||||
|
||||
@text.x = $window.width / 2 - @text.textobject.text_width("0:00") / 2
|
||||
@text.y = $window.height / 2 - @text.height / 2
|
||||
|
||||
@controller&.update
|
||||
end
|
||||
|
||||
def active?
|
||||
if @controller
|
||||
@controller.clock? || @controller.countdown?
|
||||
else
|
||||
false
|
||||
end
|
||||
end
|
||||
|
||||
def value
|
||||
@text.text
|
||||
end
|
||||
|
||||
def clock_time(time_left)
|
||||
minutes = ((time_left + 0.5) / 60.0).floor
|
||||
|
||||
seconds = time_left.round % 60
|
||||
seconds = "0#{seconds}" if seconds < 10
|
||||
|
||||
return "#{minutes}:#{seconds}" if time_left.round.even?
|
||||
return "#{minutes}<c=999999>:</c>#{seconds}" if time_left.round.odd?
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
136
lib/game_clock/clock_controller.rb
Normal file
136
lib/game_clock/clock_controller.rb
Normal file
@@ -0,0 +1,136 @@
|
||||
module TAC
|
||||
class PracticeGameClock
|
||||
class ClockController
|
||||
Event = Struct.new(:event, :trigger_after, :arguments)
|
||||
|
||||
include EventHandlers
|
||||
|
||||
def self.create_event(event, trigger_after, arguments = nil)
|
||||
arguments = [arguments] unless arguments.is_a?(Array) || arguments == nil
|
||||
|
||||
Event.new(event, trigger_after, arguments)
|
||||
end
|
||||
|
||||
AUTONOMOUS = [
|
||||
create_event(:change_clock, 0.0, "2:30"),
|
||||
create_event(:change_countdown, 0.0, "0:03"),
|
||||
create_event(:change_color, 0.0, :red),
|
||||
create_event(:change_display, 0.0, :countdown),
|
||||
create_event(:start_countdown, 0.0),
|
||||
create_event(:play_sound, 0.0, :autonomous_countdown),
|
||||
create_event(:change_color, 3.0, :white),
|
||||
create_event(:change_display, 3.0, :clock),
|
||||
create_event(:play_sound, 3.0, :autonomous_start),
|
||||
create_event(:change_display, 3.0, :clock),
|
||||
create_event(:stop_countdown, 3.0),
|
||||
create_event(:start_clock, 3.0),
|
||||
create_event(:play_sound, 33.0, :autonomous_ended),
|
||||
create_event(:stop_clock, 33.0),
|
||||
].freeze
|
||||
|
||||
PRE_TELEOP = [
|
||||
create_event(:change_color, 33.0, :orange),
|
||||
create_event(:change_countdown, 33.0, "0:08"),
|
||||
create_event(:change_display, 33.0, :countdown),
|
||||
create_event(:start_countdown, 33.0),
|
||||
create_event(:play_sound, 34.5, :teleop_pickup_controllers),
|
||||
create_event(:change_color, 37.0, :red),
|
||||
create_event(:play_sound, 38.0, :teleop_countdown),
|
||||
create_event(:stop_countdown, 41.0),
|
||||
].freeze
|
||||
|
||||
TELEOP_ENDGAME = [
|
||||
create_event(:change_color, 131.0, :white),
|
||||
create_event(:change_clock, 131.0, "0:30"),
|
||||
create_event(:start_clock, 131.0),
|
||||
create_event(:play_sound, 131.0, :end_game),
|
||||
create_event(:play_sound, 158.0, :autonomous_countdown),
|
||||
create_event(:play_sound, 161.0, :end_match),
|
||||
create_event(:stop_clock, 161.0),
|
||||
].freeze
|
||||
|
||||
TELEOP = [
|
||||
create_event(:change_color, 41.0, :white),
|
||||
create_event(:change_clock, 41.0, "2:00"),
|
||||
create_event(:play_sound, 41.0, :teleop_started),
|
||||
create_event(:change_display, 41.0, :clock),
|
||||
create_event(:start_clock, 41.0),
|
||||
TELEOP_ENDGAME
|
||||
].flatten.freeze
|
||||
|
||||
FULL_TELEOP = [
|
||||
PRE_TELEOP,
|
||||
TELEOP,
|
||||
TELEOP_ENDGAME,
|
||||
].flatten.freeze
|
||||
|
||||
FULL_MATCH = [
|
||||
# Autonomous
|
||||
AUTONOMOUS,
|
||||
FULL_TELEOP
|
||||
].flatten.freeze
|
||||
|
||||
attr_reader :display_color
|
||||
def initialize(elapsed_time = 0, events = [])
|
||||
@events = events.dup
|
||||
@last_update = Gosu.milliseconds
|
||||
|
||||
@elapsed_time = elapsed_time
|
||||
@display = :clock
|
||||
|
||||
@clock_time = 0.0
|
||||
@countdown_time = 0.0
|
||||
|
||||
@clock_running = false
|
||||
@countdown_running = false
|
||||
|
||||
@display_color = Gosu::Color::WHITE
|
||||
end
|
||||
|
||||
def update
|
||||
dt = (Gosu.milliseconds - @last_update) / 1000.0
|
||||
update_active_timer(dt)
|
||||
|
||||
@events.select { |event| event.trigger_after <= @elapsed_time }.each do |event|
|
||||
@events.delete(event)
|
||||
|
||||
if event.arguments
|
||||
self.send(event.event, *event.arguments)
|
||||
else
|
||||
self.send(event.event)
|
||||
end
|
||||
end
|
||||
|
||||
@last_update = Gosu.milliseconds
|
||||
end
|
||||
|
||||
def update_active_timer(dt)
|
||||
if @clock_running
|
||||
@clock_time -= dt
|
||||
elsif @countdown_running
|
||||
@countdown_time -= dt
|
||||
end
|
||||
|
||||
@elapsed_time += dt
|
||||
end
|
||||
|
||||
def clock?
|
||||
@clock_running
|
||||
end
|
||||
|
||||
def countdown?
|
||||
@countdown_running
|
||||
end
|
||||
|
||||
def time_left
|
||||
if @clock_running
|
||||
return @clock_time
|
||||
elsif @countdown_running
|
||||
return @countdown_time
|
||||
else
|
||||
return 60 * 2 + 30
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
107
lib/game_clock/clock_proxy.rb
Normal file
107
lib/game_clock/clock_proxy.rb
Normal file
@@ -0,0 +1,107 @@
|
||||
module TAC
|
||||
class PracticeGameClock
|
||||
class ClockProxy
|
||||
attr_reader :queue, :clock
|
||||
|
||||
def initialize(clock, jukebox)
|
||||
@clock = clock
|
||||
@jukebox = jukebox
|
||||
|
||||
@queue = []
|
||||
@callbacks = {}
|
||||
end
|
||||
|
||||
def enqueue(&block)
|
||||
@queue << block
|
||||
end
|
||||
|
||||
def register(callback, method)
|
||||
@callbacks[callback] = method
|
||||
end
|
||||
|
||||
def start_clock(mode)
|
||||
return if @clock.active? || $window.current_state.is_a?(Randomizer)
|
||||
|
||||
@clock.controller = case mode
|
||||
when :full_match
|
||||
ClockController.new(0, ClockController::FULL_MATCH)
|
||||
when :autonomous
|
||||
ClockController.new(0, ClockController::AUTONOMOUS)
|
||||
when :full_teleop
|
||||
ClockController.new(33.0, ClockController::FULL_TELEOP)
|
||||
when :teleop_only
|
||||
ClockController.new(41.0, ClockController::TELEOP)
|
||||
when :endgame_only
|
||||
ClockController.new(131.0, ClockController::TELEOP_ENDGAME)
|
||||
else
|
||||
nil
|
||||
end
|
||||
end
|
||||
|
||||
def abort_clock
|
||||
@clock.controller&.play_sound(:abort_match) if @clock.active?
|
||||
@clock.controller = nil
|
||||
end
|
||||
|
||||
def set_clock_title(string)
|
||||
@clock.title.text = string.to_s
|
||||
@clock.title.x = $window.width / 2 - @clock.title.width / 2
|
||||
end
|
||||
|
||||
def get_clock_title(string)
|
||||
@clock.title
|
||||
end
|
||||
|
||||
def jukebox_previous_track
|
||||
@jukebox.previous_track
|
||||
end
|
||||
|
||||
def jukebox_next_track
|
||||
@jukebox.next_track
|
||||
end
|
||||
|
||||
def jukebox_stop
|
||||
@jukebox.stop
|
||||
end
|
||||
|
||||
def jukebox_play
|
||||
@jukebox.play
|
||||
end
|
||||
|
||||
def jukebox_pause
|
||||
@jukebox.pause
|
||||
end
|
||||
|
||||
def jukebox_set_volume(float)
|
||||
@jukebox.set_volume(float)
|
||||
end
|
||||
|
||||
def jukebox_volume
|
||||
@jukebox.volume
|
||||
end
|
||||
|
||||
def jukebox_current_track
|
||||
@jukebox.now_playing
|
||||
end
|
||||
|
||||
def jukebox_set_sound_effects(boolean)
|
||||
@jukebox.set_sfx(boolean)
|
||||
end
|
||||
|
||||
def jukebox_volume_changed(float)
|
||||
@callbacks[:volume_changed]&.call(float)
|
||||
end
|
||||
|
||||
def jukebox_track_changed(name)
|
||||
@callbacks[:track_changed]&.call(name)
|
||||
end
|
||||
|
||||
def randomizer_changed(boolean)
|
||||
@callbacks[:randomizer_changed]&.call(boolean)
|
||||
end
|
||||
|
||||
def shutdown!
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
89
lib/game_clock/event_handlers.rb
Normal file
89
lib/game_clock/event_handlers.rb
Normal file
@@ -0,0 +1,89 @@
|
||||
module TAC
|
||||
class PracticeGameClock
|
||||
module EventHandlers
|
||||
### Clock ###
|
||||
def start_clock
|
||||
@clock_running = true
|
||||
end
|
||||
|
||||
def stop_clock
|
||||
@clock_running = false
|
||||
end
|
||||
|
||||
def change_clock(value)
|
||||
@clock_time = time_from_string(value)
|
||||
end
|
||||
|
||||
### Countdown ###
|
||||
def start_countdown
|
||||
@countdown_running = true
|
||||
end
|
||||
|
||||
def stop_countdown
|
||||
@countdown_running = false
|
||||
end
|
||||
|
||||
|
||||
def change_countdown(value)
|
||||
@countdown_time = time_from_string(value)
|
||||
end
|
||||
|
||||
def change_display(display)
|
||||
end
|
||||
|
||||
def change_color(color)
|
||||
out = case color
|
||||
when :white
|
||||
Gosu::Color::WHITE
|
||||
when :orange
|
||||
Gosu::Color.rgb(150, 75, 0)
|
||||
when :red
|
||||
Gosu::Color.rgb(150, 0, 0)
|
||||
end
|
||||
|
||||
@display_color = out
|
||||
end
|
||||
|
||||
private def time_from_string(string)
|
||||
split = string.split(":")
|
||||
minutes = (split.first.to_i) * 60
|
||||
seconds = (split.last.to_i)
|
||||
|
||||
return minutes + seconds
|
||||
end
|
||||
|
||||
def play_sound(sound)
|
||||
path = nil
|
||||
case sound
|
||||
when :autonomous_countdown
|
||||
path = "media/sounds/3-2-1.wav"
|
||||
when :autonomous_start
|
||||
path = "media/sounds/charge.wav"
|
||||
when :autonomous_ended
|
||||
path = "media/sounds/endauto.wav"
|
||||
when :teleop_pickup_controllers
|
||||
path = "media/sounds/Pick_Up_Controllers.wav"
|
||||
when :abort_match
|
||||
path = "media/sounds/fogblast.wav"
|
||||
when :teleop_countdown
|
||||
path = "media/sounds/3-2-1.wav"
|
||||
when :teleop_started
|
||||
path = "media/sounds/firebell.wav"
|
||||
when :end_game
|
||||
path = "media/sounds/factwhistle.wav"
|
||||
when :end_match
|
||||
path = "media/sounds/endmatch.wav"
|
||||
end
|
||||
|
||||
path = "#{ROOT_PATH}/#{path}"
|
||||
|
||||
if path && File.exist?(path) && !File.directory?(path)
|
||||
Jukebox::SAMPLES[path] = Gosu::Sample.new(path) unless Jukebox::SAMPLES[path].is_a?(Gosu::Sample)
|
||||
Jukebox::SAMPLES[path].play
|
||||
else
|
||||
warn "WARNING: Sample for #{sound.inspect} could not be found at '#{path}'"
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
144
lib/game_clock/jukebox.rb
Normal file
144
lib/game_clock/jukebox.rb
Normal file
@@ -0,0 +1,144 @@
|
||||
module TAC
|
||||
class PracticeGameClock
|
||||
class Jukebox
|
||||
MUSIC = Dir.glob(ROOT_PATH + "/media/music/*.*").freeze
|
||||
SAMPLES = {}
|
||||
|
||||
if File.exist?(ROOT_PATH + "/media/sounds/skystone")
|
||||
BEEPS_AND_BOOPS = Dir.glob(ROOT_PATH + "/media/sounds/skystone/*.*").freeze
|
||||
end
|
||||
|
||||
attr_reader :volume, :now_playing
|
||||
|
||||
def initialize(clock)
|
||||
@clock = clock
|
||||
|
||||
@order = MUSIC.shuffle
|
||||
@now_playing = ""
|
||||
@playing = false
|
||||
@song = nil
|
||||
@volume = 1.0
|
||||
@last_check_time = Gosu.milliseconds
|
||||
|
||||
@last_sfx_time = Gosu.milliseconds
|
||||
@sfx_random_interval = generate_sfx_period
|
||||
@play_sfx = true
|
||||
|
||||
if defined?(BEEPS_AND_BOOPS)
|
||||
BEEPS_AND_BOOPS.each do |beep|
|
||||
SAMPLES[beep] = Gosu::Sample.new(beep)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def update
|
||||
return unless Gosu.milliseconds - @last_check_time >= 2000.0
|
||||
|
||||
@last_check_time = Gosu.milliseconds
|
||||
|
||||
if @song && !@song.playing? && !@song.paused?
|
||||
next_track if @playing
|
||||
end
|
||||
|
||||
if @play_sfx && defined?(BEEPS_AND_BOOPS)
|
||||
play_sfx
|
||||
end
|
||||
end
|
||||
|
||||
def play_sfx
|
||||
if Gosu.milliseconds - @last_sfx_time >= @sfx_random_interval
|
||||
@last_sfx_time = Gosu.milliseconds
|
||||
@sfx_random_interval = generate_sfx_period
|
||||
|
||||
pan = rand(0.49999..0.50001)
|
||||
volume = rand(0.75..1.0)
|
||||
speed = rand(0.5..1.25)
|
||||
SAMPLES[BEEPS_AND_BOOPS.sample].play_pan(pan, volume, speed) unless @clock.active?
|
||||
end
|
||||
end
|
||||
|
||||
def generate_sfx_period
|
||||
# rand(15..120) * 1000.0
|
||||
rand(5..10) * 1000.0
|
||||
end
|
||||
|
||||
def set_sfx(boolean)
|
||||
@play_sfx = boolean
|
||||
end
|
||||
|
||||
def play_sfx?
|
||||
@play_sfx
|
||||
end
|
||||
|
||||
def play
|
||||
if @song && @song.paused?
|
||||
@song.play
|
||||
else
|
||||
return false unless @order.size > 0
|
||||
|
||||
@current_song = @order.first
|
||||
@song = Gosu::Song.new(@current_song)
|
||||
@song.volume = @volume
|
||||
@song.play
|
||||
@now_playing = File.basename(@current_song)
|
||||
@order.rotate!(1)
|
||||
end
|
||||
|
||||
@playing = true
|
||||
end
|
||||
|
||||
def pause
|
||||
@playing = false
|
||||
@song.pause if @song
|
||||
end
|
||||
|
||||
def song
|
||||
@song
|
||||
end
|
||||
|
||||
def stop
|
||||
@song.stop if @song
|
||||
@playing = false
|
||||
@now_playing = ""
|
||||
end
|
||||
|
||||
def previous_track
|
||||
return false unless @order.size > 0
|
||||
|
||||
@song.stop if @song
|
||||
@order.rotate!(-1)
|
||||
@current_song = @order.first
|
||||
@song = Gosu::Song.new(@current_song)
|
||||
@song.volume = @volume
|
||||
@song.play
|
||||
|
||||
@playing = true
|
||||
@now_playing = File.basename(@current_song)
|
||||
end
|
||||
|
||||
def next_track
|
||||
return false unless @order.size > 0
|
||||
|
||||
@song.stop if @song
|
||||
@current_song = @order.first
|
||||
@song = Gosu::Song.new(@current_song)
|
||||
@song.volume = @volume
|
||||
@song.play
|
||||
@order.rotate!(1)
|
||||
|
||||
@playing = true
|
||||
@now_playing = File.basename(@current_song)
|
||||
end
|
||||
|
||||
def current_track
|
||||
@current_song
|
||||
end
|
||||
|
||||
def set_volume(float)
|
||||
@volume = float
|
||||
@volume = @volume.clamp(0.1, 1.0)
|
||||
@song.volume = @volume if @song
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
28
lib/game_clock/logger.rb
Normal file
28
lib/game_clock/logger.rb
Normal file
@@ -0,0 +1,28 @@
|
||||
module TAC
|
||||
class PracticeGameClock
|
||||
class ClockNet
|
||||
class Logger
|
||||
def printer(message)
|
||||
# return
|
||||
puts "#{Time.now.strftime("%Y-%m-%d %H:%M:%S %Z")} #{message}"
|
||||
end
|
||||
|
||||
def i(tag, message)
|
||||
printer("INFO #{tag}: #{message}")
|
||||
end
|
||||
|
||||
def d(tag, message)
|
||||
printer("DEBUG #{tag}: #{message}")
|
||||
end
|
||||
|
||||
def e(tag, message)
|
||||
printer("ERROR #{tag}: #{message}")
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def log
|
||||
@logger ||= ClockNet::Logger.new
|
||||
end
|
||||
end
|
||||
end
|
||||
162
lib/game_clock/net/client.rb
Normal file
162
lib/game_clock/net/client.rb
Normal file
@@ -0,0 +1,162 @@
|
||||
require "securerandom"
|
||||
|
||||
module TAC
|
||||
class PracticeGameClock
|
||||
class ClockNet
|
||||
class Client
|
||||
TAG = "ClockNet|Client"
|
||||
CHUNK_SIZE = 4096
|
||||
PACKET_TAIL = "\r\n\n"
|
||||
|
||||
attr_reader :uuid, :read_queue, :write_queue, :socket,
|
||||
:packets_sent, :packets_received,
|
||||
:data_sent, :data_received
|
||||
attr_accessor :sync_interval, :last_socket_error, :socket_error
|
||||
def initialize
|
||||
@uuid = SecureRandom.uuid
|
||||
@read_queue = []
|
||||
@write_queue = []
|
||||
|
||||
@sync_interval = 100
|
||||
|
||||
@last_socket_error = nil
|
||||
@socket_error = false
|
||||
@bound = false
|
||||
|
||||
@packets_sent, @packets_received = 0, 0
|
||||
@data_sent, @data_received = 0, 0
|
||||
end
|
||||
|
||||
def uuid=(id)
|
||||
@uuid = id
|
||||
end
|
||||
|
||||
def socket=(socket)
|
||||
@socket = socket
|
||||
@bound = true
|
||||
|
||||
listen
|
||||
end
|
||||
|
||||
def listen
|
||||
Thread.new do
|
||||
while connected?
|
||||
# Read from socket
|
||||
while message_in = read
|
||||
if message_in.empty?
|
||||
break
|
||||
else
|
||||
log.i(TAG, "Read: " + message_in)
|
||||
|
||||
@read_queue << message_in
|
||||
|
||||
@packets_received += 1
|
||||
@data_received += message_in.length
|
||||
end
|
||||
end
|
||||
|
||||
sleep @sync_interval / 1000.0
|
||||
end
|
||||
end
|
||||
|
||||
Thread.new do
|
||||
while connected?
|
||||
# Write to socket
|
||||
while message_out = @write_queue.shift
|
||||
write(message_out)
|
||||
|
||||
@packets_sent += 1
|
||||
@data_sent += message_out.to_s.length
|
||||
log.i(TAG, "Write: " + message_out.to_s)
|
||||
end
|
||||
|
||||
sleep @sync_interval / 1000.0
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def sync(block)
|
||||
block.call
|
||||
end
|
||||
|
||||
def handle_read_queue
|
||||
message = gets
|
||||
|
||||
while message
|
||||
puts(message)
|
||||
|
||||
log.i(TAG, "Writing to Queue: " + message)
|
||||
|
||||
message = gets
|
||||
end
|
||||
end
|
||||
|
||||
def socket_error?
|
||||
@socket_error
|
||||
end
|
||||
|
||||
def connected?
|
||||
if closed? == true || closed? == nil
|
||||
false
|
||||
else
|
||||
true
|
||||
end
|
||||
end
|
||||
|
||||
def closed?
|
||||
@socket.closed? if @socket
|
||||
end
|
||||
|
||||
def write(message)
|
||||
begin
|
||||
@socket.puts("#{message}#{PACKET_TAIL}")
|
||||
rescue => error
|
||||
@last_socket_error = error
|
||||
@socket_error = true
|
||||
log.e(TAG, error.message)
|
||||
close
|
||||
end
|
||||
end
|
||||
|
||||
def read
|
||||
begin
|
||||
message = @socket.gets
|
||||
rescue => error
|
||||
@last_socket_error = error
|
||||
@socket_error = true
|
||||
|
||||
message = ""
|
||||
end
|
||||
|
||||
|
||||
return message.strip
|
||||
end
|
||||
|
||||
def puts(message)
|
||||
@write_queue << message
|
||||
end
|
||||
|
||||
def gets
|
||||
@read_queue.shift
|
||||
end
|
||||
|
||||
def encode(message)
|
||||
return message
|
||||
end
|
||||
|
||||
def decode(blob)
|
||||
return blob
|
||||
end
|
||||
|
||||
def flush
|
||||
@socket.flush if socket
|
||||
end
|
||||
|
||||
def close(reason = nil)
|
||||
write(reason) if reason
|
||||
@socket.close if @socket
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
97
lib/game_clock/net/connection.rb
Normal file
97
lib/game_clock/net/connection.rb
Normal file
@@ -0,0 +1,97 @@
|
||||
module TAC
|
||||
class PracticeGameClock
|
||||
class ClockNet
|
||||
class Connection
|
||||
TAG = "ClockNet|Connection"
|
||||
attr_reader :hostname, :port, :client, :proxy_object
|
||||
|
||||
def initialize(hostname: "localhost", port: 4567, proxy_object:)
|
||||
@hostname = hostname
|
||||
@port = port
|
||||
@proxy_object = proxy_object
|
||||
|
||||
@client = nil
|
||||
|
||||
@last_sync_time = Gosu.milliseconds
|
||||
@sync_interval = SYNC_INTERVAL
|
||||
|
||||
@last_heartbeat_sent = Gosu.milliseconds
|
||||
@heartbeat_interval = HEARTBEAT_INTERVAL
|
||||
|
||||
@connection_handler = proc do
|
||||
handle_connection
|
||||
end
|
||||
|
||||
@packet_handler = PacketHandler.new(host_is_a_connection: true, proxy_object: @proxy_object)
|
||||
end
|
||||
|
||||
def connect
|
||||
return if @client
|
||||
|
||||
@client = Client.new
|
||||
|
||||
Thread.new do
|
||||
begin
|
||||
@client.socket = Socket.tcp(@hostname, @port, connect_timeout: 5)
|
||||
@client.socket.setsockopt(Socket::IPPROTO_TCP, Socket::TCP_NODELAY, 1)
|
||||
log.i(TAG, "Connected to: #{@hostname}:#{@port}")
|
||||
|
||||
while @client && @client.connected?
|
||||
if Gosu.milliseconds > @last_sync_time + @sync_interval
|
||||
@last_sync_time = Gosu.milliseconds
|
||||
|
||||
@client.sync(@connection_handler)
|
||||
end
|
||||
end
|
||||
|
||||
rescue => error
|
||||
log.e(TAG, error)
|
||||
|
||||
if @client
|
||||
@client.close
|
||||
@client.last_socket_error = error
|
||||
@client.socket_error = true
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def handle_connection
|
||||
if @client && @client.connected?
|
||||
message = @client.gets
|
||||
|
||||
@packet_handler.handle(message) if message
|
||||
|
||||
if Gosu.milliseconds > @last_heartbeat_sent + @heartbeat_interval
|
||||
@last_heartbeat_sent = Gosu.milliseconds
|
||||
|
||||
@client.puts(PacketHandler.packet_heartbeat)
|
||||
end
|
||||
|
||||
sleep @sync_interval / 1000.0
|
||||
end
|
||||
end
|
||||
|
||||
def puts(packet)
|
||||
@client.puts(packet)
|
||||
end
|
||||
|
||||
def gets
|
||||
@client.gets
|
||||
end
|
||||
|
||||
def connected?
|
||||
@client.connected? if @client
|
||||
end
|
||||
|
||||
def closed?
|
||||
@client.closed? if @client
|
||||
end
|
||||
|
||||
def close
|
||||
@client.close if @client
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
109
lib/game_clock/net/packet.rb
Normal file
109
lib/game_clock/net/packet.rb
Normal file
@@ -0,0 +1,109 @@
|
||||
module TAC
|
||||
class PracticeGameClock
|
||||
class ClockNet
|
||||
SYNC_INTERVAL = 250
|
||||
HEARTBEAT_INTERVAL = 1_500
|
||||
|
||||
class Packet
|
||||
PROTOCOL_VERSION = 1
|
||||
PROTOCOL_SEPERATOR = "|"
|
||||
PROTOCOL_HEARTBEAT = "heartbeat"
|
||||
|
||||
PACKET_TYPES = {
|
||||
handshake: 0,
|
||||
heartbeat: 1,
|
||||
error: 2,
|
||||
shutdown: 3,
|
||||
|
||||
start_clock: 10,
|
||||
abort_clock: 11,
|
||||
|
||||
set_clock_title: 20,
|
||||
get_clock_title: 21,
|
||||
clock_title: 22,
|
||||
clock_time: 23,
|
||||
|
||||
randomizer_visible: 27,
|
||||
|
||||
jukebox_previous_track: 30,
|
||||
jukebox_next_track: 31,
|
||||
jukebox_stop: 32,
|
||||
jukebox_play: 33,
|
||||
jukebox_pause: 34,
|
||||
jukebox_set_volume: 35,
|
||||
jukebox_get_volume: 36,
|
||||
jukebox_volume: 37,
|
||||
jukebox_get_current_track: 38,
|
||||
jukebox_current_track: 39,
|
||||
jukebox_get_sound_effects: 40,
|
||||
jukebox_set_sound_effects: 41,
|
||||
jukebox_sound_effects: 42,
|
||||
}
|
||||
|
||||
def self.from_stream(message)
|
||||
slice = message.split("|", 4)
|
||||
|
||||
if slice.size < 4
|
||||
warn "Failed to split packet along first 4 " + PROTOCOL_SEPERATOR + ". Raw return: " + slice.to_s
|
||||
return nil
|
||||
end
|
||||
|
||||
if slice.first != PROTOCOL_VERSION.to_s
|
||||
warn "Incompatible protocol version received, expected: " + PROTOCOL_VERSION.to_s + " got: " + slice.first
|
||||
return nil
|
||||
end
|
||||
|
||||
unless valid_packet_type?(Integer(slice[1]))
|
||||
warn "Unknown packet type detected: #{slice[1]}"
|
||||
return nil
|
||||
end
|
||||
|
||||
protocol_version = Integer(slice[0])
|
||||
type = PACKET_TYPES.key(Integer(slice[1]))
|
||||
content_length = Integer(slice[2])
|
||||
body = slice[3]
|
||||
|
||||
raise "Type is #{type.inspect} [#{type.class}]" unless type.is_a?(Symbol)
|
||||
|
||||
return Packet.new(protocol_version, type, content_length, body)
|
||||
end
|
||||
|
||||
def self.create(packet_type, body)
|
||||
Packet.new(PROTOCOL_VERSION, PACKET_TYPES.key(packet_type), body.length, body)
|
||||
end
|
||||
|
||||
def self.valid_packet_type?(packet_type)
|
||||
PACKET_TYPES.values.find { |t| t == packet_type }
|
||||
end
|
||||
|
||||
attr_reader :protocol_version, :type, :content_length, :body
|
||||
def initialize(protocol_version, type, content_length, body)
|
||||
@protocol_version = protocol_version
|
||||
@type = type
|
||||
@content_length = content_length
|
||||
@body = body
|
||||
end
|
||||
|
||||
def encode_header
|
||||
string = ""
|
||||
string += protocol_version.to_s
|
||||
string += PROTOCOL_SEPERATOR
|
||||
string += PACKET_TYPES[type].to_s
|
||||
string += PROTOCOL_SEPERATOR
|
||||
string += content_length.to_s
|
||||
string += PROTOCOL_SEPERATOR
|
||||
|
||||
return string
|
||||
end
|
||||
|
||||
def valid?
|
||||
true
|
||||
end
|
||||
|
||||
def to_s
|
||||
"#{encode_header}#{body}"
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
320
lib/game_clock/net/packet_handler.rb
Normal file
320
lib/game_clock/net/packet_handler.rb
Normal file
@@ -0,0 +1,320 @@
|
||||
module TAC
|
||||
class PracticeGameClock
|
||||
class ClockNet
|
||||
class PacketHandler
|
||||
TAG = "ClockNet|PacketHandler"
|
||||
def initialize(host_is_a_connection: false, proxy_object:)
|
||||
@host_is_a_connection = host_is_a_connection
|
||||
@proxy_object = proxy_object
|
||||
end
|
||||
|
||||
def handle(message)
|
||||
packet = Packet.from_stream(message)
|
||||
|
||||
if packet
|
||||
log.i(TAG, "Received packet of type: #{packet.type}")
|
||||
hand_off(packet)
|
||||
else
|
||||
log.d(TAG, "Rejected raw packet: #{message}")
|
||||
end
|
||||
end
|
||||
|
||||
def hand_off(packet)
|
||||
case packet.type
|
||||
when :handshake
|
||||
handle_handshake(packet)
|
||||
when :heartbeat
|
||||
handle_heartbeat(packet)
|
||||
when :error
|
||||
handle_error(packet)
|
||||
|
||||
when :start_clock
|
||||
handle_start_clock(packet)
|
||||
when :abort_clock
|
||||
handle_abort_clock(packet)
|
||||
when :get_clock_title
|
||||
handle_get_clock_title(packet)
|
||||
when :set_clock_title
|
||||
handle_set_clock_title(packet)
|
||||
when :clock_title
|
||||
handle_clock_title(packet)
|
||||
when :jukebox_previous_track
|
||||
handle_jukebox_previous_track(packet)
|
||||
when :jukebox_next_track
|
||||
handle_jukebox_next_track(packet)
|
||||
when :jukebox_play
|
||||
handle_jukebox_play(packet)
|
||||
when :jukebox_pause
|
||||
handle_jukebox_pause(packet)
|
||||
when :jukebox_stop
|
||||
handle_jukebox_stop(packet)
|
||||
when :jukebox_set_volume
|
||||
handle_jukebox_set_volume(packet)
|
||||
when :jukebox_volume
|
||||
handle_jukebox_volume(packet)
|
||||
when :jukebox_set_sound_effects
|
||||
handle_jukebox_set_sound_effects(packet)
|
||||
when :jukebox_current_track
|
||||
handle_jukebox_current_track(packet)
|
||||
when :clock_time
|
||||
handle_clock_time(packet)
|
||||
when :randomizer_visible
|
||||
handle_randomizer_visible(packet)
|
||||
when :shutdown
|
||||
handle_shutdown(packet)
|
||||
else
|
||||
log.d(TAG, "No hand off available for packet type: #{packet.type}")
|
||||
end
|
||||
end
|
||||
|
||||
def handle_handshake(packet)
|
||||
if @host_is_a_connection
|
||||
end
|
||||
end
|
||||
|
||||
# TODO: Reset socket timeout
|
||||
def handle_heartbeat(packet)
|
||||
end
|
||||
|
||||
# TODO: Handle errors
|
||||
def handle_error(packet)
|
||||
title, message = packet.body.split(Packet::PROTOCOL_SEPERATOR, 2)
|
||||
log.e(TAG, "Remote error: #{title}: #{message}")
|
||||
end
|
||||
|
||||
def handle_start_clock(packet)
|
||||
return if @host_is_a_connection
|
||||
|
||||
@proxy_object.enqueue do
|
||||
@proxy_object.start_clock(packet.body.to_sym)
|
||||
end
|
||||
end
|
||||
|
||||
def handle_abort_clock(packet)
|
||||
return if @host_is_a_connection
|
||||
|
||||
@proxy_object.abort_clock
|
||||
end
|
||||
|
||||
def handle_set_clock_title(packet)
|
||||
return if @host_is_a_connection
|
||||
|
||||
title = packet.body
|
||||
|
||||
@proxy_object.enqueue do
|
||||
@proxy_object.set_clock_title(title)
|
||||
end
|
||||
end
|
||||
|
||||
def handle_get_clock_title(packet)
|
||||
return if @host_is_a_connection
|
||||
|
||||
RemoteControl.server.active_client.puts(Packet.clock_title(@proxy_object.clock.title))
|
||||
end
|
||||
|
||||
def handle_jukebox_previous_track(packet)
|
||||
return if @host_is_a_connection
|
||||
|
||||
@proxy_object.jukebox_previous_track
|
||||
|
||||
RemoteControl.server.active_client.puts(PacketHandler.packet_jukebox_current_track(@proxy_object.jukebox_current_track))
|
||||
end
|
||||
|
||||
def handle_jukebox_next_track(packet)
|
||||
return if @host_is_a_connection
|
||||
|
||||
@proxy_object.jukebox_next_track
|
||||
|
||||
RemoteControl.server.active_client.puts(PacketHandler.packet_jukebox_current_track(@proxy_object.jukebox_current_track))
|
||||
end
|
||||
|
||||
def handle_jukebox_play(packet)
|
||||
return if @host_is_a_connection
|
||||
|
||||
@proxy_object.jukebox_play
|
||||
|
||||
RemoteControl.server.active_client.puts(PacketHandler.packet_jukebox_current_track(@proxy_object.jukebox_current_track))
|
||||
end
|
||||
|
||||
def handle_jukebox_pause(packet)
|
||||
return if @host_is_a_connection
|
||||
|
||||
@proxy_object.jukebox_pause
|
||||
|
||||
RemoteControl.server.active_client.puts(PacketHandler.packet_jukebox_current_track(@proxy_object.jukebox_current_track))
|
||||
end
|
||||
|
||||
def handle_jukebox_stop(packet)
|
||||
return if @host_is_a_connection
|
||||
|
||||
@proxy_object.jukebox_stop
|
||||
|
||||
RemoteControl.server.active_client.puts(PacketHandler.packet_jukebox_current_track(@proxy_object.jukebox_current_track))
|
||||
end
|
||||
|
||||
def handle_jukebox_set_volume(packet)
|
||||
return if @host_is_a_connection
|
||||
|
||||
float = packet.body.to_f
|
||||
float = float.clamp(0.0, 1.0)
|
||||
|
||||
@proxy_object.jukebox_set_volume(float)
|
||||
|
||||
float = @proxy_object.jukebox_volume
|
||||
RemoteControl.server.active_client.puts(PacketHandler.packet_jukebox_volume(float))
|
||||
end
|
||||
|
||||
def handle_jukebox_get_volume(packet)
|
||||
return if @host_is_a_connection
|
||||
|
||||
float = @proxy_object.jukebox_volume
|
||||
|
||||
RemoteControl.server.active_client.puts(PacketHandler.packet_jukebox_volume(float))
|
||||
end
|
||||
|
||||
def handle_jukebox_volume(packet)
|
||||
return unless @host_is_a_connection
|
||||
|
||||
float = packet.body.to_f
|
||||
|
||||
@proxy_object.enqueue do
|
||||
@proxy_object.volume_changed(float)
|
||||
end
|
||||
end
|
||||
|
||||
def handle_jukebox_set_sound_effects(packet)
|
||||
return if @host_is_a_connection
|
||||
|
||||
boolean = packet.body == "true"
|
||||
|
||||
@proxy_object.enqueue do
|
||||
@proxy_object.jukebox_set_sound_effects(boolean)
|
||||
end
|
||||
end
|
||||
|
||||
def handle_jukebox_current_track(packet)
|
||||
return unless @host_is_a_connection
|
||||
|
||||
@proxy_object.enqueue do
|
||||
@proxy_object.track_changed(packet.body)
|
||||
end
|
||||
end
|
||||
|
||||
def handle_clock_time(packet)
|
||||
return unless @host_is_a_connection
|
||||
|
||||
@proxy_object.enqueue do
|
||||
@proxy_object.clock_changed(packet.body)
|
||||
end
|
||||
end
|
||||
|
||||
def handle_randomizer_visible(packet)
|
||||
boolean = packet.body == "true"
|
||||
boolean = false if @proxy_object.is_a?(ClockProxy) && @proxy_object.clock.active?
|
||||
|
||||
@proxy_object.enqueue do
|
||||
@proxy_object.randomizer_changed(boolean)
|
||||
end
|
||||
|
||||
return if @host_is_a_connection
|
||||
|
||||
# Send confirmation to client
|
||||
RemoteControl.server.active_client.puts(PacketHandler.packet_randomizer_visible(boolean))
|
||||
end
|
||||
|
||||
def handle_shutdown(packet)
|
||||
unless @host_is_a_connection
|
||||
# RemoteControl.server.close
|
||||
# $window.close
|
||||
Gosu::Song.current_song&.stop
|
||||
exit
|
||||
end
|
||||
end
|
||||
|
||||
def self.packet_handshake(client_uuid)
|
||||
Packet.create(Packet::PACKET_TYPES[:handshake], client_uuid)
|
||||
end
|
||||
|
||||
def self.packet_heartbeat
|
||||
Packet.create(Packet::PACKET_TYPES[:heartbeat], Packet::PROTOCOL_HEARTBEAT)
|
||||
end
|
||||
|
||||
def self.packet_error(error_code, message)
|
||||
Packet.create(Packet::PACKET_TYPES[:error], error_code.to_s, message.to_s)
|
||||
end
|
||||
|
||||
def self.packet_start_clock(mode)
|
||||
Packet.create(Packet::PACKET_TYPES[:start_clock], mode.to_s)
|
||||
end
|
||||
|
||||
def self.packet_abort_clock
|
||||
Packet.create(Packet::PACKET_TYPES[:abort_clock], "")
|
||||
end
|
||||
|
||||
def self.packet_set_clock_title(string)
|
||||
Packet.create(Packet::PACKET_TYPES[:set_clock_title], string.to_s)
|
||||
end
|
||||
|
||||
def self.packet_get_clock_title
|
||||
Packet.create(Packet::PACKET_TYPES[:get_clock_title], "")
|
||||
end
|
||||
|
||||
def self.packet_clock_title(string)
|
||||
Packet.create(Packet::PACKET_TYPES[:clock_title], string.to_s)
|
||||
end
|
||||
|
||||
def self.packet_jukebox_previous_track
|
||||
Packet.create(Packet::PACKET_TYPES[:jukebox_previous_track], "")
|
||||
end
|
||||
|
||||
def self.packet_jukebox_next_track
|
||||
Packet.create(Packet::PACKET_TYPES[:jukebox_next_track], "")
|
||||
end
|
||||
|
||||
def self.packet_jukebox_play
|
||||
Packet.create(Packet::PACKET_TYPES[:jukebox_play], "")
|
||||
end
|
||||
|
||||
def self.packet_jukebox_pause
|
||||
Packet.create(Packet::PACKET_TYPES[:jukebox_pause], "")
|
||||
end
|
||||
|
||||
def self.packet_jukebox_stop
|
||||
Packet.create(Packet::PACKET_TYPES[:jukebox_stop], "")
|
||||
end
|
||||
|
||||
def self.packet_jukebox_set_volume(float)
|
||||
Packet.create(Packet::PACKET_TYPES[:jukebox_set_volume], float.to_s)
|
||||
end
|
||||
|
||||
def self.packet_jukebox_get_volume
|
||||
Packet.create(Packet::PACKET_TYPES[:jukebox_get_volume], "")
|
||||
end
|
||||
|
||||
def self.packet_jukebox_volume(float)
|
||||
Packet.create(Packet::PACKET_TYPES[:jukebox_volume], float.to_s)
|
||||
end
|
||||
|
||||
def self.packet_jukebox_set_sound_effects(boolean)
|
||||
Packet.create(Packet::PACKET_TYPES[:jukebox_set_sound_effects], boolean.to_s)
|
||||
end
|
||||
|
||||
def self.packet_jukebox_current_track(name)
|
||||
Packet.create(Packet::PACKET_TYPES[:jukebox_current_track], name)
|
||||
end
|
||||
|
||||
def self.packet_clock_time(string)
|
||||
Packet.create(Packet::PACKET_TYPES[:clock_time], string)
|
||||
end
|
||||
|
||||
def self.packet_randomizer_visible(boolean)
|
||||
Packet.create(Packet::PACKET_TYPES[:randomizer_visible], boolean.to_s)
|
||||
end
|
||||
|
||||
def self.packet_shutdown
|
||||
Packet.create(Packet::PACKET_TYPES[:shutdown], "")
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
147
lib/game_clock/net/server.rb
Normal file
147
lib/game_clock/net/server.rb
Normal file
@@ -0,0 +1,147 @@
|
||||
module TAC
|
||||
class PracticeGameClock
|
||||
class ClockNet
|
||||
class Server
|
||||
TAG = "ClockNet|Server"
|
||||
attr_reader :active_client,
|
||||
:packets_sent, :packets_received, :data_sent, :data_received,
|
||||
:client_last_packets_sent, :client_last_packets_received, :client_last_data_sent, :client_last_data_received,
|
||||
:proxy_object
|
||||
def initialize(hostname: "localhost", port: 4567, proxy_object: )
|
||||
$server = self
|
||||
|
||||
@hostname = hostname
|
||||
@port = port
|
||||
@proxy_object = proxy_object
|
||||
|
||||
@socket = nil
|
||||
@active_client = nil
|
||||
@connection_attempts = 0
|
||||
@max_connection_attempts = 10
|
||||
|
||||
@packets_sent, @packets_received, @client_last_packets_sent, @client_last_packets_received = 0, 0, 0, 0
|
||||
@data_sent, @data_received, @client_last_data_sent, @client_last_data_received = 0, 0, 0, 0
|
||||
|
||||
@last_sync_time = Gosu.milliseconds
|
||||
@sync_interval = SYNC_INTERVAL
|
||||
|
||||
@last_heartbeat_sent = Gosu.milliseconds
|
||||
@heartbeat_interval = HEARTBEAT_INTERVAL
|
||||
|
||||
@client_handler_proc = proc do
|
||||
handle_client
|
||||
end
|
||||
|
||||
@packet_handler = PacketHandler.new(proxy_object: @proxy_object)
|
||||
end
|
||||
|
||||
def start(run_on_main_thread: false)
|
||||
thread = Thread.new do
|
||||
while (!@socket && @connection_attempts < @max_connection_attempts)
|
||||
begin
|
||||
log.i(TAG, "Starting server...")
|
||||
@socket = TCPServer.new(@port)
|
||||
@socket.setsockopt(Socket::IPPROTO_TCP, Socket::TCP_NODELAY, 1)
|
||||
rescue IOError => error
|
||||
log.e(TAG, error)
|
||||
|
||||
@connection_attempts += 1
|
||||
retry if @connection_attempts < @max_connection_attempts
|
||||
end
|
||||
end
|
||||
|
||||
while @socket && !@socket.closed?
|
||||
begin
|
||||
run_server
|
||||
rescue IOError => error
|
||||
log.e(TAG, error)
|
||||
@socket.close if @socket
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
thread.join if run_on_main_thread
|
||||
end
|
||||
|
||||
def run_server
|
||||
while !@socket.closed?
|
||||
client = Client.new
|
||||
client.sync_interval = @sync_interval
|
||||
client.socket = @socket.accept
|
||||
|
||||
if @active_client && @active_client.connected?
|
||||
log.i(TAG, "Too many clients, already have one connected!")
|
||||
client.close("Too many clients!")
|
||||
else
|
||||
@active_client = client
|
||||
# TODO: Backup local config
|
||||
# SEND CONFIG
|
||||
|
||||
@active_client.puts(PacketHandler.packet_handshake(@active_client.uuid))
|
||||
|
||||
log.i(TAG, "Client connected!")
|
||||
|
||||
Thread.new do
|
||||
while @active_client && @active_client.connected?
|
||||
if Gosu.milliseconds > @last_sync_time + @sync_interval
|
||||
@last_sync_time = Gosu.milliseconds
|
||||
|
||||
@active_client.sync(@client_handler_proc)
|
||||
update_stats
|
||||
end
|
||||
end
|
||||
|
||||
update_stats
|
||||
@active_client = nil
|
||||
|
||||
@client_last_packets_sent = 0
|
||||
@client_last_packets_received = 0
|
||||
@client_last_data_sent = 0
|
||||
@client_last_data_received = 0
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def handle_client
|
||||
if @active_client && @active_client.connected?
|
||||
message = @active_client.gets
|
||||
|
||||
if message && !message.empty?
|
||||
@packet_handler.handle(message)
|
||||
end
|
||||
|
||||
if Gosu.milliseconds > @last_heartbeat_sent + @heartbeat_interval
|
||||
@last_heartbeat_sent = Gosu.milliseconds
|
||||
|
||||
@active_client.puts(PacketHandler.packet_heartbeat)
|
||||
end
|
||||
|
||||
sleep @sync_interval / 1000.0
|
||||
end
|
||||
end
|
||||
|
||||
def close
|
||||
@socket.close
|
||||
end
|
||||
|
||||
private def update_stats
|
||||
if @active_client
|
||||
# NOTE: Sent and Received are reversed for Server stats
|
||||
|
||||
@packets_sent += @active_client.packets_received - @client_last_packets_received
|
||||
@packets_received += @active_client.packets_sent - @client_last_packets_sent
|
||||
|
||||
@data_sent += @active_client.data_received - @client_last_data_received
|
||||
@data_received += @active_client.data_sent - @client_last_data_sent
|
||||
|
||||
@client_last_packets_sent = @active_client.packets_sent
|
||||
@client_last_packets_received = @active_client.packets_received
|
||||
@client_last_data_sent = @active_client.data_sent
|
||||
@client_last_data_received = @active_client.data_received
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
135
lib/game_clock/particle_emitter.rb
Normal file
135
lib/game_clock/particle_emitter.rb
Normal file
@@ -0,0 +1,135 @@
|
||||
module TAC
|
||||
class PracticeGameClock
|
||||
class ParticleEmitter
|
||||
def initialize(max_particles: 50, time_to_live: 30_000, interval: 1_500, z: -2)
|
||||
@max_particles = max_particles
|
||||
@time_to_live = time_to_live
|
||||
@interval = interval
|
||||
@z = -2
|
||||
|
||||
@particles = []
|
||||
@image_options = Dir.glob("#{ROOT_PATH}/media/particles/*.*")
|
||||
@last_spawned = 0
|
||||
@clock_active = false
|
||||
end
|
||||
|
||||
def draw
|
||||
@particles.each(&:draw)
|
||||
end
|
||||
|
||||
def update
|
||||
@particles.each { |part| part.update($window.dt) }
|
||||
@particles.delete_if { |part| part.die? }
|
||||
|
||||
spawn_particles
|
||||
end
|
||||
|
||||
def spawn_particles
|
||||
# !clock_active? &&
|
||||
if @particles.count < @max_particles && Gosu.milliseconds - @last_spawned >= @interval
|
||||
screen_midpoint = CyberarmEngine::Vector.new($window.width / 2, $window.height / 2)
|
||||
scale = rand(0.25..1.0)
|
||||
image_name = @image_options.sample
|
||||
|
||||
return unless image_name
|
||||
|
||||
image = $window.current_state.get_image(image_name)
|
||||
position = CyberarmEngine::Vector.new(0, 0)
|
||||
|
||||
r = rand
|
||||
if r < 0.25 # LEFT
|
||||
position.x = -image.width * scale
|
||||
position.y = rand(0..($window.height - image.height * scale))
|
||||
elsif r < 0.5 # RIGHT
|
||||
position.x = $window.width + (image.width * scale)
|
||||
position.y = rand(0..($window.height - image.height * scale))
|
||||
elsif r < 0.75 # TOP
|
||||
position.x = rand(0..($window.width - image.width * scale))
|
||||
position.y = -image.height * scale
|
||||
else #BOTTOM
|
||||
position.x = rand(0..($window.width - image.width * scale))
|
||||
position.y = $window.height + image.height * scale
|
||||
end
|
||||
|
||||
position.x ||= 0
|
||||
position.y ||= 0
|
||||
|
||||
velocity = (screen_midpoint - position)
|
||||
|
||||
@particles << Particle.new(
|
||||
image: image,
|
||||
position: position,
|
||||
velocity: velocity,
|
||||
time_to_live: @time_to_live,
|
||||
speed: rand(24..128),
|
||||
scale: scale,
|
||||
clock_active: @clock_active,
|
||||
z: @z
|
||||
)
|
||||
|
||||
@last_spawned = Gosu.milliseconds
|
||||
end
|
||||
end
|
||||
|
||||
def clock_active!
|
||||
@clock_active = true
|
||||
@particles.each(&:clock_active!)
|
||||
end
|
||||
|
||||
def clock_inactive!
|
||||
@clock_active = false
|
||||
@particles.each(&:clock_inactive!)
|
||||
end
|
||||
|
||||
def clock_active?
|
||||
@clock_active
|
||||
end
|
||||
|
||||
class Particle
|
||||
def initialize(image:, position:, velocity:, time_to_live:, speed:, z:, scale: 1.0, clock_active: false)
|
||||
@image = image
|
||||
@position = position
|
||||
@velocity = velocity.normalized
|
||||
@time_to_live = time_to_live
|
||||
@speed = speed
|
||||
@z = z
|
||||
@scale = scale
|
||||
|
||||
@born_at = Gosu.milliseconds
|
||||
@born_time_to_live = time_to_live
|
||||
@color = Gosu::Color.new(0xff_ffffff)
|
||||
@clock_active = clock_active
|
||||
end
|
||||
|
||||
def draw
|
||||
@image.draw(@position.x, @position.y, @z, @scale, @scale, @color)
|
||||
end
|
||||
|
||||
def update(dt)
|
||||
@position += @velocity * @speed * dt
|
||||
|
||||
@color.alpha = (255.0 * ratio).to_i.clamp(0, 255)
|
||||
end
|
||||
|
||||
def ratio
|
||||
r = 1.0 - ((Gosu.milliseconds - @born_at) / @time_to_live.to_f)
|
||||
@clock_active ? r.clamp(0.0, 0.5) : r
|
||||
end
|
||||
|
||||
def die?
|
||||
ratio <= 0
|
||||
end
|
||||
|
||||
def clock_active!
|
||||
@clock_active = true
|
||||
# @time_to_live = (Gosu.milliseconds - @born_at) + 1_000
|
||||
end
|
||||
|
||||
def clock_inactive!
|
||||
@clock_active = false
|
||||
# @time_to_live = @born_time_to_live unless Gosu.milliseconds - @born_at < @time_to_live
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
179
lib/game_clock/randomizer.rb
Normal file
179
lib/game_clock/randomizer.rb
Normal file
@@ -0,0 +1,179 @@
|
||||
require "securerandom"
|
||||
|
||||
module TAC
|
||||
class PracticeGameClock
|
||||
class Randomizer < CyberarmEngine::GameState
|
||||
def setup
|
||||
@roll = SecureRandom.random_number(1..6)
|
||||
|
||||
@dimple_color = 0xff_008000
|
||||
@dimple_res = 36
|
||||
|
||||
@size = [window.width, window.height].min / 2.0
|
||||
|
||||
@ducks = []
|
||||
|
||||
case @roll
|
||||
when 1, 4
|
||||
# Blue: Right
|
||||
# Red: Left
|
||||
|
||||
@ducks << Ducky.new(window: window, alliance: :blue, slot: 3, speed: 512, die_size: @size)
|
||||
@ducks << Ducky.new(window: window, alliance: :red, slot: 1, speed: 512, die_size: @size)
|
||||
when 2, 5
|
||||
#Blue and Red: Center
|
||||
|
||||
@ducks << Ducky.new(window: window, alliance: :blue, slot: 2, speed: 512, die_size: @size)
|
||||
@ducks << Ducky.new(window: window, alliance: :red, slot: 2, speed: 512, die_size: @size)
|
||||
when 3, 6
|
||||
# Blue: Left
|
||||
# Red: Right
|
||||
|
||||
@ducks << Ducky.new(window: window, alliance: :blue, slot: 1, speed: 512, die_size: @size)
|
||||
@ducks << Ducky.new(window: window, alliance: :red, slot: 3, speed: 512, die_size: @size)
|
||||
end
|
||||
end
|
||||
|
||||
def draw
|
||||
window.previous_state.draw
|
||||
|
||||
Gosu.flush
|
||||
|
||||
fill(0xdd_202020)
|
||||
|
||||
Gosu.translate(window.width * 0.5 - @size * 0.5, 24) do
|
||||
Gosu.draw_rect(0, 0, @size, @size, Gosu::Color::BLACK)
|
||||
Gosu.draw_rect(12, 12, @size - 24, @size - 24, Gosu::Color::GRAY)
|
||||
|
||||
self.send(:"dice_#{@roll}", @size)
|
||||
end
|
||||
|
||||
@ducks.each { |o| o.draw(@size) }
|
||||
end
|
||||
|
||||
def dimple(size)
|
||||
size / 9.0
|
||||
end
|
||||
|
||||
def update
|
||||
window.previous_state&.update_non_gui
|
||||
|
||||
@ducks.each { |o| o.update(@size) }
|
||||
|
||||
@size = [window.width, window.height].min / 2.0
|
||||
end
|
||||
|
||||
def button_down(id)
|
||||
case id
|
||||
when Gosu::MS_LEFT, Gosu::KB_ESCAPE, Gosu::KB_SPACE
|
||||
pop_state
|
||||
end
|
||||
end
|
||||
|
||||
def dice_1(size)
|
||||
Gosu.draw_circle(size / 2, size / 2, dimple(size), @dimple_res, @dimple_color)
|
||||
end
|
||||
|
||||
def dice_2(size)
|
||||
Gosu.draw_circle(size * 0.25, size * 0.25, dimple(size), @dimple_res, @dimple_color)
|
||||
Gosu.draw_circle(size * 0.75, size * 0.75, dimple(size), @dimple_res, @dimple_color)
|
||||
end
|
||||
|
||||
def dice_3(size)
|
||||
Gosu.draw_circle(size * 0.25, size * 0.25, dimple(size), @dimple_res, @dimple_color)
|
||||
Gosu.draw_circle(size * 0.50, size * 0.50, dimple(size), @dimple_res, @dimple_color)
|
||||
Gosu.draw_circle(size * 0.75, size * 0.75, dimple(size), @dimple_res, @dimple_color)
|
||||
end
|
||||
|
||||
def dice_4(size)
|
||||
Gosu.draw_circle(size * 0.25, size * 0.25, dimple(size), @dimple_res, @dimple_color)
|
||||
Gosu.draw_circle(size * 0.75, size * 0.25, dimple(size), @dimple_res, @dimple_color)
|
||||
Gosu.draw_circle(size * 0.25, size * 0.75, dimple(size), @dimple_res, @dimple_color)
|
||||
Gosu.draw_circle(size * 0.75, size * 0.75, dimple(size), @dimple_res, @dimple_color)
|
||||
end
|
||||
|
||||
def dice_5(size)
|
||||
Gosu.draw_circle(size * 0.50, size * 0.50, dimple(size), @dimple_res, @dimple_color)
|
||||
Gosu.draw_circle(size * 0.25, size * 0.25, dimple(size), @dimple_res, @dimple_color)
|
||||
Gosu.draw_circle(size * 0.75, size * 0.25, dimple(size), @dimple_res, @dimple_color)
|
||||
Gosu.draw_circle(size * 0.25, size * 0.75, dimple(size), @dimple_res, @dimple_color)
|
||||
Gosu.draw_circle(size * 0.75, size * 0.75, dimple(size), @dimple_res, @dimple_color)
|
||||
end
|
||||
|
||||
def dice_6(size)
|
||||
Gosu.draw_circle(size * 0.25, size * 0.20, dimple(size), @dimple_res, @dimple_color)
|
||||
Gosu.draw_circle(size * 0.75, size * 0.20, dimple(size), @dimple_res, @dimple_color)
|
||||
Gosu.draw_circle(size * 0.25, size * 0.50, dimple(size), @dimple_res, @dimple_color)
|
||||
Gosu.draw_circle(size * 0.75, size * 0.50, dimple(size), @dimple_res, @dimple_color)
|
||||
Gosu.draw_circle(size * 0.25, size * 0.80, dimple(size), @dimple_res, @dimple_color)
|
||||
Gosu.draw_circle(size * 0.75, size * 0.80, dimple(size), @dimple_res, @dimple_color)
|
||||
end
|
||||
|
||||
class Ducky
|
||||
SIZE = 0.20
|
||||
HALF_SIZE = SIZE * 0.5
|
||||
|
||||
def initialize(window:, alliance:, slot:, speed:, die_size:)
|
||||
@window = window
|
||||
@alliance = alliance
|
||||
@slot = slot
|
||||
@speed = speed
|
||||
|
||||
@image = @window.get_image("#{ROOT_PATH}/media/openclipart_ducky.png")
|
||||
@debug_text = Gosu::Font.new(28)
|
||||
|
||||
if @alliance == :blue
|
||||
@position = CyberarmEngine::Vector.new(@window.width, die_size)
|
||||
else
|
||||
@position = CyberarmEngine::Vector.new(-die_size, die_size + die_size * 0.40)
|
||||
end
|
||||
end
|
||||
|
||||
def draw(size)
|
||||
Gosu.translate(@position.x, @position.y) do
|
||||
Gosu.draw_rect(0, size * SIZE, size * SIZE, size * SIZE, alliance_color)
|
||||
Gosu.draw_rect(size * 0.5 - size * HALF_SIZE, size * SIZE, size * SIZE, size * SIZE, alliance_color)
|
||||
Gosu.draw_rect(size * (1.0 - SIZE), size * SIZE, size * SIZE, size * SIZE, alliance_color)
|
||||
|
||||
duck_scale = (size * (SIZE + HALF_SIZE)) / @image.width
|
||||
duck_scale_x = @alliance == :blue ? -duck_scale : duck_scale
|
||||
@image.draw_rot(slot_position(size), size * SIZE + float_y(size), 1, 0, 0.5, 0.5, duck_scale_x, duck_scale)
|
||||
end
|
||||
end
|
||||
|
||||
def update(size)
|
||||
center = @window.width * 0.5 - size * 0.5
|
||||
|
||||
if @position.x > center
|
||||
@position.x -= @speed * @window.dt
|
||||
@position.x = center if @position.x < center
|
||||
elsif @position.x < center
|
||||
@position.x += @speed * @window.dt
|
||||
@position.x = center if @position.x > center
|
||||
end
|
||||
end
|
||||
|
||||
def alliance_color
|
||||
@alliance == :blue ? 0xff_000080 : 0xff_800000
|
||||
end
|
||||
|
||||
def slot_position(size)
|
||||
case @slot
|
||||
when 1
|
||||
size * HALF_SIZE
|
||||
when 2
|
||||
size * 0.5
|
||||
when 3
|
||||
size * (1.0 - HALF_SIZE)
|
||||
else
|
||||
raise "Slot value of: #{@slot.inspect} is invalid!"
|
||||
end
|
||||
end
|
||||
|
||||
def float_y(size)
|
||||
Math.sin(Gosu.milliseconds / 100.0) * (size * 0.01)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
271
lib/game_clock/remote_control.rb
Normal file
271
lib/game_clock/remote_control.rb
Normal file
@@ -0,0 +1,271 @@
|
||||
module TAC
|
||||
class PracticeGameClock
|
||||
class RemoteControl
|
||||
@@connection = nil
|
||||
@@server = nil
|
||||
|
||||
def self.connection
|
||||
@@connection
|
||||
end
|
||||
|
||||
def self.connection=(connection)
|
||||
@@connection = connection
|
||||
end
|
||||
|
||||
def self.server
|
||||
@@server
|
||||
end
|
||||
|
||||
def self.server=(server)
|
||||
@@server = server
|
||||
end
|
||||
|
||||
class NetConnect < CyberarmEngine::GuiState
|
||||
def setup
|
||||
theme(THEME)
|
||||
|
||||
background Palette::TACNET_NOT_CONNECTED
|
||||
|
||||
banner "ClockNet Remote Control", text_align: :center, width: 1.0
|
||||
flow(width: 1.0) do
|
||||
stack(width: 0.25) {}
|
||||
stack(width: 0.5) do
|
||||
title "Hostname"
|
||||
@hostname = edit_line "localhost", width: 1.0
|
||||
title "Port"
|
||||
@port = edit_line "4567", width: 1.0
|
||||
|
||||
flow(width: 1.0, margin_top: 20) do
|
||||
@back_button = button "Back", width: 0.5 do
|
||||
window.pop_state
|
||||
end
|
||||
|
||||
@connect_button = button "Connect", width: 0.5 do
|
||||
begin
|
||||
@connect_button.enabled = false
|
||||
@back_button.enabled = false
|
||||
|
||||
@connection = ClockNet::Connection.new(hostname: @hostname.value, port: Integer(@port.value), proxy_object: RemoteProxy.new(window))
|
||||
|
||||
@connection.connect
|
||||
RemoteControl.connection = @connection
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def update
|
||||
super
|
||||
|
||||
if RemoteControl.connection
|
||||
push_state(Controller) if RemoteControl.connection.connected?
|
||||
|
||||
RemoteControl.connection = nil if RemoteControl.connection.client.socket_error?
|
||||
else
|
||||
@back_button.enabled = true
|
||||
@connect_button.enabled = true
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
class Controller < CyberarmEngine::GuiState
|
||||
def setup
|
||||
theme(THEME)
|
||||
|
||||
at_exit do
|
||||
@connection&.close
|
||||
end
|
||||
|
||||
@jukebox_volume = 1.0
|
||||
@jukebox_sound_effects = true
|
||||
@randomizer_visible = false
|
||||
|
||||
RemoteControl.connection.proxy_object.register(:track_changed, method(:track_changed))
|
||||
RemoteControl.connection.proxy_object.register(:volume_changed, method(:volume_changed))
|
||||
RemoteControl.connection.proxy_object.register(:clock_changed, method(:clock_changed))
|
||||
RemoteControl.connection.proxy_object.register(:randomizer_changed, method(:randomizer_changed))
|
||||
|
||||
background Palette::TACNET_NOT_CONNECTED
|
||||
|
||||
banner "ClockNet Remote Control", text_align: :center, width: 1.0
|
||||
|
||||
flow width: 1.0, height: 1.0 do
|
||||
stack width: 0.5 do
|
||||
title "Match", width: 1.0, text_align: :center
|
||||
button "Start Match", width: 1.0, text_size: 48, margin_bottom: 50 do
|
||||
start_clock(:full_match)
|
||||
end
|
||||
|
||||
title "Practice", width: 1.0, text_align: :center
|
||||
button "Autonomous", width: 1.0 do
|
||||
start_clock(:autonomous)
|
||||
end
|
||||
button "TeleOp with Countdown", width: 1.0 do
|
||||
start_clock(:full_teleop)
|
||||
end
|
||||
button "TeleOp", width: 1.0 do
|
||||
start_clock(:teleop_only)
|
||||
end
|
||||
button "TeleOp Endgame", width: 1.0, margin_bottom: 50 do
|
||||
start_clock(:endgame_only)
|
||||
end
|
||||
|
||||
button "Abort Match", width: 1.0 do
|
||||
RemoteControl.connection.puts(ClockNet::PacketHandler.packet_abort_clock)
|
||||
end
|
||||
|
||||
button "Shutdown", width: 1.0, **TAC::THEME_DANGER_BUTTON do
|
||||
RemoteControl.connection.puts(ClockNet::PacketHandler.packet_shutdown)
|
||||
sleep 1 # let packet escape before closing
|
||||
end
|
||||
end
|
||||
|
||||
stack width: 0.495 do
|
||||
title "Clock Title", width: 1.0, text_align: :center
|
||||
|
||||
stack width: 0.9, margin_left: 50 do
|
||||
@title = edit_line "FIRST TECH CHALLENGE", width: 1.0
|
||||
|
||||
button "Update", width: 1.0, margin_bottom: 50 do
|
||||
RemoteControl.connection.puts(ClockNet::PacketHandler.packet_set_clock_title(@title.value.strip))
|
||||
end
|
||||
end
|
||||
|
||||
title "JukeBox", width: 1.0, text_align: :center
|
||||
stack width: 0.9, margin_left: 50 do
|
||||
flow width: 1.0 do
|
||||
tagline "Now Playing: "
|
||||
@track_name = tagline ""
|
||||
end
|
||||
|
||||
flow width: 1.0 do
|
||||
tagline "Volume: "
|
||||
@volume = tagline "100%"
|
||||
end
|
||||
|
||||
flow width: 1.0 do
|
||||
button get_image("#{ROOT_PATH}/media/icons/previous.png") do
|
||||
RemoteControl.connection.puts(ClockNet::PacketHandler.packet_jukebox_previous_track)
|
||||
end
|
||||
|
||||
button get_image("#{ROOT_PATH}/media/icons/right.png") do |button|
|
||||
if @jukebox_playing
|
||||
RemoteControl.connection.puts(ClockNet::PacketHandler.packet_jukebox_pause)
|
||||
button.value = get_image("#{ROOT_PATH}/media/icons/right.png")
|
||||
@jukebox_playing = false
|
||||
else
|
||||
RemoteControl.connection.puts(ClockNet::PacketHandler.packet_jukebox_play)
|
||||
button.value = get_image("#{ROOT_PATH}/media/icons/pause.png")
|
||||
@jukebox_playing = true
|
||||
end
|
||||
end
|
||||
|
||||
button get_image("#{ROOT_PATH}/media/icons/stop.png") do
|
||||
RemoteControl.connection.puts(ClockNet::PacketHandler.packet_jukebox_stop)
|
||||
end
|
||||
|
||||
button get_image("#{ROOT_PATH}/media/icons/next.png") do
|
||||
RemoteControl.connection.puts(ClockNet::PacketHandler.packet_jukebox_next_track)
|
||||
end
|
||||
|
||||
button get_image("#{ROOT_PATH}/media/icons/minus.png"), margin_left: 20 do
|
||||
@jukebox_volume -= 0.1
|
||||
@jukebox_volume = 0.1 if @jukebox_volume < 0.1
|
||||
RemoteControl.connection.puts(ClockNet::PacketHandler.packet_jukebox_set_volume(@jukebox_volume))
|
||||
end
|
||||
|
||||
button get_image("#{ROOT_PATH}/media/icons/plus.png") do
|
||||
@jukebox_volume += 0.1
|
||||
@jukebox_volume = 1.0 if @jukebox_volume > 1.0
|
||||
RemoteControl.connection.puts(ClockNet::PacketHandler.packet_jukebox_set_volume(@jukebox_volume))
|
||||
end
|
||||
|
||||
button get_image("#{ROOT_PATH}/media/icons/musicOn.png"), margin_left: 20, tip: "Toggle Sound Effects" do |button|
|
||||
if @jukebox_sound_effects
|
||||
button.value = get_image("#{ROOT_PATH}/media/icons/musicOff.png")
|
||||
@jukebox_sound_effects = false
|
||||
else
|
||||
button.value = get_image("#{ROOT_PATH}/media/icons/musicOn.png")
|
||||
@jukebox_sound_effects = true
|
||||
end
|
||||
|
||||
RemoteControl.connection.puts(ClockNet::PacketHandler.packet_jukebox_set_sound_effects(@jukebox_sound_effects))
|
||||
end
|
||||
end
|
||||
|
||||
button "Open Music Library", width: 1.0 do
|
||||
path = "#{ROOT_PATH}/media/music"
|
||||
|
||||
if RUBY_PLATFORM.match(/ming|msys|cygwin/)
|
||||
system("explorer \"#{path.gsub("/", "\\")}\"")
|
||||
elsif RUBY_PLATFORM.match(/linux/)
|
||||
system("xdg-open \"#{ROOT_PATH}/media/music\"")
|
||||
else
|
||||
# TODO.
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
stack width: 0.9, margin_left: 50, margin_top: 20 do
|
||||
flow width: 1.0 do
|
||||
title "Clock: "
|
||||
@clock_label = title "0:00"
|
||||
end
|
||||
|
||||
flow width: 1.0 do
|
||||
title "Randomizer: "
|
||||
@randomizer_label = title "Not Visible"
|
||||
end
|
||||
|
||||
button "Randomizer", width: 1.0, **TAC::THEME_DANGER_BUTTON do
|
||||
@randomizer_visible = !@randomizer_visible
|
||||
|
||||
RemoteControl.connection.puts(ClockNet::PacketHandler.packet_randomizer_visible(@randomizer_visible))
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def update
|
||||
super
|
||||
|
||||
while (o = RemoteControl.connection.proxy_object.queue.shift)
|
||||
o.call
|
||||
end
|
||||
|
||||
return if RemoteControl.connection.connected?
|
||||
|
||||
# We've lost connection, unset window's connection object
|
||||
# and send user back to connect screen to to attempt to
|
||||
# reconnect
|
||||
RemoteControl.connection = nil
|
||||
pop_state
|
||||
end
|
||||
|
||||
def start_clock(mode)
|
||||
RemoteControl.connection.puts(ClockNet::PacketHandler.packet_start_clock(mode.to_s))
|
||||
end
|
||||
|
||||
def track_changed(name)
|
||||
@track_name.value = name
|
||||
end
|
||||
|
||||
def volume_changed(float)
|
||||
@volume.value = "#{(float.round(1) * 100.0).round}%"
|
||||
end
|
||||
|
||||
def clock_changed(string)
|
||||
@clock_label.value = string
|
||||
end
|
||||
|
||||
def randomizer_changed(boolean)
|
||||
@randomizer_label.value = "Visible" if boolean
|
||||
@randomizer_label.value = "Not Visible" unless boolean
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
71
lib/game_clock/remote_proxy.rb
Normal file
71
lib/game_clock/remote_proxy.rb
Normal file
@@ -0,0 +1,71 @@
|
||||
module TAC
|
||||
class PracticeGameClock
|
||||
class RemoteProxy
|
||||
attr_reader :queue
|
||||
|
||||
def initialize(window)
|
||||
@window = window
|
||||
|
||||
@queue = []
|
||||
@callbacks = {}
|
||||
end
|
||||
|
||||
def enqueue(&block)
|
||||
@queue << block
|
||||
end
|
||||
|
||||
def register(callback, method)
|
||||
@callbacks[callback] = method
|
||||
end
|
||||
|
||||
def start_clock(mode)
|
||||
end
|
||||
|
||||
def abort_clock
|
||||
end
|
||||
|
||||
def set_clock_title(string)
|
||||
end
|
||||
|
||||
def get_clock_title(string)
|
||||
end
|
||||
|
||||
def jukebox_previous_track
|
||||
end
|
||||
|
||||
def jukebox_next_track
|
||||
end
|
||||
|
||||
def jukebox_stop
|
||||
end
|
||||
|
||||
def jukebox_play
|
||||
end
|
||||
|
||||
def jukebox_pause
|
||||
end
|
||||
|
||||
def jukebox_sound_effects(boolean)
|
||||
end
|
||||
|
||||
def volume_changed(float)
|
||||
@callbacks[:volume_changed]&.call(float)
|
||||
end
|
||||
|
||||
def track_changed(name)
|
||||
@callbacks[:track_changed]&.call(name)
|
||||
end
|
||||
|
||||
def clock_changed(string)
|
||||
@callbacks[:clock_changed]&.call(string)
|
||||
end
|
||||
|
||||
def randomizer_changed(boolean)
|
||||
@callbacks[:randomizer_changed]&.call(boolean)
|
||||
end
|
||||
|
||||
def shutdown!
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
30
lib/game_clock/theme.rb
Normal file
30
lib/game_clock/theme.rb
Normal file
@@ -0,0 +1,30 @@
|
||||
module TAC
|
||||
class PracticeGameClock
|
||||
THEME = {
|
||||
TextBlock: {
|
||||
font: "Canterell",
|
||||
color: Gosu::Color.new(0xee_ffffff)
|
||||
},
|
||||
Button: {
|
||||
image_width: 40,
|
||||
text_size: 40,
|
||||
background: Palette::TIMECRAFTERS_PRIMARY,
|
||||
border_thickness: 1,
|
||||
border_color: Gosu::Color.new(0xff_111111),
|
||||
hover: {
|
||||
background: Palette::TIMECRAFTERS_SECONDARY,
|
||||
},
|
||||
active: {
|
||||
background: Palette::TIMECRAFTERS_TERTIARY,
|
||||
}
|
||||
},
|
||||
EditLine: {
|
||||
caret_color: Gosu::Color.new(0xff_88ef90),
|
||||
},
|
||||
ToggleButton: {
|
||||
width: 18,
|
||||
checkmark_image: "#{File.expand_path("..", __dir__)}/media/icons/checkmark.png",
|
||||
}
|
||||
}
|
||||
end
|
||||
end
|
||||
297
lib/game_clock/view.rb
Normal file
297
lib/game_clock/view.rb
Normal file
@@ -0,0 +1,297 @@
|
||||
module TAC
|
||||
class PracticeGameClock
|
||||
class View < CyberarmEngine::GuiState
|
||||
|
||||
attr_reader :clock
|
||||
|
||||
def setup
|
||||
@remote_control_mode = @options[:remote_control_mode]
|
||||
window.show_cursor = !@remote_control_mode
|
||||
@escape_counter = 0
|
||||
|
||||
@background_image = get_image("#{ROOT_PATH}/media/background.png")
|
||||
# Preload duck image since Gosu and windows threads don't get along with OpenGL (image is blank if loaded in a threaded context)
|
||||
get_image("#{ROOT_PATH}/media/openclipart_ducky.png")
|
||||
@menu_background = 0xaa004000
|
||||
@mouse = Mouse.new(window)
|
||||
@clock = Clock.new
|
||||
@clock.controller = nil
|
||||
@last_clock_display_value = @clock.value
|
||||
|
||||
@particle_emitters = [
|
||||
PracticeGameClock::ParticleEmitter.new
|
||||
]
|
||||
|
||||
@last_clock_state = @clock.active?
|
||||
|
||||
theme(THEME)
|
||||
|
||||
@menu_container = flow width: 1.0 do
|
||||
stack(width: 0.35, padding: 5) do
|
||||
background @menu_background
|
||||
|
||||
title "Match", width: 1.0, text_align: :center
|
||||
button "Start Match", width: 1.0, margin_bottom: 50 do
|
||||
@clock_proxy.start_clock(:full_match)
|
||||
end
|
||||
|
||||
title "Practice", width: 1.0, text_align: :center
|
||||
button "Autonomous", width: 1.0 do
|
||||
@clock_proxy.start_clock(:autonomous)
|
||||
end
|
||||
|
||||
button "TeleOp with Countdown", width: 1.0 do
|
||||
@clock_proxy.start_clock(:full_teleop)
|
||||
end
|
||||
|
||||
button "TeleOp", width: 1.0 do
|
||||
@clock_proxy.start_clock(:teleop_only)
|
||||
end
|
||||
|
||||
button "TeleOp Endgame", width: 1.0 do
|
||||
@clock_proxy.start_clock(:endgame_only)
|
||||
end
|
||||
|
||||
button "Abort Match", width: 1.0, margin_top: 50 do
|
||||
@clock_proxy.abort_clock
|
||||
end
|
||||
|
||||
button "Close", width: 1.0, **TAC::THEME_DANGER_BUTTON do
|
||||
if window.instance_variable_get(:"@states").size == 1
|
||||
window.close
|
||||
else
|
||||
@server&.close
|
||||
|
||||
@jukebox.stop
|
||||
window.fullscreen = false
|
||||
window.pop_state
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
stack width: 0.4, padding_left: 50 do
|
||||
background @menu_background
|
||||
|
||||
flow do
|
||||
label "♫ Now playing:"
|
||||
@current_song_label = label "♫ ♫ ♫"
|
||||
end
|
||||
|
||||
flow do
|
||||
label "Volume:"
|
||||
@current_volume_label = label "100%"
|
||||
end
|
||||
|
||||
flow do
|
||||
button get_image("#{ROOT_PATH}/media/icons/previous.png") do
|
||||
@jukebox.previous_track
|
||||
end
|
||||
|
||||
button get_image("#{ROOT_PATH}/media/icons/pause.png") do |button|
|
||||
if @jukebox.song && @jukebox.song.paused?
|
||||
button.value = get_image("#{ROOT_PATH}/media/icons/right.png")
|
||||
@jukebox.play
|
||||
elsif !@jukebox.song
|
||||
button.value = get_image("#{ROOT_PATH}/media/icons/right.png")
|
||||
@jukebox.play
|
||||
else
|
||||
button.value = get_image("#{ROOT_PATH}/media/icons/pause.png")
|
||||
@jukebox.pause
|
||||
end
|
||||
end
|
||||
|
||||
button get_image("#{ROOT_PATH}/media/icons/stop.png") do
|
||||
@jukebox.stop
|
||||
end
|
||||
|
||||
button get_image("#{ROOT_PATH}/media/icons/next.png") do
|
||||
@jukebox.next_track
|
||||
end
|
||||
|
||||
button get_image("#{ROOT_PATH}/media/icons/minus.png"), margin_left: 20 do
|
||||
@jukebox.set_volume(@jukebox.volume - 0.1)
|
||||
end
|
||||
|
||||
button get_image("#{ROOT_PATH}/media/icons/plus.png") do
|
||||
@jukebox.set_volume(@jukebox.volume + 0.1)
|
||||
end
|
||||
|
||||
button "Open Music Library", margin_left: 50 do
|
||||
if RUBY_PLATFORM.match(/ming|msys|cygwin/)
|
||||
system("explorer #{ROOT_PATH}/media/music")
|
||||
elsif RUBY_PLATFORM.match(/linux/)
|
||||
system("xdg-open #{ROOT_PATH}/media/music")
|
||||
else
|
||||
# TODO.
|
||||
end
|
||||
end
|
||||
|
||||
button get_image("#{ROOT_PATH}/media/icons/musicOn.png"), margin_left: 50, tip: "Toggle Sound Effects" do |button|
|
||||
boolean = @jukebox.set_sfx(!@jukebox.play_sfx?)
|
||||
|
||||
if boolean
|
||||
button.value = get_image("#{ROOT_PATH}/media/icons/musicOn.png")
|
||||
else
|
||||
button.value = get_image("#{ROOT_PATH}/media/icons/musicOff.png")
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
stack width: 1.0 do
|
||||
button "Randomizer", width: 1.0, **TAC::THEME_DANGER_BUTTON do
|
||||
unless @clock.active?
|
||||
push_state(Randomizer)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@jukebox = Jukebox.new(@clock)
|
||||
|
||||
@clock_proxy = ClockProxy.new(@clock, @jukebox)
|
||||
|
||||
if @remote_control_mode
|
||||
@server = ClockNet::Server.new(proxy_object: @clock_proxy)
|
||||
@server.start
|
||||
RemoteControl.server = @server
|
||||
|
||||
@clock_proxy.register(:randomizer_changed, method(:randomizer_changed))
|
||||
end
|
||||
end
|
||||
|
||||
def draw
|
||||
background_image_scale = [window.width.to_f / @background_image.width, window.height.to_f / @background_image.height].max
|
||||
|
||||
@background_image.draw(0, 0, -3, background_image_scale, background_image_scale)
|
||||
@particle_emitters.each(&:draw)
|
||||
@clock.draw
|
||||
|
||||
super
|
||||
end
|
||||
|
||||
def update
|
||||
super
|
||||
@clock.update
|
||||
@mouse.update
|
||||
update_non_gui
|
||||
|
||||
if @last_clock_state != @clock.active?
|
||||
@particle_emitters.each { |emitter| @clock.active? ? emitter.clock_active! : emitter.clock_inactive! }
|
||||
end
|
||||
|
||||
if @remote_control_mode
|
||||
@menu_container.hide
|
||||
else
|
||||
if @mouse.last_moved < 1.5
|
||||
@menu_container.show unless @menu_container.visible?
|
||||
window.show_cursor = true
|
||||
else
|
||||
@menu_container.hide if @menu_container.visible?
|
||||
window.show_cursor = false
|
||||
end
|
||||
end
|
||||
|
||||
if @clock.value != @last_clock_display_value
|
||||
@last_clock_display_value = @clock.value
|
||||
|
||||
if @remote_control_mode && @server.active_client
|
||||
@server.active_client.puts(ClockNet::PacketHandler.packet_clock_time(@last_clock_display_value))
|
||||
end
|
||||
end
|
||||
|
||||
if @last_track_name != @jukebox.current_track
|
||||
track_changed(@jukebox.current_track)
|
||||
end
|
||||
|
||||
if @last_volume != @jukebox.volume
|
||||
volume_changed(@jukebox.volume)
|
||||
end
|
||||
|
||||
@last_track_name = @jukebox.current_track
|
||||
@last_volume = @jukebox.volume
|
||||
@last_clock_state = @clock.active?
|
||||
end
|
||||
|
||||
def update_non_gui
|
||||
if @remote_control_mode
|
||||
while (o = RemoteControl.server.proxy_object.queue.shift)
|
||||
o.call
|
||||
end
|
||||
end
|
||||
|
||||
@particle_emitters.each(&:update)
|
||||
@jukebox.update
|
||||
end
|
||||
|
||||
def button_down(id)
|
||||
super
|
||||
|
||||
@mouse.button_down(id)
|
||||
|
||||
case id
|
||||
when Gosu::KB_ESCAPE
|
||||
@escape_counter += 1
|
||||
|
||||
if @escape_counter >= 3
|
||||
@server&.close
|
||||
|
||||
if window.instance_variable_get(:"@states").size == 1
|
||||
window.close
|
||||
else
|
||||
window.fullscreen = false
|
||||
window.pop_state
|
||||
end
|
||||
end
|
||||
else
|
||||
@escape_counter = 0
|
||||
end
|
||||
end
|
||||
|
||||
def track_changed(name)
|
||||
@current_song_label.value = File.basename(name)
|
||||
end
|
||||
|
||||
def volume_changed(float)
|
||||
@current_volume_label.value = "#{(float.round(1) * 100.0).round}%"
|
||||
end
|
||||
|
||||
def randomizer_changed(boolean)
|
||||
if boolean
|
||||
push_state(Randomizer) unless @clock.active?
|
||||
else
|
||||
pop_state if current_state.is_a?(Randomizer)
|
||||
end
|
||||
end
|
||||
|
||||
class Mouse
|
||||
def initialize(window)
|
||||
@window = window
|
||||
@last_moved = 0
|
||||
|
||||
@last_position = CyberarmEngine::Vector.new(@window.mouse_x, @window.mouse_y)
|
||||
end
|
||||
|
||||
def update
|
||||
position = CyberarmEngine::Vector.new(@window.mouse_x, @window.mouse_y)
|
||||
|
||||
if @last_position != position
|
||||
@last_position = position
|
||||
@last_moved = Gosu.milliseconds
|
||||
end
|
||||
end
|
||||
|
||||
def button_down(id)
|
||||
case id
|
||||
when Gosu::MS_LEFT, Gosu::MS_MIDDLE, Gosu::MS_RIGHT
|
||||
@last_moved = Gosu.milliseconds
|
||||
end
|
||||
end
|
||||
|
||||
def last_moved
|
||||
(Gosu.milliseconds - @last_moved) / 1000.0
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -42,7 +42,7 @@ module TAC
|
||||
|
||||
flow(width: 1.0, margin_bottom: 20) do
|
||||
@role_name = edit_line "", placeholder: "Add role", width: 0.9
|
||||
button get_image("#{TAC::ROOT_PATH}/media/icons/plus.png"), image_width: 0.1 do
|
||||
button get_image("#{TAC::ROOT_PATH}/media/icons/plus.png"), image_width: 0.1, tip: "Add role" do
|
||||
if @role_name.value.strip.length.positive?
|
||||
@roles.push(@role_name.value.strip)
|
||||
@role_name.value = ""
|
||||
@@ -61,7 +61,7 @@ module TAC
|
||||
|
||||
flow(width: 1.0, margin_bottom: 20) do
|
||||
@roster_name = edit_line "", placeholder: "Add name", width: 0.9
|
||||
button get_image("#{TAC::ROOT_PATH}/media/icons/plus.png"), image_width: 0.1 do
|
||||
button get_image("#{TAC::ROOT_PATH}/media/icons/plus.png"), image_width: 0.1, tip: "Add name" do
|
||||
if @roster_name.value.strip.length.positive?
|
||||
@roster.push(@roster_name.value.strip)
|
||||
@roster_name.value = ""
|
||||
@@ -96,7 +96,7 @@ module TAC
|
||||
background i.even? ? 0xff_007000 : 0xff_006000
|
||||
|
||||
tagline name, width: 0.9
|
||||
button "<b>X</b>", width: 0.1, text_size: 18, **THEME_DANGER_BUTTON do
|
||||
button get_image("#{TAC::ROOT_PATH}/media/icons/trashcan.png"), image_width: 0.1, tip: "Remove role", **THEME_DANGER_BUTTON do
|
||||
@roles.delete(name)
|
||||
populate_roles
|
||||
end
|
||||
@@ -112,7 +112,7 @@ module TAC
|
||||
background i.even? ? 0xff_007000 : 0xff_006000
|
||||
|
||||
tagline name, width: 0.9
|
||||
button "<b>X</b>", width: 0.1, text_size: 18, **THEME_DANGER_BUTTON do
|
||||
button get_image("#{TAC::ROOT_PATH}/media/icons/trashcan.png"), image_width: 0.1, tip: "Remove name", **THEME_DANGER_BUTTON do
|
||||
@roster.delete(name)
|
||||
populate_roster
|
||||
end
|
||||
|
||||
56
lib/pages/game_clock.rb
Normal file
56
lib/pages/game_clock.rb
Normal file
@@ -0,0 +1,56 @@
|
||||
module TAC
|
||||
class Pages
|
||||
class GameClock < Page
|
||||
def setup
|
||||
header_bar("Game Clock")
|
||||
|
||||
body.clear do
|
||||
flow(width: 1.0, height: 1.0) do
|
||||
@command_options = flow(width: 1.0) do
|
||||
stack(width: 0.3) do
|
||||
end
|
||||
|
||||
stack(width: 0.4) do
|
||||
banner "Choose Mode", width: 1.0, text_align: :center
|
||||
title "Local", width: 1.0, text_align: :center
|
||||
|
||||
button "Game Clock", width: 1.0 do
|
||||
push_state(PracticeGameClock::View)
|
||||
|
||||
window.fullscreen = true
|
||||
end
|
||||
|
||||
button "Dual Screen Game Clock", width: 1.0 do
|
||||
# Spawn game clock window
|
||||
$clock_pid = Process.spawn(
|
||||
RbConfig.ruby,
|
||||
"#{ROOT_PATH}/timecrafters_configuration_tool.rb",
|
||||
"--game-clock-remote-display"
|
||||
)
|
||||
|
||||
|
||||
# switch to remote control
|
||||
push_state(PracticeGameClock::RemoteControl::NetConnect)
|
||||
end
|
||||
|
||||
title "Remote", width: 1.0, text_align: :center, margin_top: 32
|
||||
button "Game Clock Display", width: 1.0 do
|
||||
push_state(PracticeGameClock::View, remote_control_mode: true)
|
||||
|
||||
window.fullscreen = true
|
||||
end
|
||||
|
||||
button "Game Clock Remote Control", width: 1.0 do
|
||||
push_state(PracticeGameClock::RemoteControl::NetConnect)
|
||||
end
|
||||
end
|
||||
|
||||
stack(width: 0.3) do
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -2,6 +2,8 @@ module TAC
|
||||
class States
|
||||
class Boot < CyberarmEngine::GuiState
|
||||
def setup
|
||||
window.show_cursor = true
|
||||
|
||||
stack width: 1.0, height: 1.0 do
|
||||
background [TAC::Palette::TIMECRAFTERS_PRIMARY, TAC::Palette::TIMECRAFTERS_SECONDARY, TAC::Palette::TIMECRAFTERS_TERTIARY, TAC::Palette::TIMECRAFTERS_PRIMARY]
|
||||
end
|
||||
|
||||
@@ -3,6 +3,8 @@ class Editor < CyberarmEngine::GuiState
|
||||
attr_reader :header_bar, :header_bar_label, :navigation, :content, :menu_bar, :status_bar, :body
|
||||
|
||||
def setup
|
||||
window.show_cursor = true
|
||||
|
||||
@window_width = 0
|
||||
@window_height = 0
|
||||
|
||||
@@ -65,10 +67,6 @@ class Editor < CyberarmEngine::GuiState
|
||||
page(TAC::Pages::TACNET)
|
||||
end
|
||||
|
||||
button get_image("#{TAC::ROOT_PATH}/media/icons/right.png"), margin: 4, tip: "Simulator", image_width: 1.0 do
|
||||
page(TAC::Pages::Simulator)
|
||||
end
|
||||
|
||||
button get_image("#{TAC::ROOT_PATH}/media/icons/gear.png"), margin: 4, tip: "Configurations", image_width: 1.0 do
|
||||
page(TAC::Pages::Configurations)
|
||||
end
|
||||
@@ -81,6 +79,15 @@ class Editor < CyberarmEngine::GuiState
|
||||
page(TAC::Pages::Search)
|
||||
end
|
||||
|
||||
stack(margin_left: 4, width: 1.0, margin_right: 4) do
|
||||
background 0xff_444444
|
||||
para "Tools", width: 1.0, text_align: :center
|
||||
end
|
||||
|
||||
button get_image("#{TAC::ROOT_PATH}/media/icons/right.png"), margin: 4, tip: "Simulator", image_width: 1.0 do
|
||||
page(TAC::Pages::Simulator)
|
||||
end
|
||||
|
||||
button get_image("#{TAC::ROOT_PATH}/media/icons/joystickLeft.png"), margin: 4, tip: "Field Planner", image_width: 1.0 do
|
||||
page(TAC::Pages::FieldPlanner)
|
||||
end
|
||||
@@ -88,6 +95,14 @@ class Editor < CyberarmEngine::GuiState
|
||||
button get_image("#{TAC::ROOT_PATH}/media/icons/massiveMultiplayer.png"), margin: 4, tip: "Drive Team Rotation Generator", image_width: 1.0 do
|
||||
page(TAC::Pages::DriveTeamRotationGenerator)
|
||||
end
|
||||
|
||||
button get_image("#{TAC::ROOT_PATH}/media/icons/custom_stopWatch.png"), margin: 4, tip: "Game Clock", image_width: 1.0 do
|
||||
page(TAC::Pages::GameClock)
|
||||
end
|
||||
|
||||
button get_image("#{TAC::ROOT_PATH}/media/icons/power.png"), margin: 4, tip: "Exit", image_width: 1.0, **TAC::THEME_DANGER_BUTTON do
|
||||
window.close
|
||||
end
|
||||
end
|
||||
|
||||
@content = stack(width: window.width - @navigation.style.width, height: 1.0) do
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
module TAC
|
||||
NAME = "TimeCrafters Configuration Tool"
|
||||
VERSION = "0.4.2"
|
||||
VERSION = "0.5.1"
|
||||
RELEASE_NAME = "Beta"
|
||||
end
|
||||
@@ -1,6 +1,7 @@
|
||||
module TAC
|
||||
class Window < CyberarmEngine::Window
|
||||
attr_reader :backend, :notification_manager
|
||||
|
||||
def initialize(**args)
|
||||
super(**args)
|
||||
|
||||
@@ -8,8 +9,12 @@ module TAC
|
||||
@backend = Backend.new
|
||||
@notification_manager = GosuNotifications::NotificationManager.new(window: self, edge: :bottom)
|
||||
|
||||
if ARGV.join.include?("--game-clock-remote-display")
|
||||
push_state(PracticeGameClock::View, remote_control_mode: true)
|
||||
else
|
||||
push_state(TAC::States::Boot)
|
||||
end
|
||||
end
|
||||
|
||||
def draw
|
||||
super
|
||||
@@ -24,10 +29,6 @@ module TAC
|
||||
@notification_manager.update
|
||||
end
|
||||
|
||||
def needs_cursor?
|
||||
true
|
||||
end
|
||||
|
||||
def toast(title, message = nil)
|
||||
@notification_manager.create_notification(
|
||||
priority: GosuNotifications::Notification::PRIORITY_HIGH,
|
||||
|
||||
BIN
media/background.png
Normal file
BIN
media/background.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 134 KiB |
6244
media/background.svg
Normal file
6244
media/background.svg
Normal file
File diff suppressed because it is too large
Load Diff
|
After Width: | Height: | Size: 231 KiB |
BIN
media/icons/custom_stopWatch.png
Normal file
BIN
media/icons/custom_stopWatch.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 2.1 KiB |
117
media/icons/custom_stopWatch.svg
Normal file
117
media/icons/custom_stopWatch.svg
Normal file
@@ -0,0 +1,117 @@
|
||||
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
|
||||
<!-- Created with Inkscape (http://www.inkscape.org/) -->
|
||||
|
||||
<svg
|
||||
width="100"
|
||||
height="100"
|
||||
viewBox="0 0 100 100"
|
||||
version="1.1"
|
||||
id="svg5"
|
||||
inkscape:export-filename="/home/cyberarm/Code/timecrafters_configuration_tool_desktop/media/icons/custom_stopWatch.png"
|
||||
inkscape:export-xdpi="96"
|
||||
inkscape:export-ydpi="96"
|
||||
inkscape:version="1.1.1 (3bf5ae0d25, 2021-09-20)"
|
||||
sodipodi:docname="custom_stopWatch.svg"
|
||||
xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape"
|
||||
xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd"
|
||||
xmlns="http://www.w3.org/2000/svg"
|
||||
xmlns:svg="http://www.w3.org/2000/svg">
|
||||
<sodipodi:namedview
|
||||
id="namedview7"
|
||||
pagecolor="#dcdcdc"
|
||||
bordercolor="#666666"
|
||||
borderopacity="1.0"
|
||||
inkscape:pageshadow="2"
|
||||
inkscape:pageopacity="0"
|
||||
inkscape:pagecheckerboard="0"
|
||||
inkscape:document-units="px"
|
||||
showgrid="true"
|
||||
inkscape:showpageshadow="false"
|
||||
borderlayer="true"
|
||||
inkscape:snap-bbox="true"
|
||||
inkscape:snap-bbox-midpoints="true"
|
||||
inkscape:bbox-nodes="true"
|
||||
inkscape:zoom="4"
|
||||
inkscape:cx="-12.625"
|
||||
inkscape:cy="52.625"
|
||||
inkscape:window-width="1920"
|
||||
inkscape:window-height="1011"
|
||||
inkscape:window-x="0"
|
||||
inkscape:window-y="0"
|
||||
inkscape:window-maximized="1"
|
||||
inkscape:current-layer="layer1">
|
||||
<inkscape:grid
|
||||
type="xygrid"
|
||||
id="grid824" />
|
||||
</sodipodi:namedview>
|
||||
<defs
|
||||
id="defs2" />
|
||||
<g
|
||||
inkscape:label="Layer 1"
|
||||
inkscape:groupmode="layer"
|
||||
id="layer1">
|
||||
<rect
|
||||
style="fill:#ffffff;fill-opacity:0.98396;stroke:none;stroke-width:2;stroke-miterlimit:4;stroke-dasharray:none"
|
||||
id="rect3345"
|
||||
width="20"
|
||||
height="6"
|
||||
x="40"
|
||||
y="7"
|
||||
ry="1" />
|
||||
<path
|
||||
id="path848"
|
||||
style="fill:#ffffff;fill-opacity:0.98396;stroke-width:2"
|
||||
d="M 50 15 A 35 35 0 0 0 15 50 A 35 35 0 0 0 50 85 A 35 35 0 0 0 85 50 A 35 35 0 0 0 50 15 z M 50 25 A 25.000003 25.000003 0 0 1 75 50 A 25.000003 25.000003 0 0 1 50 75 A 25.000003 25.000003 0 0 1 25 50 A 25.000003 25.000003 0 0 1 50 25 z " />
|
||||
<circle
|
||||
style="fill:#ffffff;fill-opacity:0.98396;stroke-width:2"
|
||||
id="path1762"
|
||||
cx="50"
|
||||
cy="50"
|
||||
r="2" />
|
||||
<path
|
||||
style="fill:none;stroke:#ffffff;stroke-width:2;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1;stroke-miterlimit:4;stroke-dasharray:none"
|
||||
d="M 50,50 60,30"
|
||||
id="path2248"
|
||||
sodipodi:nodetypes="cc" />
|
||||
<path
|
||||
style="fill:none;stroke:#ffffff;stroke-width:4;stroke-linecap:butt;stroke-linejoin:miter;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1"
|
||||
d="m 50,26 v 9"
|
||||
id="path2778"
|
||||
sodipodi:nodetypes="cc" />
|
||||
<path
|
||||
style="fill:none;stroke:#ffffff;stroke-width:4;stroke-linecap:butt;stroke-linejoin:miter;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1"
|
||||
d="m 50,65 v 9"
|
||||
id="path2778-0"
|
||||
sodipodi:nodetypes="cc" />
|
||||
<path
|
||||
style="fill:none;stroke:#ffffff;stroke-width:4;stroke-linecap:butt;stroke-linejoin:miter;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1"
|
||||
d="M 74,50 H 65"
|
||||
id="path2778-9"
|
||||
sodipodi:nodetypes="cc" />
|
||||
<path
|
||||
style="fill:none;stroke:#ffffff;stroke-width:4;stroke-linecap:butt;stroke-linejoin:miter;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1"
|
||||
d="M 35,50 H 26"
|
||||
id="path2778-0-3"
|
||||
sodipodi:nodetypes="cc" />
|
||||
<path
|
||||
style="fill:none;stroke:#ffffff;stroke-width:4;stroke-linecap:butt;stroke-linejoin:miter;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1"
|
||||
d="m 66.970563,33.029437 -6.363961,6.363961"
|
||||
id="path2778-6"
|
||||
sodipodi:nodetypes="cc" />
|
||||
<path
|
||||
style="fill:none;stroke:#ffffff;stroke-width:4;stroke-linecap:butt;stroke-linejoin:miter;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1"
|
||||
d="m 39.393398,60.606602 -6.363961,6.363961"
|
||||
id="path2778-0-0"
|
||||
sodipodi:nodetypes="cc" />
|
||||
<path
|
||||
style="fill:none;stroke:#ffffff;stroke-width:4;stroke-linecap:butt;stroke-linejoin:miter;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1"
|
||||
d="M 66.970563,66.970563 60.606602,60.606602"
|
||||
id="path2778-9-6"
|
||||
sodipodi:nodetypes="cc" />
|
||||
<path
|
||||
style="fill:none;stroke:#ffffff;stroke-width:4;stroke-linecap:butt;stroke-linejoin:miter;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1"
|
||||
d="M 39.393398,39.393398 33.029437,33.029437"
|
||||
id="path2778-0-3-2"
|
||||
sodipodi:nodetypes="cc" />
|
||||
</g>
|
||||
</svg>
|
||||
|
After Width: | Height: | Size: 4.6 KiB |
0
media/music/.gitkeep
Normal file
0
media/music/.gitkeep
Normal file
BIN
media/openclipart_ducky.png
Normal file
BIN
media/openclipart_ducky.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 12 KiB |
0
media/particles/.gitkeep
Normal file
0
media/particles/.gitkeep
Normal file
0
media/sounds/.gitkeep
Normal file
0
media/sounds/.gitkeep
Normal file
@@ -29,6 +29,7 @@ require_relative "lib/pages/presets"
|
||||
require_relative "lib/pages/search"
|
||||
require_relative "lib/pages/field_planner"
|
||||
require_relative "lib/pages/drive_team_rotation_generator"
|
||||
require_relative "lib/pages/game_clock"
|
||||
require_relative "lib/simulator/robot"
|
||||
require_relative "lib/simulator/field"
|
||||
require_relative "lib/simulator/simulation"
|
||||
@@ -50,6 +51,24 @@ require_relative "lib/tacnet/client"
|
||||
require_relative "lib/tacnet/connection"
|
||||
require_relative "lib/tacnet/server"
|
||||
|
||||
require_relative "lib/game_clock/view"
|
||||
require_relative "lib/game_clock/clock"
|
||||
require_relative "lib/game_clock/event_handlers"
|
||||
require_relative "lib/game_clock/clock_controller"
|
||||
require_relative "lib/game_clock/jukebox"
|
||||
require_relative "lib/game_clock/theme"
|
||||
require_relative "lib/game_clock/clock_proxy"
|
||||
require_relative "lib/game_clock/logger"
|
||||
require_relative "lib/game_clock/particle_emitter"
|
||||
require_relative "lib/game_clock/randomizer"
|
||||
require_relative "lib/game_clock/remote_control"
|
||||
require_relative "lib/game_clock/remote_proxy"
|
||||
require_relative "lib/game_clock/net/client"
|
||||
require_relative "lib/game_clock/net/server"
|
||||
require_relative "lib/game_clock/net/connection"
|
||||
require_relative "lib/game_clock/net/packet_handler"
|
||||
require_relative "lib/game_clock/net/packet"
|
||||
|
||||
# Thread.abort_on_exception = true
|
||||
|
||||
USE_REDESIGN = ARGV.include?("--redesign")
|
||||
@@ -58,3 +77,5 @@ BORDERLESS = ARGV.include?("--borderless")
|
||||
if not defined?(Ocra)
|
||||
TAC::Window.new(width: (Gosu.screen_width * 0.8).round, height: (Gosu.screen_height * 0.8).round, resizable: true, borderless: BORDERLESS).show
|
||||
end
|
||||
|
||||
Process.wait($clock_pid) if $clock_pid
|
||||
|
||||
Reference in New Issue
Block a user