mirror of
https://github.com/TimeCrafters/timecrafters_configuration_tool_desktop.git
synced 2025-12-16 05:42:35 +00:00
Restructed Simulator to support multiple robots, Field now draws base field without scaling
This commit is contained in:
@@ -21,24 +21,42 @@ module TAC
|
||||
background Gosu::Color.new(0x88_ff8800)
|
||||
|
||||
flow width: 1.0, height: 0.05 do
|
||||
button get_image("#{TAC::ROOT_PATH}/media/icons/right.png"), image_width: THEME_ICON_SIZE, width: 0.49 do
|
||||
button get_image("#{TAC::ROOT_PATH}/media/icons/right.png"), image_width: THEME_ICON_SIZE, width: 0.49, tip: "Run simulation" do
|
||||
begin
|
||||
@simulation = TAC::Simulator::Simulation.new(source_code: @source_code.value, field_container: @field_container)
|
||||
@simulation.__start
|
||||
@simulation.start
|
||||
rescue SyntaxError, NameError, NoMethodError, TypeError, ArgumentError => e
|
||||
puts e.backtrace.reverse.join("\n")
|
||||
puts e
|
||||
push_state(Dialog::AlertDialog, title: "#{e.class}", message: e)
|
||||
end
|
||||
end
|
||||
button get_image("#{TAC::ROOT_PATH}/media/icons/stop.png"), image_width: THEME_ICON_SIZE, width: 0.49 do
|
||||
@simulation.__queue.clear if @simulation
|
||||
button get_image("#{TAC::ROOT_PATH}/media/icons/stop.png"), image_width: THEME_ICON_SIZE, width: 0.49, tip: "Stop simulation" do
|
||||
@simulation.queue.clear if @simulation
|
||||
end
|
||||
button get_image("#{TAC::ROOT_PATH}/media/icons/save.png"), image_width: THEME_ICON_SIZE, width: 0.49, tip: "Save source code" do
|
||||
File.open("#{TAC::ROOT_PATH}/data/simulator.rb", "w") { |f| f.write @source_code.value }
|
||||
end
|
||||
button get_image("#{TAC::ROOT_PATH}/media/icons/save.png"), image_width: THEME_ICON_SIZE, width: 0.49
|
||||
|
||||
@simulation_status = label ""
|
||||
end
|
||||
|
||||
stack width: 1.0, height: 0.95 do
|
||||
@source_code = edit_box "backward 100\nturn 90\nforward 100\nturn -90\nforward 100\nturn -90\nforward 100", width: 1.0, height: 1.0
|
||||
source_code = ""
|
||||
if File.exist?("#{TAC::ROOT_PATH}/data/simulator.rb")
|
||||
source_code = File.read("#{TAC::ROOT_PATH}/data/simulator.rb")
|
||||
else
|
||||
source_code =
|
||||
"robot = create_robot(alliance: :blue, width: 18, depth: 18)
|
||||
robot.backward 100
|
||||
robot.turn 90
|
||||
robot.forward 100
|
||||
robot.turn -90
|
||||
robot.forward 100
|
||||
robot.turn -90
|
||||
robot.forward 100"
|
||||
end
|
||||
@source_code = edit_box source_code, width: 1.0, height: 1.0
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -48,13 +66,13 @@ module TAC
|
||||
super
|
||||
|
||||
Gosu.flush
|
||||
@simulation.__draw if @simulation
|
||||
@simulation.draw if @simulation
|
||||
end
|
||||
|
||||
def update
|
||||
super
|
||||
|
||||
@simulation.__update if @simulation
|
||||
@simulation.update if @simulation
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user