mirror of
https://github.com/cyberarm/i-mic-rts.git
synced 2025-12-15 15:52:34 +00:00
Added Settings
This commit is contained in:
@@ -11,5 +11,4 @@ Building a Command & Conquer style RTS in Ruby
|
|||||||
* `ruby i-mic-rts.rb`
|
* `ruby i-mic-rts.rb`
|
||||||
|
|
||||||
### Options
|
### Options
|
||||||
* `--debug` Jump straight to Game
|
* `--debug-game` Jump straight to Game
|
||||||
* `--fast` Skip intro
|
|
||||||
@@ -8,10 +8,13 @@ end
|
|||||||
|
|
||||||
require "nokogiri"
|
require "nokogiri"
|
||||||
|
|
||||||
|
require "json"
|
||||||
|
|
||||||
require_relative "lib/version"
|
require_relative "lib/version"
|
||||||
require_relative "lib/errors"
|
require_relative "lib/errors"
|
||||||
require_relative "lib/window"
|
require_relative "lib/window"
|
||||||
require_relative "lib/camera"
|
require_relative "lib/camera"
|
||||||
|
require_relative "lib/setting"
|
||||||
|
|
||||||
require_relative "lib/states/boot"
|
require_relative "lib/states/boot"
|
||||||
require_relative "lib/states/game"
|
require_relative "lib/states/game"
|
||||||
@@ -36,4 +39,6 @@ require_relative "lib/director"
|
|||||||
require_relative "lib/player"
|
require_relative "lib/player"
|
||||||
require_relative "lib/connection"
|
require_relative "lib/connection"
|
||||||
|
|
||||||
|
IMICRTS::Setting.setup
|
||||||
|
|
||||||
IMICRTS::Window.new(width: Gosu.screen_width / 4 * 3, height: Gosu.screen_height / 4 * 3, fullscreen: false, resizable: true).show
|
IMICRTS::Window.new(width: Gosu.screen_width / 4 * 3, height: Gosu.screen_height / 4 * 3, fullscreen: false, resizable: true).show
|
||||||
@@ -57,9 +57,9 @@ class IMICRTS
|
|||||||
@players.find { |player| player.id == id }
|
@players.find { |player| player.id == id }
|
||||||
end
|
end
|
||||||
|
|
||||||
def find_path(player:, entity:, goal:, travels_along: :ground, allow_diagonal: true, klass: IMICRTS::Pathfinder::BasePathfinder)
|
def find_path(player:, entity:, goal:, travels_along: :ground, allow_diagonal: Setting.enabled?(:debug_pathfinding_allow_diagonal), klass: IMICRTS::Pathfinder::BasePathfinder)
|
||||||
if klass.cached_path(entity, goal, travels_along)
|
if klass.cached_path(entity, goal, travels_along)
|
||||||
puts "using a cached path!" if true#Setting.enabled?(:debug_mode)
|
puts "using a cached path!" if Setting.enabled?(:debug_mode)
|
||||||
return klass.cached_path(entity, goal, travels_along)
|
return klass.cached_path(entity, goal, travels_along)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
@@ -67,7 +67,7 @@ class IMICRTS
|
|||||||
|
|
||||||
def target=(entity)
|
def target=(entity)
|
||||||
@target = entity
|
@target = entity
|
||||||
@path = @director.find_path(player: @player, entity: self, goal: @target)
|
@pathfinder = @director.find_path(player: @player, entity: self, goal: @target)
|
||||||
end
|
end
|
||||||
|
|
||||||
def hit?(x_or_vector, y = nil)
|
def hit?(x_or_vector, y = nil)
|
||||||
@@ -119,11 +119,21 @@ class IMICRTS
|
|||||||
def draw_gizmos
|
def draw_gizmos
|
||||||
Gosu.draw_rect(@position.x - @radius, @position.y - (@radius + 2), @radius * 2, 2, Gosu::Color::GREEN, ZOrder::ENTITY_GIZMOS)
|
Gosu.draw_rect(@position.x - @radius, @position.y - (@radius + 2), @radius * 2, 2, Gosu::Color::GREEN, ZOrder::ENTITY_GIZMOS)
|
||||||
|
|
||||||
if @path
|
if @pathfinder && Setting.enabled?(:debug_pathfinding) && @pathfinder.path.first
|
||||||
@path.path.each_with_index do |node, i|
|
Gosu.draw_line(
|
||||||
next_node = @path.path.dig(i + 1)
|
@position.x, @position.y, Gosu::Color::RED,
|
||||||
|
@pathfinder.path.first.tile.position.x, @pathfinder.path.first.tile.position.y, Gosu::Color::RED,
|
||||||
|
ZOrder::ENTITY_GIZMOS
|
||||||
|
)
|
||||||
|
|
||||||
|
@pathfinder.path.each_with_index do |node, i|
|
||||||
|
next_node = @pathfinder.path.dig(i + 1)
|
||||||
if next_node
|
if next_node
|
||||||
Gosu.draw_line(node.tile.position.x, node.tile.position.y, Gosu::Color::RED, next_node.tile.position.x, next_node.tile.position.y, Gosu::Color::RED, ZOrder::ENTITY_GIZMOS)
|
Gosu.draw_line(
|
||||||
|
node.tile.position.x, node.tile.position.y, Gosu::Color::RED,
|
||||||
|
next_node.tile.position.x, next_node.tile.position.y, Gosu::Color::RED,
|
||||||
|
ZOrder::ENTITY_GIZMOS
|
||||||
|
)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -4,8 +4,8 @@ class IMICRTS
|
|||||||
Node = Struct.new(:tile, :parent, :distance, :cost)
|
Node = Struct.new(:tile, :parent, :distance, :cost)
|
||||||
CACHE = {}
|
CACHE = {}
|
||||||
|
|
||||||
def self.cached_path(source, goal, travels_along)
|
def self.cached_path(entity, goal, travels_along)
|
||||||
found_path = CACHE.dig(travels_along, source, goal)
|
found_path = CACHE.dig(travels_along, entity, goal)
|
||||||
if found_path
|
if found_path
|
||||||
found_path = nil unless found_path.valid?
|
found_path = nil unless found_path.valid?
|
||||||
end
|
end
|
||||||
@@ -55,7 +55,7 @@ class IMICRTS
|
|||||||
|
|
||||||
@current_node = create_node(position.x, position.y)
|
@current_node = create_node(position.x, position.y)
|
||||||
unless @current_node
|
unless @current_node
|
||||||
puts "Failed to find path!" if true
|
puts "Failed to find path!" if Setting.enabled?(:debug_mode)
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -65,7 +65,7 @@ class IMICRTS
|
|||||||
|
|
||||||
find
|
find
|
||||||
|
|
||||||
Pathfinder.cache_path(self) if @path.size > 0 && false#Setting.enabled?(:cache_paths)
|
self.class.cache_path(self) if @path.size > 0 && true#Setting.enabled?(:debug_cache_paths)
|
||||||
end
|
end
|
||||||
|
|
||||||
# Checks if Map still has all of paths required tiles
|
# Checks if Map still has all of paths required tiles
|
||||||
@@ -87,7 +87,7 @@ class IMICRTS
|
|||||||
end
|
end
|
||||||
|
|
||||||
if @depth >= @max_depth
|
if @depth >= @max_depth
|
||||||
puts "Failed to find path from: #{@source.x}:#{@source.y} (#{@map.grid.dig(@source.x,@source.y).element.class}) to: #{@goal.position.x}:#{@goal.position.y} (#{@goal.element.class}) [#{@depth}/#{@max_depth} depth]" if true#Setting.enabled?(:debug_mode)
|
puts "Failed to find path from: #{@source.x}:#{@source.y} (#{@map.grid.dig(@source.x,@source.y).element.class}) to: #{@goal.position.x}:#{@goal.position.y} (#{@goal.element.class}) [#{@depth}/#{@max_depth} depth]" if Setting.enabled?(:debug_mode)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -112,7 +112,7 @@ class IMICRTS
|
|||||||
@path.reverse!
|
@path.reverse!
|
||||||
|
|
||||||
@seeking = false
|
@seeking = false
|
||||||
puts "Generated path with #{@path.size} steps, #{@created_nodes} nodes created. [#{@depth}/#{@max_depth} depth]" if true#Setting.enabled?(:debug_mode)
|
puts "Generated path with #{@path.size} steps, #{@created_nodes} nodes created. [#{@depth}/#{@max_depth} depth]" if Setting.enabled?(:debug_mode)
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
@@ -7,12 +7,42 @@ class IMICRTS
|
|||||||
background [0xff555555, Gosu::Color::GRAY]
|
background [0xff555555, Gosu::Color::GRAY]
|
||||||
|
|
||||||
label "Settings", text_size: 78, margin: 20
|
label "Settings", text_size: 78, margin: 20
|
||||||
label "Nothing to see here, move along."
|
|
||||||
|
stack(width: 1.0) do
|
||||||
|
background 0xff030303
|
||||||
|
|
||||||
|
label "Debug Settings"
|
||||||
|
@debug_mode = check_box "Debug Mode", checked: Setting.enabled?(:debug_mode)
|
||||||
|
@debug_info_bar = check_box "Show Debug Info Bar", checked: Setting.enabled?(:debug_info_bar)
|
||||||
|
@debug_pathfinding = check_box "Debug Pathfinding", checked: Setting.enabled?(:debug_pathfinding)
|
||||||
|
@debug_pathfinding_allow_diagonal = check_box "Allow Diagonal Paths", checked: Setting.enabled?(:debug_pathfinding_allow_diagonal)
|
||||||
|
end
|
||||||
|
|
||||||
|
button("Save and Close", width: 1.0, margin_top: 20) do
|
||||||
|
if valid_options?
|
||||||
|
save_settings
|
||||||
|
|
||||||
|
push_state(MainMenu)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
button("Back", width: 1.0, margin_top: 20) do
|
button("Back", width: 1.0, margin_top: 20) do
|
||||||
push_state(MainMenu)
|
push_state(MainMenu)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def valid_options?
|
||||||
|
true
|
||||||
|
end
|
||||||
|
|
||||||
|
def save_settings
|
||||||
|
Setting.set(:debug_mode, @debug_mode.value)
|
||||||
|
Setting.set(:debug_info_bar, @debug_info_bar.value)
|
||||||
|
Setting.set(:debug_pathfinding, @debug_pathfinding.value)
|
||||||
|
Setting.set(:debug_pathfinding_allow_diagonal, @debug_pathfinding_allow_diagonal.value)
|
||||||
|
|
||||||
|
Setting.save!
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@@ -18,7 +18,7 @@ class IMICRTS
|
|||||||
stack do
|
stack do
|
||||||
case elements[index]
|
case elements[index]
|
||||||
when :edit_line
|
when :edit_line
|
||||||
edit_line "Novice"
|
edit_line Setting.get(:player_name)
|
||||||
when :button
|
when :button
|
||||||
button item
|
button item
|
||||||
when :toggle_button
|
when :toggle_button
|
||||||
|
|||||||
@@ -6,10 +6,10 @@ class IMICRTS
|
|||||||
@mouse = CyberarmEngine::Vector.new
|
@mouse = CyberarmEngine::Vector.new
|
||||||
|
|
||||||
self.caption = "#{IMICRTS::NAME} (#{IMICRTS::VERSION} #{IMICRTS::VERSION_NAME})"
|
self.caption = "#{IMICRTS::NAME} (#{IMICRTS::VERSION} #{IMICRTS::VERSION_NAME})"
|
||||||
if ARGV.join.include?("--fast")
|
if ARGV.join.include?("--debug-game")
|
||||||
push_state(MainMenu)
|
|
||||||
elsif ARGV.join.include?("--debug")
|
|
||||||
push_state(Game)
|
push_state(Game)
|
||||||
|
elsif Setting.enabled?(:skip_intro)
|
||||||
|
push_state(MainMenu)
|
||||||
else
|
else
|
||||||
push_state(Boot)
|
push_state(Boot)
|
||||||
end
|
end
|
||||||
|
|||||||
Reference in New Issue
Block a user