mirror of
https://github.com/TimeCrafters/timecrafters_configuration_tool_desktop.git
synced 2025-12-15 21:32:35 +00:00
Removed gosu dependency from Server by adding TACNET.milliseconds method, made tacnet hostname/port editable
This commit is contained in:
@@ -9,7 +9,7 @@ module TAC
|
|||||||
end
|
end
|
||||||
|
|
||||||
def config_changed!
|
def config_changed!
|
||||||
@config.config.updated_at = Time.now
|
@config.configuration.updated_at = Time.now
|
||||||
@config_changed = true
|
@config_changed = true
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
@@ -1,8 +1,8 @@
|
|||||||
module TAC
|
module TAC
|
||||||
class Config
|
class Config
|
||||||
attr_reader :config, :groups
|
attr_reader :configuration, :groups
|
||||||
def initialize
|
def initialize
|
||||||
@config = nil
|
@configuration = nil
|
||||||
@groups = nil
|
@groups = nil
|
||||||
|
|
||||||
parse(File.read(TAC::CONFIG_PATH))
|
parse(File.read(TAC::CONFIG_PATH))
|
||||||
@@ -24,13 +24,13 @@ module TAC
|
|||||||
end
|
end
|
||||||
|
|
||||||
def parse_spec_current(data)
|
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) }
|
@groups = data.dig(:data, :groups).map { |g| Group.from_json(g) }
|
||||||
end
|
end
|
||||||
|
|
||||||
def to_json(*args)
|
def to_json(*args)
|
||||||
{
|
{
|
||||||
config: @config,
|
config: @configuration,
|
||||||
data: {
|
data: {
|
||||||
groups: @groups
|
groups: @groups
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -9,8 +9,8 @@ module TAC
|
|||||||
TIMECRAFTERS_SECONDARY = Gosu::Color.new(0xff_006000)
|
TIMECRAFTERS_SECONDARY = Gosu::Color.new(0xff_006000)
|
||||||
TIMECRAFTERS_TERTIARY = Gosu::Color.new(0xff_00d000)
|
TIMECRAFTERS_TERTIARY = Gosu::Color.new(0xff_00d000)
|
||||||
|
|
||||||
TACNET_PRIMARY = Gosu::Color.new(0xff_000080)
|
TACNET_PRIMARY = Gosu::Color.new(0xff_003f7f)
|
||||||
TACNET_SECONDARY = Gosu::Color.new(0xff_000060)
|
TACNET_SECONDARY = Gosu::Color.new(0xff_007f7f)
|
||||||
|
|
||||||
GROUPS_PRIMARY = Gosu::Color.new(0xff_444444)
|
GROUPS_PRIMARY = Gosu::Color.new(0xff_444444)
|
||||||
GROUPS_SECONDARY = Gosu::Color.new(0xff_444444)
|
GROUPS_SECONDARY = Gosu::Color.new(0xff_444444)
|
||||||
|
|||||||
@@ -47,8 +47,20 @@ module TAC
|
|||||||
|
|
||||||
flow width: 0.399 do
|
flow width: 0.399 do
|
||||||
stack width: 0.5 do
|
stack width: 0.5 do
|
||||||
label "TACNET v#{TACNET::Packet::PROTOCOL_VERSION}", color: TAC::Palette::TACNET_PRIMARY
|
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
|
||||||
@tacnet_ip_address = label "#{TACNET::DEFAULT_HOSTNAME}:#{TACNET::DEFAULT_PORT}", color: TAC::Palette::TACNET_SECONDARY
|
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
|
end
|
||||||
|
|
||||||
stack width: 0.499 do
|
stack width: 0.499 do
|
||||||
@@ -59,7 +71,7 @@ module TAC
|
|||||||
when :connected, :connecting
|
when :connected, :connecting
|
||||||
window.backend.tacnet.close
|
window.backend.tacnet.close
|
||||||
when :not_connected, :connection_error
|
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
|
||||||
end
|
end
|
||||||
button get_image("#{TAC::ROOT_PATH}/media/icons/information.png"), image_width: 18, width: 0.475 do
|
button get_image("#{TAC::ROOT_PATH}/media/icons/information.png"), image_width: 18, width: 0.475 do
|
||||||
|
|||||||
@@ -70,5 +70,9 @@ module TAC
|
|||||||
def gets
|
def gets
|
||||||
@connection.gets if connected?
|
@connection.gets if connected?
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def self.milliseconds
|
||||||
|
Process.clock_gettime(Process::CLOCK_MONOTONIC, :millisecond)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@@ -9,10 +9,10 @@ module TAC
|
|||||||
|
|
||||||
@client = nil
|
@client = nil
|
||||||
|
|
||||||
@last_sync_time = Gosu.milliseconds
|
@last_sync_time = TACNET.milliseconds
|
||||||
@sync_interval = SYNC_INTERVAL
|
@sync_interval = SYNC_INTERVAL
|
||||||
|
|
||||||
@last_heartbeat_sent = Gosu.milliseconds
|
@last_heartbeat_sent = TACNET.milliseconds
|
||||||
@heartbeat_interval = HEARTBEAT_INTERVAL
|
@heartbeat_interval = HEARTBEAT_INTERVAL
|
||||||
|
|
||||||
@connection_handler = proc do
|
@connection_handler = proc do
|
||||||
@@ -33,8 +33,8 @@ module TAC
|
|||||||
log.i(TAG, "Connected to: #{@hostname}:#{@port}")
|
log.i(TAG, "Connected to: #{@hostname}:#{@port}")
|
||||||
|
|
||||||
while @client && @client.connected?
|
while @client && @client.connected?
|
||||||
if Gosu.milliseconds > @last_sync_time + @sync_interval
|
if TACNET.milliseconds > @last_sync_time + @sync_interval
|
||||||
@last_sync_time = Gosu.milliseconds
|
@last_sync_time = TACNET.milliseconds
|
||||||
|
|
||||||
@client.sync(@connection_handler)
|
@client.sync(@connection_handler)
|
||||||
end
|
end
|
||||||
@@ -58,8 +58,8 @@ module TAC
|
|||||||
|
|
||||||
@packet_handler.handle(message) if message
|
@packet_handler.handle(message) if message
|
||||||
|
|
||||||
if Gosu.milliseconds > @last_heartbeat_sent + @heartbeat_interval
|
if TACNET.milliseconds > @last_heartbeat_sent + @heartbeat_interval
|
||||||
@last_heartbeat_sent = Gosu.milliseconds
|
@last_heartbeat_sent = TACNET.milliseconds
|
||||||
|
|
||||||
@client.puts(PacketHandler.packet_heartbeat)
|
@client.puts(PacketHandler.packet_heartbeat)
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -18,10 +18,10 @@ module TAC
|
|||||||
@packets_sent, @packets_received, @client_last_packets_sent, @client_last_packets_received = 0, 0, 0, 0
|
@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
|
@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
|
@sync_interval = SYNC_INTERVAL
|
||||||
|
|
||||||
@last_heartbeat_sent = Gosu.milliseconds
|
@last_heartbeat_sent = TACNET.milliseconds
|
||||||
@heartbeat_interval = HEARTBEAT_INTERVAL
|
@heartbeat_interval = HEARTBEAT_INTERVAL
|
||||||
|
|
||||||
@client_handler_proc = proc do
|
@client_handler_proc = proc do
|
||||||
@@ -80,8 +80,8 @@ module TAC
|
|||||||
|
|
||||||
Thread.new do
|
Thread.new do
|
||||||
while @active_client && @active_client.connected?
|
while @active_client && @active_client.connected?
|
||||||
if Gosu.milliseconds > @last_sync_time + @sync_interval
|
if TACNET.milliseconds > @last_sync_time + @sync_interval
|
||||||
@last_sync_time = Gosu.milliseconds
|
@last_sync_time = TACNET.milliseconds
|
||||||
|
|
||||||
@active_client.sync(@client_handler_proc)
|
@active_client.sync(@client_handler_proc)
|
||||||
update_stats
|
update_stats
|
||||||
@@ -108,8 +108,8 @@ module TAC
|
|||||||
@packet_handler.handle(message)
|
@packet_handler.handle(message)
|
||||||
end
|
end
|
||||||
|
|
||||||
if Gosu.milliseconds > @last_heartbeat_sent + @heartbeat_interval
|
if TACNET.milliseconds > @last_heartbeat_sent + @heartbeat_interval
|
||||||
@last_heartbeat_sent = Gosu.milliseconds
|
@last_heartbeat_sent = TACNET.milliseconds
|
||||||
|
|
||||||
@active_client.puts(PacketHandler.packet_heartbeat)
|
@active_client.puts(PacketHandler.packet_heartbeat)
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -14,6 +14,9 @@ module TAC
|
|||||||
active: {
|
active: {
|
||||||
background: TAC::Palette::TIMECRAFTERS_TERTIARY
|
background: TAC::Palette::TIMECRAFTERS_TERTIARY
|
||||||
}
|
}
|
||||||
|
},
|
||||||
|
EditLine: {
|
||||||
|
caret_color: Gosu::Color.new(0xff_434343)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
@@ -2,8 +2,6 @@ require "json"
|
|||||||
require "socket"
|
require "socket"
|
||||||
require "securerandom"
|
require "securerandom"
|
||||||
|
|
||||||
require "gosu"
|
|
||||||
|
|
||||||
require_relative "lib/tac"
|
require_relative "lib/tac"
|
||||||
require_relative "lib/logger"
|
require_relative "lib/logger"
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user