diff --git a/lib/backend.rb b/lib/backend.rb index 042ef9d..5411cbe 100644 --- a/lib/backend.rb +++ b/lib/backend.rb @@ -9,7 +9,7 @@ module TAC end def config_changed! - @config.config.updated_at = Time.now + @config.configuration.updated_at = Time.now @config_changed = true end diff --git a/lib/config.rb b/lib/config.rb index 1fc4835..56aa4a6 100644 --- a/lib/config.rb +++ b/lib/config.rb @@ -1,8 +1,8 @@ module TAC class Config - attr_reader :config, :groups + attr_reader :configuration, :groups def initialize - @config = nil + @configuration = nil @groups = nil parse(File.read(TAC::CONFIG_PATH)) @@ -24,13 +24,13 @@ module TAC end def parse_spec_current(data) - @config = Configuration.from_json(data[:config]) + @configuration = Configuration.from_json(data[:config]) @groups = data.dig(:data, :groups).map { |g| Group.from_json(g) } end def to_json(*args) { - config: @config, + config: @configuration, data: { groups: @groups } diff --git a/lib/palette.rb b/lib/palette.rb index 4142907..66488d8 100644 --- a/lib/palette.rb +++ b/lib/palette.rb @@ -9,8 +9,8 @@ module TAC TIMECRAFTERS_SECONDARY = Gosu::Color.new(0xff_006000) TIMECRAFTERS_TERTIARY = Gosu::Color.new(0xff_00d000) - TACNET_PRIMARY = Gosu::Color.new(0xff_000080) - TACNET_SECONDARY = Gosu::Color.new(0xff_000060) + TACNET_PRIMARY = Gosu::Color.new(0xff_003f7f) + TACNET_SECONDARY = Gosu::Color.new(0xff_007f7f) GROUPS_PRIMARY = Gosu::Color.new(0xff_444444) GROUPS_SECONDARY = Gosu::Color.new(0xff_444444) diff --git a/lib/states/editor.rb b/lib/states/editor.rb index 074050e..607c9f7 100644 --- a/lib/states/editor.rb +++ b/lib/states/editor.rb @@ -47,8 +47,20 @@ module TAC flow width: 0.399 do stack width: 0.5 do - label "TACNET v#{TACNET::Packet::PROTOCOL_VERSION}", color: TAC::Palette::TACNET_PRIMARY - @tacnet_ip_address = label "#{TACNET::DEFAULT_HOSTNAME}:#{TACNET::DEFAULT_PORT}", color: TAC::Palette::TACNET_SECONDARY + label "TACNET v#{TACNET::Packet::PROTOCOL_VERSION}", color: TAC::Palette::TACNET_PRIMARY, text_shadow: true, text_shadow_size: 1, text_shadow_color: Gosu::Color::BLACK + flow width: 1.0 do + @tacnet_hostname = edit_line "#{window.backend.config.configuration.hostname}", text_size: 18, width: 0.5, margin_right: 0 + @tacnet_hostname.subscribe(:changed) do |caller, value| + window.backend.config.configuration.hostname = value + window.backend.config_changed! + end + label ":", text_size: 18, margin: 0, padding: 0, padding_top: 3 + @tacnet_port = edit_line "#{window.backend.config.configuration.port}", text_size: 18, width: 0.2, margin_left: 0 + @tacnet_port.subscribe(:changed) do |caller, value| + window.backend.config.configuration.port = Integer(value) + window.backend.config_changed! + end + end end stack width: 0.499 do @@ -59,7 +71,7 @@ module TAC when :connected, :connecting window.backend.tacnet.close when :not_connected, :connection_error - window.backend.tacnet.connect("localhost")#("192.168.1.5") + window.backend.tacnet.connect(@tacnet_hostname.value, @tacnet_port.value) end end button get_image("#{TAC::ROOT_PATH}/media/icons/information.png"), image_width: 18, width: 0.475 do diff --git a/lib/tacnet.rb b/lib/tacnet.rb index 9a384ca..5560d75 100644 --- a/lib/tacnet.rb +++ b/lib/tacnet.rb @@ -70,5 +70,9 @@ module TAC def gets @connection.gets if connected? end + + def self.milliseconds + Process.clock_gettime(Process::CLOCK_MONOTONIC, :millisecond) + end end end \ No newline at end of file diff --git a/lib/tacnet/connection.rb b/lib/tacnet/connection.rb index cfacd18..fc364a0 100644 --- a/lib/tacnet/connection.rb +++ b/lib/tacnet/connection.rb @@ -9,10 +9,10 @@ module TAC @client = nil - @last_sync_time = Gosu.milliseconds + @last_sync_time = TACNET.milliseconds @sync_interval = SYNC_INTERVAL - @last_heartbeat_sent = Gosu.milliseconds + @last_heartbeat_sent = TACNET.milliseconds @heartbeat_interval = HEARTBEAT_INTERVAL @connection_handler = proc do @@ -33,8 +33,8 @@ module TAC log.i(TAG, "Connected to: #{@hostname}:#{@port}") while @client && @client.connected? - if Gosu.milliseconds > @last_sync_time + @sync_interval - @last_sync_time = Gosu.milliseconds + if TACNET.milliseconds > @last_sync_time + @sync_interval + @last_sync_time = TACNET.milliseconds @client.sync(@connection_handler) end @@ -58,8 +58,8 @@ module TAC @packet_handler.handle(message) if message - if Gosu.milliseconds > @last_heartbeat_sent + @heartbeat_interval - @last_heartbeat_sent = Gosu.milliseconds + if TACNET.milliseconds > @last_heartbeat_sent + @heartbeat_interval + @last_heartbeat_sent = TACNET.milliseconds @client.puts(PacketHandler.packet_heartbeat) end diff --git a/lib/tacnet/server.rb b/lib/tacnet/server.rb index 116a323..a174f62 100644 --- a/lib/tacnet/server.rb +++ b/lib/tacnet/server.rb @@ -18,10 +18,10 @@ module TAC @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 + @last_sync_time = TACNET.milliseconds @sync_interval = SYNC_INTERVAL - @last_heartbeat_sent = Gosu.milliseconds + @last_heartbeat_sent = TACNET.milliseconds @heartbeat_interval = HEARTBEAT_INTERVAL @client_handler_proc = proc do @@ -80,8 +80,8 @@ module TAC Thread.new do while @active_client && @active_client.connected? - if Gosu.milliseconds > @last_sync_time + @sync_interval - @last_sync_time = Gosu.milliseconds + if TACNET.milliseconds > @last_sync_time + @sync_interval + @last_sync_time = TACNET.milliseconds @active_client.sync(@client_handler_proc) update_stats @@ -108,8 +108,8 @@ module TAC @packet_handler.handle(message) end - if Gosu.milliseconds > @last_heartbeat_sent + @heartbeat_interval - @last_heartbeat_sent = Gosu.milliseconds + if TACNET.milliseconds > @last_heartbeat_sent + @heartbeat_interval + @last_heartbeat_sent = TACNET.milliseconds @active_client.puts(PacketHandler.packet_heartbeat) end diff --git a/lib/theme.rb b/lib/theme.rb index 7b4f9fb..8decd53 100644 --- a/lib/theme.rb +++ b/lib/theme.rb @@ -14,6 +14,9 @@ module TAC active: { background: TAC::Palette::TIMECRAFTERS_TERTIARY } + }, + EditLine: { + caret_color: Gosu::Color.new(0xff_434343) } } end \ No newline at end of file diff --git a/tacnet_test_server.rb b/tacnet_test_server.rb index ab0773a..134f3e5 100644 --- a/tacnet_test_server.rb +++ b/tacnet_test_server.rb @@ -2,8 +2,6 @@ require "json" require "socket" require "securerandom" -require "gosu" - require_relative "lib/tac" require_relative "lib/logger"