diff --git a/Gemfile b/Gemfile
index 035b77c..0538055 100644
--- a/Gemfile
+++ b/Gemfile
@@ -1,14 +1,15 @@
# frozen_string_literal: true
+
source "https://rubygems.org"
-gem "rake"
-gem "opengl-bindings", require: "opengl"
gem "cyberarm_engine", git: "https://github.com/cyberarm/cyberarm_engine"
-gem "nokogiri", ">= 1.11.0.rc1"
gem "i18n"
+gem "nokogiri", ">= 1.11.0.rc1"
+gem "opengl-bindings", require: "opengl"
+gem "rake"
group(:packaging) do
- gem "releasy", github: "gosu/releasy"
- gem "ocra"
- gem "rubyzip"
gem "excon"
+ gem "ocra"
+ gem "releasy", github: "gosu/releasy"
+ gem "rubyzip"
end
diff --git a/Rakefile b/Rakefile
index 22f6095..876a0be 100644
--- a/Rakefile
+++ b/Rakefile
@@ -1,4 +1,5 @@
# frozen_string_literal: true
+
require "json"
require "tmpdir"
require "fileutils"
@@ -6,7 +7,7 @@ require "fileutils"
require "zip"
require "excon"
require "releasy"
-require 'bundler/setup' # Releasy requires that your application uses bundler.
+require "bundler/setup" # Releasy requires that your application uses bundler.
require_relative "lib/version"
Releasy::Project.new do
diff --git a/_background_menu_test.rb b/_background_menu_test.rb
index 1f787df..d6eebb5 100644
--- a/_background_menu_test.rb
+++ b/_background_menu_test.rb
@@ -1,4 +1,5 @@
# frozen_string_literal: true
+
begin
require_relative "../cyberarm_engine/lib/cyberarm_engine"
rescue LoadError
@@ -13,26 +14,26 @@ class Window < Gosu::Window
@slope = 250
@color_step = 10
@base_color = Gosu::Color.rgb(255, 127, 0)
- @title = CyberarmEngine::Text.new("I-MIC FPS", color: Gosu::Color.rgb(255,127,0), size: 100, x: 0, y: 15, alignment: :center)
- @singleplayer = CyberarmEngine::Text.new("Singleplayer", color: Gosu::Color.rgb(0,127,127), size: 50, x: 0, y: 150, alignment: :center)
+ @title = CyberarmEngine::Text.new("I-MIC FPS", color: Gosu::Color.rgb(255, 127, 0), size: 100, x: 0, y: 15, alignment: :center)
+ @singleplayer = CyberarmEngine::Text.new("Singleplayer", color: Gosu::Color.rgb(0, 127, 127), size: 50, x: 0, y: 150, alignment: :center)
end
def draw
@background ||= Gosu.record(Gosu.screen_width, Gosu.screen_height) do
- ((Gosu.screen_height+@slope)/@size).times do |i|
+ ((Gosu.screen_height + @slope) / @size).times do |i|
fill_quad(
- 0, i*@size,
- 0, @slope+(i*@size),
- Gosu.screen_width/2, (-@slope)+(i*@size),
- Gosu.screen_width/2, i*@size,
- Gosu::Color.rgba(@base_color.red-i*@color_step, @base_color.green-i*@color_step, @base_color.blue-i*@color_step, 200)
+ 0, i * @size,
+ 0, @slope + (i * @size),
+ Gosu.screen_width / 2, (-@slope) + (i * @size),
+ Gosu.screen_width / 2, i * @size,
+ Gosu::Color.rgba(@base_color.red - i * @color_step, @base_color.green - i * @color_step, @base_color.blue - i * @color_step, 200)
)
fill_quad(
- Gosu.screen_width, i*@size,
- Gosu.screen_width, @slope+(i*@size),
- Gosu.screen_width/2, (-@slope)+(i*@size),
- Gosu.screen_width/2, i*@size,
- Gosu::Color.rgba(@base_color.red-i*@color_step, @base_color.green-i*@color_step, @base_color.blue-i*@color_step, 200)
+ Gosu.screen_width, i * @size,
+ Gosu.screen_width, @slope + (i * @size),
+ Gosu.screen_width / 2, (-@slope) + (i * @size),
+ Gosu.screen_width / 2, i * @size,
+ Gosu::Color.rgba(@base_color.red - i * @color_step, @base_color.green - i * @color_step, @base_color.blue - i * @color_step, 200)
)
end
end
@@ -41,8 +42,8 @@ class Window < Gosu::Window
# Box
draw_rect(
- Gosu.screen_width/4, 0,
- Gosu.screen_width/2, Gosu.screen_height,
+ Gosu.screen_width / 4, 0,
+ Gosu.screen_width / 2, Gosu.screen_height,
Gosu::Color.rgba(100, 100, 100, 150)
# Gosu::Color.rgba(@base_color.red+@color_step, @base_color.green+@color_step, @base_color.blue+@color_step, 200)
)
@@ -54,21 +55,21 @@ class Window < Gosu::Window
# Cursor
fill_quad(
mouse_x, mouse_y,
- mouse_x+16, mouse_y+16,
- mouse_x, mouse_y+16,
- mouse_x, mouse_y+16,
+ mouse_x + 16, mouse_y + 16,
+ mouse_x, mouse_y + 16,
+ mouse_x, mouse_y + 16,
Gosu::Color::RED, Float::INFINITY
)
end
def fill_quad(x1, y1, x2, y2, x3, y3, x4, y4, color = Gosu::Color::WHITE, z = 0, mode = :default)
draw_quad(
- x1,y1, color,
- x2,y2, color,
- x3,y3, color,
- x4,y4, color,
+ x1, y1, color,
+ x2, y2, color,
+ x3, y3, color,
+ x4, y4, color,
z, mode
- )
+ )
end
def button_up(id)
@@ -80,4 +81,4 @@ class Window < Gosu::Window
end
end
-Window.new.show
\ No newline at end of file
+Window.new.show
diff --git a/assets/base/door/scripts/door.rb b/assets/base/door/scripts/door.rb
index 3ad7f4b..08a4397 100644
--- a/assets/base/door/scripts/door.rb
+++ b/assets/base/door/scripts/door.rb
@@ -1,10 +1,11 @@
# frozen_string_literal: true
+
origin = entity.position
on.entity_moved do |event|
- if origin.distance3d(event.entity.position) <= 3.0
- entity.position = origin + Vector.up * 2.4
- else
- entity.position = origin
- end
-end
\ No newline at end of file
+ entity.position = if origin.distance3d(event.entity.position) <= 3.0
+ origin + Vector.up * 2.4
+ else
+ origin
+ end
+end
diff --git a/assets/base/power_plant/scripts/power_plant.rb b/assets/base/power_plant/scripts/power_plant.rb
index a226093..8c535b0 100644
--- a/assets/base/power_plant/scripts/power_plant.rb
+++ b/assets/base/power_plant/scripts/power_plant.rb
@@ -1,9 +1,10 @@
# frozen_string_literal: true
+
component(:building)
on.create do |event|
- map.insert_entity("base", "purchase_terminal", event.entity.position + Vector.new(-1.5, 1.5, -4.52), Vector.new(0, 20, 0), data: {team: nil})
+ map.insert_entity("base", "purchase_terminal", event.entity.position + Vector.new(-1.5, 1.5, -4.52), Vector.new(0, 20, 0), data: { team: nil })
map.insert_entity("base", "information_panel", event.entity.position + Vector.new(3, 0, 1), Vector.new(0, -90, 0))
map.insert_entity("base", "door", event.entity.position + Vector.new(0, 0, 6), Vector.new(0, 0, 0))
map.insert_entity("base", "door", event.entity.position + Vector.new(0, 0, 6), Vector.new(0, 180, 0))
-end
\ No newline at end of file
+end
diff --git a/assets/base/shared/scripts/vehicle.rb b/assets/base/shared/scripts/vehicle.rb
index 915b8ba..98d5090 100644
--- a/assets/base/shared/scripts/vehicle.rb
+++ b/assets/base/shared/scripts/vehicle.rb
@@ -1,4 +1,5 @@
# frozen_string_literal: true
+
component(:vehicle) # Generic, Weapon
on.button_down(:interact) do |event|
@@ -8,4 +9,4 @@ on.button_down(:interact) do |event|
# elsif event.player.driving?(event.entity) or event.player.passenger?(event.entity)
# event.player.exit_vehicle
# end
-end
\ No newline at end of file
+end
diff --git a/assets/base/war_factory/scripts/war_factory.rb b/assets/base/war_factory/scripts/war_factory.rb
index 8cdbb0b..cbc5b9a 100644
--- a/assets/base/war_factory/scripts/war_factory.rb
+++ b/assets/base/war_factory/scripts/war_factory.rb
@@ -1,12 +1,13 @@
# frozen_string_literal: true
+
component(:building)
on.create do |event|
- map.insert_entity("base", "purchase_terminal", event.entity.position + Vector.new(6, 1.5, 3), Vector.new(0, -90, 0), data: {team: nil})
+ map.insert_entity("base", "purchase_terminal", event.entity.position + Vector.new(6, 1.5, 3), Vector.new(0, -90, 0), data: { team: nil })
map.insert_entity("base", "information_panel", event.entity.position + Vector.new(0.5, 0, 3), Vector.new(0, 90, 0))
map.insert_entity("base", "door", event.entity.position + Vector.new(3.3, 0, 6), Vector.new(0, 0, 0))
map.insert_entity("base", "door", event.entity.position + Vector.new(3.3, 0, 6), Vector.new(0, 180, 0))
# map.insert_particle_emitter(Vector.new(3.0, 15.379, 0.029), Texture.new(path: ["base", "shared", "particles", "smoke", "smoke.png"]))
# map.insert_particle_emitter(Vector.new(5.0, 15.379, 0.029), Texture.new(path: ["base", "shared", "particles", "smoke", "smoke.png"]))
-end
\ No newline at end of file
+end
diff --git a/i-mic-fps-server.rb b/i-mic-fps-server.rb
index 2ea5225..29210fc 100644
--- a/i-mic-fps-server.rb
+++ b/i-mic-fps-server.rb
@@ -1,10 +1,11 @@
# frozen_string_literal: true
+
IMICFPS_SERVER_MODE = true
require_relative "i-mic-fps"
-director = IMICFPS::Networking::Director.new(mode: :server, hostname: "0.0.0.0", port: 56789, interface: IMICFPS::Networking::MemoryServer)
+director = IMICFPS::Networking::Director.new(mode: :server, hostname: "0.0.0.0", port: 56_789, interface: IMICFPS::Networking::MemoryServer)
director.define_singleton_method(:tick) do |dt|
puts "Ticked: #{dt}"
end
-director.run.join
\ No newline at end of file
+director.run.join
diff --git a/i-mic-fps.rb b/i-mic-fps.rb
index 7f2f4c9..82bea31 100644
--- a/i-mic-fps.rb
+++ b/i-mic-fps.rb
@@ -1,4 +1,5 @@
# frozen_string_literal: true
+
require "fiddle"
require "yaml"
require "json"
@@ -18,8 +19,8 @@ begin
require_relative "../cyberarm_engine/lib/cyberarm_engine/opengl"
rescue LoadError => e
pp e
- require "cyberarm_engine"
- require "cyberarm_engine/opengl"
+ require "cyberarm_engine"
+ require "cyberarm_engine/opengl"
end
Dir.chdir(File.dirname(__FILE__))
@@ -31,16 +32,16 @@ include GLU
def require_all(directory)
files = Dir["#{directory}/**/*.rb"].sort!
- begin
+ loop do
failed = []
first_name_error = nil
files.each do |file|
begin
require_relative file
- rescue NameError => name_error
+ rescue NameError => e
failed << file
- first_name_error ||= name_error
+ first_name_error ||= e
end
end
@@ -49,7 +50,8 @@ def require_all(directory)
else
files = failed
end
- end until( failed.empty? )
+ break if failed.empty?
+ end
end
require_all "lib"
@@ -68,24 +70,22 @@ def prevent_launch?
return [true, "#{m}: Packaging lockfile is present (#{packaging_lockfile})"]
end
- return [false, ""]
+ [false, ""]
end
-unless prevent_launch?[0]
- if ARGV.join.include?("--profile")
- begin
- require "ruby-prof"
- RubyProf.start
- IMICFPS::Window.new.show
- result = RubyProf.stop
- printer = RubyProf::MultiPrinter.new(result)
- printer.print(path: ".", profile: "profile", min_percent: 2)
- rescue LoadError
- puts "ruby-prof not installed!"
- end
- else
+if prevent_launch?[0]
+ puts prevent_launch?[1]
+elsif ARGV.join.include?("--profile")
+ begin
+ require "ruby-prof"
+ RubyProf.start
IMICFPS::Window.new.show
+ result = RubyProf.stop
+ printer = RubyProf::MultiPrinter.new(result)
+ printer.print(path: ".", profile: "profile", min_percent: 2)
+ rescue LoadError
+ puts "ruby-prof not installed!"
end
else
- puts prevent_launch?[1]
+ IMICFPS::Window.new.show
end
diff --git a/lib/camera_controller.rb b/lib/camera_controller.rb
index 241a594..d5b2a57 100644
--- a/lib/camera_controller.rb
+++ b/lib/camera_controller.rb
@@ -1,11 +1,13 @@
# frozen_string_literal: true
+
class IMICFPS
class CameraController
include CommonMethods
attr_accessor :mode, :camera, :entity, :distance, :origin_distance,
:constant_pitch, :mouse_sensitivity, :mouse_captured
- def initialize(mode: :fpv, camera:, entity:)
+
+ def initialize(camera:, entity:, mode: :fpv)
# :fpv - First Person View
# :tpv - Third Person View
@mode = mode
@@ -16,7 +18,8 @@ class IMICFPS
@origin_distance = @distance
@constant_pitch = 20.0
- window.mouse_x, window.mouse_y = window.width / 2, window.height / 2
+ window.mouse_x = window.width / 2
+ window.mouse_y = window.height / 2
@true_mouse = Point.new(window.width / 2, window.height / 2)
@mouse_sensitivity = 20.0 # Less is faster, more is slower
@@ -41,11 +44,11 @@ class IMICFPS
end
def position_camera
- if first_person_view?
- @distance = 0
- else
- @distance = @origin_distance
- end
+ @distance = if first_person_view?
+ 0
+ else
+ @origin_distance
+ end
x_offset = horizontal_distance_from_object * Math.sin(@entity.orientation.y.degrees_to_radians)
z_offset = horizontal_distance_from_object * Math.cos(@entity.orientation.y.degrees_to_radians)
@@ -63,7 +66,7 @@ class IMICFPS
position_camera
if @mouse_captured
- delta = Float(@true_mouse.x - self.mouse_x) / (@mouse_sensitivity * @camera.field_of_view) * 70
+ delta = Float(@true_mouse.x - mouse_x) / (@mouse_sensitivity * @camera.field_of_view) * 70
@camera.orientation.y -= delta
@camera.orientation.y %= 360.0
@@ -73,9 +76,10 @@ class IMICFPS
@entity.orientation.y += delta
@entity.orientation.y %= 360.0
- window.mouse_x = window.width / 2 if window.mouse_x <= 1 || window.mouse_x >= window.width-1
- window.mouse_y = window.height / 2 if window.mouse_y <= 1 || window.mouse_y >= window.height-1
- @true_mouse.x, @true_mouse.y = window.mouse_x, window.mouse_y
+ window.mouse_x = window.width / 2 if window.mouse_x <= 1 || window.mouse_x >= window.width - 1
+ window.mouse_y = window.height / 2 if window.mouse_y <= 1 || window.mouse_y >= window.height - 1
+ @true_mouse.x = window.mouse_x
+ @true_mouse.y = window.mouse_y
end
end
@@ -102,6 +106,7 @@ class IMICFPS
end
end
- def button_up(id); end
+ def button_up(id)
+ end
end
end
diff --git a/lib/common_methods.rb b/lib/common_methods.rb
index c8482f6..9b96c4a 100644
--- a/lib/common_methods.rb
+++ b/lib/common_methods.rb
@@ -1,20 +1,38 @@
# frozen_string_literal: true
+
class IMICFPS
def self.assets_path
- File.expand_path("./../../assets", __FILE__)
+ File.expand_path("../assets", __dir__)
end
module CommonMethods
+ def window
+ $window
+ end
- def window; $window; end
+ def delta_time
+ (Gosu.milliseconds - window.delta_time) / 1000.0
+ end
- def delta_time; (Gosu.milliseconds - window.delta_time) / 1000.0; end
- def button_down?(id); window.button_down?(id); end
+ def button_down?(id)
+ window.button_down?(id)
+ end
- def mouse_x; window.mouse_x; end
- def mouse_y; window.mouse_y; end
- def mouse_x=(int); window.mouse_x = int; end
- def mouse_y=(int); window.mouse_y = int; end
+ def mouse_x
+ window.mouse_x
+ end
+
+ def mouse_y
+ window.mouse_y
+ end
+
+ def mouse_x=(int)
+ window.mouse_x = int
+ end
+
+ def mouse_y=(int)
+ window.mouse_y = int
+ end
def gl(&block)
window.gl do
@@ -25,32 +43,43 @@ class IMICFPS
def formatted_number(number)
string = number.to_s.reverse.scan(/\d{1,3}/).join(",").reverse
- string.insert(0, "-") if number < 0
+ string.insert(0, "-") if number.negative?
- return string
+ string
end
- def control_down?; button_down?(Gosu::KbLeftControl) || button_down?(Gosu::KbRightControl); end
- def shift_down?; button_down?(Gosu::KbLeftShift) || button_down?(Gosu::KbRightShift); end
- def alt_down?; button_down?(Gosu::KbLeftAlt) || button_down?(Gosu::KbRightAlt); end
+ def control_down?
+ button_down?(Gosu::KbLeftControl) || button_down?(Gosu::KbRightControl)
+ end
+
+ def shift_down?
+ button_down?(Gosu::KbLeftShift) || button_down?(Gosu::KbRightShift)
+ end
+
+ def alt_down?
+ button_down?(Gosu::KbLeftAlt) || button_down?(Gosu::KbRightAlt)
+ end
def draw_rect(*args)
window.draw_rect(*args)
end
+
def draw_quad(*args)
window.draw_quad(*args)
end
+
def fill(color = Gosu::Color::WHITE, z = 0)
draw_rect(0, 0, window.width, window.height, color, z)
end
+
def fill_quad(x1, y1, x2, y2, x3, y3, x4, y4, color = Gosu::Color::WHITE, z = 0, mode = :default)
draw_quad(
- x1,y1, color,
- x2,y2, color,
- x3,y3, color,
- x4,y4, color,
+ x1, y1, color,
+ x2, y2, color,
+ x3, y3, color,
+ x4, y4, color,
z, mode
- )
+ )
end
def menu_background(primary_color, accent_color, color_step, transparency, bar_size, slope)
diff --git a/lib/component.rb b/lib/component.rb
index d944832..f44b8c7 100644
--- a/lib/component.rb
+++ b/lib/component.rb
@@ -1,26 +1,27 @@
# frozen_string_literal: true
+
class IMICFPS
class Component
- COMPONENTS = {}
+ @components = {}
def self.get(name)
- COMPONENTS.dig(name)
+ @components[name]
end
def self.inherited(subclass)
- COMPONENTS["__pending"] ||= []
- COMPONENTS["__pending"] << subclass
+ @components["__pending"] ||= []
+ @components["__pending"] << subclass
end
def self.initiate
- return unless COMPONENTS.dig("__pending") # Already setup
+ return unless @components["__pending"] # Already setup
- COMPONENTS["__pending"].each do |klass|
+ @components["__pending"].each do |klass|
component = klass.new
- COMPONENTS[component.name] = component
+ @components[component.name] = component
end
- COMPONENTS.delete("__pending")
+ @components.delete("__pending")
end
def initialize
@@ -31,12 +32,10 @@ class IMICFPS
string = self.class.name.split("::").last
split = string.scan(/[A-Z][a-z]*/)
- component_name = "#{split.map { |s| s.downcase }.join("_")}".to_sym
-
- return component_name
+ split.map(&:downcase).join("_").to_s.to_sym
end
def setup
end
end
-end
\ No newline at end of file
+end
diff --git a/lib/components/building.rb b/lib/components/building.rb
index dcaa7c4..2606c89 100644
--- a/lib/components/building.rb
+++ b/lib/components/building.rb
@@ -1,7 +1,8 @@
# frozen_string_literal: true
+
class IMICFPS
class Components
class Building < Component
end
end
-end
\ No newline at end of file
+end
diff --git a/lib/constants.rb b/lib/constants.rb
index 29e725b..6a193ef 100644
--- a/lib/constants.rb
+++ b/lib/constants.rb
@@ -1,4 +1,5 @@
# frozen_string_literal: true
+
class IMICFPS
GAME_ROOT_PATH = File.expand_path("..", File.dirname(__FILE__))
diff --git a/lib/crosshair.rb b/lib/crosshair.rb
index 5b77bc9..5f7366c 100644
--- a/lib/crosshair.rb
+++ b/lib/crosshair.rb
@@ -1,17 +1,18 @@
# frozen_string_literal: true
+
class IMICFPS
class Crosshair
include CommonMethods
- def initialize(color: Gosu::Color.rgb(255,127,0), size: 10, thickness: 3)
+ def initialize(color: Gosu::Color.rgb(255, 127, 0), size: 10, thickness: 3)
@color = color
@size = size
@thickness = thickness
end
def draw
- draw_rect(window.width/2-@size, (window.height/2-@size)-@thickness/2, @size*2, @thickness, @color, 0, :default)
- draw_rect((window.width/2)-@thickness/2, window.height/2-(@size*2), @thickness, @size*2, @color, 0, :default)
+ draw_rect(window.width / 2 - @size, (window.height / 2 - @size) - @thickness / 2, @size * 2, @thickness, @color, 0, :default)
+ draw_rect((window.width / 2) - @thickness / 2, window.height / 2 - (@size * 2), @thickness, @size * 2, @color, 0, :default)
end
end
-end
\ No newline at end of file
+end
diff --git a/lib/demo.rb b/lib/demo.rb
index 5ccec7d..12cc076 100644
--- a/lib/demo.rb
+++ b/lib/demo.rb
@@ -1,4 +1,5 @@
# frozen_string_literal: true
+
class IMICFPS
class Demo
def initialize(camera:, player:, demo:, mode:)
@@ -7,7 +8,7 @@ class IMICFPS
@demo = demo
@mode = mode
- @index= 0
+ @index = 0
@tick = 0
@changed = false
@@ -55,33 +56,37 @@ class IMICFPS
@tick += 1
end
- def playing?; @mode == :play; end
- def recording?; !playing?; end
+ def playing?
+ @mode == :play
+ end
+
+ def recording?
+ !playing?
+ end
def play
if @data[@index]&.start_with?("tick")
if @tick == @data[@index].split(" ").last.to_i
- @index+=1
+ @index += 1
- until(@data[@index]&.start_with?("tick"))
+ until @data[@index]&.start_with?("tick")
break unless @data[@index]
data = @data[@index].split(" ")
- if data.first == "up"
+ case data.first
+ when "up"
input = InputMapper.get(data.last.to_sym)
key = input.is_a?(Array) ? input.first : input
$window.current_state.button_up(key) if key
- elsif data.first == "down"
+ when "down"
input = InputMapper.get(data.last.to_sym)
key = input.is_a?(Array) ? input.first : input
$window.current_state.button_down(key) if key
- elsif data.first == "mouse"
+ when "mouse"
@camera.orientation.z = data[1].to_f
@player.orientation.y = (data[2].to_f * -1) - 180
- else
- # hmm
end
@index += 1
@@ -106,4 +111,4 @@ class IMICFPS
@index += 1
end
end
-end
\ No newline at end of file
+end
diff --git a/lib/event.rb b/lib/event.rb
index 1cb92cb..dd778e0 100644
--- a/lib/event.rb
+++ b/lib/event.rb
@@ -1,11 +1,14 @@
# frozen_string_literal: true
+
class IMICFPS
class EventHandler
class Event
attr_reader :entity, :context
+
def initialize(entity:, context: nil)
- @entity, @context = entity, context
+ @entity = entity
+ @context = context
end
end
end
-end
\ No newline at end of file
+end
diff --git a/lib/event_handler.rb b/lib/event_handler.rb
index 56c44b6..e6705e6 100644
--- a/lib/event_handler.rb
+++ b/lib/event_handler.rb
@@ -1,4 +1,5 @@
# frozen_string_literal: true
+
class IMICFPS
class EventHandler
@@handlers = {}
@@ -23,7 +24,7 @@ class IMICFPS
end
def self.get(event)
- @@handlers.dig(event)
+ @@handlers[event]
end
def initialize
@@ -37,4 +38,4 @@ class IMICFPS
raise NotImplementedError
end
end
-end
\ No newline at end of file
+end
diff --git a/lib/event_handlers/entity_lifecycle.rb b/lib/event_handlers/entity_lifecycle.rb
index 02ec802..97db21d 100644
--- a/lib/event_handlers/entity_lifecycle.rb
+++ b/lib/event_handlers/entity_lifecycle.rb
@@ -1,9 +1,10 @@
# frozen_string_literal: true
+
class IMICFPS
class EventHandler
class EntityLifeCycle < EventHandler
def handles
- [:create, :move, :destroy]
+ %i[create move destroy]
end
def handle(subscriber, context, *args)
diff --git a/lib/event_handlers/entity_moved.rb b/lib/event_handlers/entity_moved.rb
index f9778d8..b6ecc93 100644
--- a/lib/event_handlers/entity_moved.rb
+++ b/lib/event_handlers/entity_moved.rb
@@ -1,4 +1,5 @@
# frozen_string_literal: true
+
class IMICFPS
class EventHandler
class EntityMoved < EventHandler
@@ -6,11 +7,11 @@ class IMICFPS
[:entity_moved]
end
- def handle(subscriber, context, *args)
+ def handle(subscriber, _context, *args)
event = EventHandler::Event.new(entity: args.first.first)
subscriber.trigger(event)
end
end
end
-end
\ No newline at end of file
+end
diff --git a/lib/event_handlers/input.rb b/lib/event_handlers/input.rb
index 94d8925..1854243 100644
--- a/lib/event_handlers/input.rb
+++ b/lib/event_handlers/input.rb
@@ -1,9 +1,10 @@
# frozen_string_literal: true
+
class IMICFPS
class EventHandler
class Input < EventHandler
def handles
- [:button_down, :button_up]
+ %i[button_down button_up]
end
def handle(subscriber, context, *args)
@@ -14,12 +15,10 @@ class IMICFPS
if action.is_a?(Numeric) && action == key
subscriber.trigger(event)
- else
- if InputMapper.get(action) == key
- subscriber.trigger(event)
- end
+ elsif InputMapper.get(action) == key
+ subscriber.trigger(event)
end
end
end
end
-end
\ No newline at end of file
+end
diff --git a/lib/ext/load_opengl.rb b/lib/ext/load_opengl.rb
index 627a009..e5bb745 100644
--- a/lib/ext/load_opengl.rb
+++ b/lib/ext/load_opengl.rb
@@ -1,4 +1,5 @@
# frozen_string_literal: true
+
case OpenGL.get_platform
when :OPENGL_PLATFORM_WINDOWS
OpenGL.load_lib("opengl32.dll", "C:/Windows/System32")
@@ -29,8 +30,8 @@ when :OPENGL_PLATFORM_LINUX
OpenGL.load_lib("libGL.so", gl_library_path)
GLU.load_lib("libGLU.so", gl_library_path)
else
- raise RuntimeError, "Couldn't find GL libraries"
+ raise "Couldn't find GL libraries"
end
else
- raise RuntimeError, "Unsupported platform."
-end
\ No newline at end of file
+ raise "Unsupported platform."
+end
diff --git a/lib/ext/numeric.rb b/lib/ext/numeric.rb
index 16c4d1b..15c9d2d 100644
--- a/lib/ext/numeric.rb
+++ b/lib/ext/numeric.rb
@@ -1,4 +1,5 @@
# frozen_string_literal: true
+
if RUBY_VERSION < "2.5.0"
puts "-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-"
puts "|NOTICE| Ruby is #{RUBY_VERSION} not 2.5.0+..............................|Notice|"
@@ -12,8 +13,8 @@ if RUBY_VERSION < "2.5.0"
elsif self > max
max
else
- return self
+ self
end
end
end
-end
\ No newline at end of file
+end
diff --git a/lib/game_objects/entities/editor.rb b/lib/game_objects/entities/editor.rb
index acca00a..efe0290 100644
--- a/lib/game_objects/entities/editor.rb
+++ b/lib/game_objects/entities/editor.rb
@@ -1,7 +1,7 @@
# frozen_string_literal: true
+
class IMICFPS
class Editor < Entity
-
attr_accessor :speed
attr_reader :bound_model, :first_person_view
@@ -15,7 +15,6 @@ class IMICFPS
@first_person_view = true
@visible = false
@drag = 0.9
-
end
def update
diff --git a/lib/game_objects/entities/player.rb b/lib/game_objects/entities/player.rb
index 4b115c4..efe5757 100644
--- a/lib/game_objects/entities/player.rb
+++ b/lib/game_objects/entities/player.rb
@@ -1,7 +1,7 @@
# frozen_string_literal: true
+
class IMICFPS
class Player < Entity
-
attr_accessor :speed
attr_reader :name, :bound_model
diff --git a/lib/game_objects/entities/skydome.rb b/lib/game_objects/entities/skydome.rb
index 887a498..72dedcf 100644
--- a/lib/game_objects/entities/skydome.rb
+++ b/lib/game_objects/entities/skydome.rb
@@ -1,4 +1,5 @@
# frozen_string_literal: true
+
class IMICFPS
class Skydome < Entity
def setup
diff --git a/lib/game_objects/entities/terrain.rb b/lib/game_objects/entities/terrain.rb
index 363ba28..5097d24 100644
--- a/lib/game_objects/entities/terrain.rb
+++ b/lib/game_objects/entities/terrain.rb
@@ -1,4 +1,5 @@
# frozen_string_literal: true
+
class IMICFPS
class Terrain < Entity
end
diff --git a/lib/game_objects/entity.rb b/lib/game_objects/entity.rb
index 307b5a7..5fa68a7 100644
--- a/lib/game_objects/entity.rb
+++ b/lib/game_objects/entity.rb
@@ -1,14 +1,12 @@
# frozen_string_literal: true
+
class IMICFPS
-
-
# A game object is any renderable thing
class Entity
include CommonMethods
- attr_accessor :visible, :renderable, :backface_culling
- attr_accessor :position, :orientation, :scale, :velocity
- attr_reader :name, :debug_color, :bounding_box, :drag, :camera, :manifest, :model
+ attr_accessor :visible, :renderable, :backface_culling, :position, :orientation, :scale, :velocity, :debug_color
+ attr_reader :name, :bounding_box, :drag, :camera, :manifest, :model
def initialize(manifest:, map_entity: nil, spawnpoint: nil, backface_culling: true, run_scripts: true)
@manifest = manifest
@@ -54,7 +52,7 @@ class IMICFPS
@camera = nil
- return self
+ self
end
def load_scripts
@@ -94,7 +92,6 @@ class IMICFPS
def draw
end
-
def update
unless at_same_position?
Publisher.instance.publish(:entity_moved, nil, self)
@@ -104,10 +101,6 @@ class IMICFPS
@last_position = Vector.new(@position.x, @position.y, @position.z)
end
- def debug_color=(color)
- @debug_color = color
- end
-
def at_same_position?
@position == @last_position
end
diff --git a/lib/game_objects/particle_emitter.rb b/lib/game_objects/particle_emitter.rb
index a15a3a7..8cc4cc8 100644
--- a/lib/game_objects/particle_emitter.rb
+++ b/lib/game_objects/particle_emitter.rb
@@ -1,4 +1,5 @@
# frozen_string_literal: true
+
class IMICFPS
def initialize(position:, image:, interval: 1_500, time_to_live: 3_000, max_particles: 500)
end
@@ -8,4 +9,4 @@ class IMICFPS
def update
end
-end
\ No newline at end of file
+end
diff --git a/lib/hud.rb b/lib/hud.rb
index c7db3a5..717bfbe 100644
--- a/lib/hud.rb
+++ b/lib/hud.rb
@@ -1,4 +1,5 @@
# frozen_string_literal: true
+
class IMICFPS
class HUD
def initialize(player)
@@ -7,8 +8,8 @@ class IMICFPS
@health = HealthWidget.new({ player: player })
@chat_history = ChatHistoryWidget.new({ player: player })
@score_board = ScoreBoardWidget.new({ player: player })
- @squad = SquadWidget.new( { player: player } )
- @crosshair = CrosshairWidget.new( { player: player } )
+ @squad = SquadWidget.new({ player: player })
+ @crosshair = CrosshairWidget.new({ player: player })
@hud_elements = [
@ammo,
@@ -17,8 +18,8 @@ class IMICFPS
@chat_history,
@score_board,
@squad,
-
- @crosshair,
+
+ @crosshair
]
end
diff --git a/lib/hud/widget.rb b/lib/hud/widget.rb
index 1bbb8a2..efa9322 100644
--- a/lib/hud/widget.rb
+++ b/lib/hud/widget.rb
@@ -1,4 +1,5 @@
# frozen_string_literal: true
+
class IMICFPS
class HUD
class Widget
@@ -24,6 +25,7 @@ class IMICFPS
end
attr_reader :options
+
def initialize(options = {})
@options = options
@player = options[:player]
@@ -41,4 +43,4 @@ class IMICFPS
end
end
end
-end
\ No newline at end of file
+end
diff --git a/lib/hud/widgets/ammo.rb b/lib/hud/widgets/ammo.rb
index 2267792..499c99d 100644
--- a/lib/hud/widgets/ammo.rb
+++ b/lib/hud/widgets/ammo.rb
@@ -1,4 +1,5 @@
# frozen_string_literal: true
+
class IMICFPS
class HUD
class AmmoWidget < HUD::Widget
@@ -18,7 +19,7 @@ class IMICFPS
def update
if (Gosu.milliseconds / 1000.0) % 1.0 >= 0.9
- random = "#{rand(0..199)}".rjust(3, "0")
+ random = rand(0..199).to_s.rjust(3, "0")
@text.text = "#{random}/999"
end
@@ -27,4 +28,4 @@ class IMICFPS
end
end
end
-end
\ No newline at end of file
+end
diff --git a/lib/hud/widgets/chat_history.rb b/lib/hud/widgets/chat_history.rb
index 89f8fd3..9205d68 100644
--- a/lib/hud/widgets/chat_history.rb
+++ b/lib/hud/widgets/chat_history.rb
@@ -1,4 +1,5 @@
# frozen_string_literal: true
+
class IMICFPS
class HUD
class ChatHistoryWidget < HUD::Widget
@@ -36,8 +37,8 @@ class IMICFPS
end
def random_message
- usernames = [
- "Cyberarm", "Cyber", "TankKiller", "DavyJones",
+ usernames = %w[
+ Cyberarm Cyber TankKiller DavyJones
]
entities = [
"Alternate Tank", "Hover Hank", "Helicopter", "Jeep"
@@ -47,12 +48,12 @@ class IMICFPS
"Compass Bridge", "Compass Power Plant", "Gort Power Plant", "Gort Bridge", "Nest"
]
- events = [:spot, :kill, :target, :message]
+ events = %i[spot kill target message]
messages = [
"Need more tanks!",
"I need 351 credits to purchase a tank",
- "I got 300",
+ "I got 300"
]
segments = {
@@ -74,4 +75,4 @@ class IMICFPS
end
end
end
-end
\ No newline at end of file
+end
diff --git a/lib/hud/widgets/crosshair.rb b/lib/hud/widgets/crosshair.rb
index 491f025..f5755cc 100644
--- a/lib/hud/widgets/crosshair.rb
+++ b/lib/hud/widgets/crosshair.rb
@@ -1,4 +1,5 @@
# frozen_string_literal: true
+
class IMICFPS
class HUD
class CrosshairWidget < HUD::Widget
@@ -7,10 +8,10 @@ class IMICFPS
@color = Gosu::Color.new(0x44ffffff)
@image = Gosu::Image.new("#{GAME_ROOT_PATH}/static/crosshairs/crosshair.png")
-
+
@last_changed_time = Gosu.milliseconds
@change_interval = 1_500
-
+
@colors = [0xffffffff, 0xaaffffff, 0x88ffffff, 0x22ffffff]
end
diff --git a/lib/hud/widgets/health.rb b/lib/hud/widgets/health.rb
index 2721a93..6d283d0 100644
--- a/lib/hud/widgets/health.rb
+++ b/lib/hud/widgets/health.rb
@@ -1,4 +1,5 @@
# frozen_string_literal: true
+
class IMICFPS
class HUD
class HealthWidget < HUD::Widget
@@ -26,9 +27,7 @@ class IMICFPS
)
bottom_right = (window.width / 2 - @width / 2) + @width * @health - @slant
- if @width * @health - @slant < @slant
- bottom_right = (window.width / 2 - @width / 2) + @slant
- end
+ bottom_right = (window.width / 2 - @width / 2) + @slant if @width * @health - @slant < @slant
# Current Health
fill_quad(
@@ -41,7 +40,7 @@ class IMICFPS
end
def update
- percentage = "#{(@health * 100).round}".rjust(3, "0")
+ percentage = (@health * 100).round.to_s.rjust(3, "0")
@text.text = "[Health #{percentage}%]"
@text.x = window.width / 2 - @text.width / 2
@text.y = @spacer + Widget.margin + @height / 2 - @text.height / 2
@@ -51,4 +50,4 @@ class IMICFPS
end
end
end
-end
\ No newline at end of file
+end
diff --git a/lib/hud/widgets/radar.rb b/lib/hud/widgets/radar.rb
index 887a37b..7a59dcb 100644
--- a/lib/hud/widgets/radar.rb
+++ b/lib/hud/widgets/radar.rb
@@ -1,4 +1,5 @@
# frozen_string_literal: true
+
class IMICFPS
class HUD
class RadarWidget < HUD::Widget
diff --git a/lib/hud/widgets/score_board.rb b/lib/hud/widgets/score_board.rb
index 51b1ed2..5b8c00e 100644
--- a/lib/hud/widgets/score_board.rb
+++ b/lib/hud/widgets/score_board.rb
@@ -1,9 +1,10 @@
# frozen_string_literal: true
+
class IMICFPS
class HUD
class ScoreBoardWidget < HUD::Widget
def setup
- @usernames = Array("AAAA".."zzzz")#"Adran".."Zebra")
+ @usernames = Array("AAAA".."zzzz") # "Adran".."Zebra")
@text = CyberarmEngine::Text.new(
"",
@@ -36,12 +37,12 @@ class IMICFPS
{
name: "Compass",
credits: 0,
- score: 0,
+ score: 0
},
{
name: "Gort",
credits: 0,
- score: 0,
+ score: 0
}
],
players: []
@@ -56,8 +57,8 @@ class IMICFPS
}
end
- data[:teams][0][:credits] = data[:players].select { |player| player[:team] == 0 }.map { |player| player[:credits] }.reduce(0, :+)
- data[:teams][0][:score] = data[:players].select { |player| player[:team] == 0 }.map { |player| player[:score] }.reduce(0, :+)
+ data[:teams][0][:credits] = data[:players].select { |player| (player[:team]).zero? }.map { |player| player[:credits] }.reduce(0, :+)
+ data[:teams][0][:score] = data[:players].select { |player| (player[:team]).zero? }.map { |player| player[:score] }.reduce(0, :+)
data[:teams][1][:credits] = data[:players].select { |player| player[:team] == 1 }.map { |player| player[:credits] }.reduce(0, :+)
data[:teams][1][:score] = data[:players].select { |player| player[:team] == 1 }.map { |player| player[:score] }.reduce(0, :+)
@@ -65,12 +66,12 @@ class IMICFPS
data[:teams] = data[:teams].sort_by { |team| team[:score] }.reverse
data[:players] = data[:players].sort_by { |player| player[:score] }.reverse
- return data
+ data
end
def set_text
- team_header = [:name, :credits, :score]
- player_header = [:username, :credits, :score]
+ team_header = %i[name credits score]
+ player_header = %i[username credits score]
data = generate_random_data
@@ -78,7 +79,7 @@ class IMICFPS
text += "# Team Credits Score\n"
data[:teams].each_with_index do |team, i|
i += 1
- text += "#{i} #{team[:name]} #{i.even? ? team[:credits] : '-----'} #{team[:score]}\n"
+ text += "#{i} #{team[:name]} #{i.even? ? team[:credits] : '-----'} #{team[:score]}\n"
end
text += "\n"
@@ -93,4 +94,4 @@ class IMICFPS
end
end
end
-end
\ No newline at end of file
+end
diff --git a/lib/hud/widgets/squad.rb b/lib/hud/widgets/squad.rb
index c63ce16..fec5125 100644
--- a/lib/hud/widgets/squad.rb
+++ b/lib/hud/widgets/squad.rb
@@ -1,4 +1,5 @@
# frozen_string_literal: true
+
class IMICFPS
class HUD
class SquadWidget < HUD::Widget
diff --git a/lib/managers/collision_manager.rb b/lib/managers/collision_manager.rb
index e36518c..b4785ee 100644
--- a/lib/managers/collision_manager.rb
+++ b/lib/managers/collision_manager.rb
@@ -1,7 +1,9 @@
# frozen_string_literal: true
+
class IMICFPS
class CollisionManager
attr_reader :map, :collisions
+
def initialize(map:)
@map = map
@collisions = {}
@@ -48,13 +50,13 @@ class IMICFPS
next if entity.manifest.collision_resolution == :static # Only dynamic entities can be resolved
search = @aabb_tree.search(entity.bounding_box)
- if search.size > 0
- search.reject! {|ent| ent == entity || !ent.collidable?}
+ if search.size.positive?
+ search.reject! { |ent| ent == entity || !ent.collidable? }
broadphase[entity] = search
end
end
- broadphase.each do |entity, _collisions|
+ broadphase.each do |_entity, _collisions|
_collisions.each do |ent|
# aabb vs aabb
# next unless entity.bounding_box.intersect?(ent.bounding_box)
@@ -73,15 +75,15 @@ class IMICFPS
# AABBTree on entities is relative to model origin of 0,0,0
def localize_entity_bounding_box(entity, target)
- return entity.bounding_box if target.position == 0 && target.orientation == 0
+ return entity.bounding_box if target.position.zero? && target.orientation.zero?
# "tranform" entity bounding box into target's space
- local = (target.position) # needs tweaking, works well enough for now
+ local = target.position # needs tweaking, works well enough for now
box = entity.bounding_box.clone
box.min -= local
box.max -= local
- return box
+ box
end
def on_ground?(entity) # TODO: Use some form of caching to speed this up
@@ -96,7 +98,7 @@ class IMICFPS
broadphase.detect do |ent|
ray = Ray.new(entity.position - ent.position, Vector.down)
- if ent.model.aabb_tree.search(ray).size > 0
+ if ent.model.aabb_tree.search(ray).size.positive?
on_ground = true
return true
end
@@ -105,7 +107,7 @@ class IMICFPS
break if on_ground
end
- return on_ground
+ on_ground
end
end
end
diff --git a/lib/managers/entity_manager.rb b/lib/managers/entity_manager.rb
index e1cebf1..1793c62 100644
--- a/lib/managers/entity_manager.rb
+++ b/lib/managers/entity_manager.rb
@@ -1,13 +1,16 @@
# frozen_string_literal: true
+
class IMICFPS
module EntityManager # Get included into GameState context
def add_entity(entity)
- @collision_manager.add(entity) if @collision_manager && entity.manifest.collision # Add every entity to collision manager
+ if @collision_manager && entity.manifest.collision
+ @collision_manager.add(entity)
+ end # Add every entity to collision manager
Publisher.instance.publish(:create, nil, entity)
@entities << entity
end
- def insert_entity(package, name, position, orientation, data = {})
+ def insert_entity(package, name, position, orientation, _data = {})
ent = MapParser::Entity.new(package, name, position, orientation, Vector.new(1, 1, 1))
add_entity(IMICFPS::Entity.new(map_entity: ent, manifest: Manifest.new(package: package, name: name)))
end
diff --git a/lib/managers/input_mapper.rb b/lib/managers/input_mapper.rb
index 24a1cba..93f5286 100644
--- a/lib/managers/input_mapper.rb
+++ b/lib/managers/input_mapper.rb
@@ -1,4 +1,5 @@
# frozen_string_literal: true
+
class IMICFPS
class InputMapper
@@keymap = {}
@@ -16,11 +17,12 @@ class IMICFPS
if id_or_action.is_a?(Integer)
@@keys[id_or_action] = true
else
- query = @@keymap.dig(id_or_action)
+ query = @@keymap[id_or_action]
- if query.is_a?(Integer)
- query
- elsif query.is_a?(Array)
+ case query
+ when Integer
+ query
+ when Array
query.each do |key|
@@keys[key] = true
end
@@ -34,11 +36,12 @@ class IMICFPS
if id_or_action.is_a?(Integer)
@@keys[id_or_action] = false
else
- query = @@keymap.dig(id_or_action)
+ query = @@keymap[id_or_action]
- if query.is_a?(Integer)
+ case query
+ when Integer
query
- elsif query.is_a?(Array)
+ when Array
query.each do |key|
@@keys[key] = false
end
@@ -49,12 +52,14 @@ class IMICFPS
end
def self.get(action)
- @@keymap.dig(action)
+ @@keymap[action]
end
def self.set(action, key)
- raise "action must be a symbol" unless action.is_a?(Symbol)
- raise "key must be a whole number or Array of whole numbers, got #{key}" unless key.is_a?(Integer) || key.is_a?(Array)
+ raise "action must be a symbol" unless action.is_a?(Symbol)
+ unless key.is_a?(Integer) || key.is_a?(Array)
+ raise "key must be a whole number or Array of whole numbers, got #{key}"
+ end
warn "InputMapper.set(:#{action}) is already defined as #{@@keymap[action]}" if @@keymap[action]
@@ -74,7 +79,7 @@ class IMICFPS
end
def self.is?(action, query_key)
- keys = @@keymap.dig(action)
+ keys = @@keymap[action]
if keys.is_a?(Array)
keys.include?(query_key)
@@ -85,16 +90,17 @@ class IMICFPS
def self.actions(key)
@@keymap.select do |action, value|
- if value.is_a?(Array)
+ case value
+ when Array
action if value.include?(key)
- else
- action if value == key
+ when key
+ action
end
end.map { |keymap| keymap.first.is_a?(Symbol) ? keymap.first : keymap.first.first }
end
def self.reset_keys
- @@keys.each do |key, value|
+ @@keys.each do |key, _value|
@@keys[key] = false
end
end
@@ -125,4 +131,4 @@ IMICFPS::InputMapper.set(:decrease_mouse_sensitivity, Gosu::KB_NUMPAD_MINUS)
IMICFPS::InputMapper.set(:reset_mouse_sensitivity, Gosu::KB_NUMPAD_MULTIPLY)
IMICFPS::InputMapper.set(:decrease_view_distance, Gosu::MsWheelDown)
-IMICFPS::InputMapper.set(:increase_view_distance, Gosu::MsWheelUp)
\ No newline at end of file
+IMICFPS::InputMapper.set(:increase_view_distance, Gosu::MsWheelUp)
diff --git a/lib/managers/light_manager.rb b/lib/managers/light_manager.rb
index ded252b..4b6048b 100644
--- a/lib/managers/light_manager.rb
+++ b/lib/managers/light_manager.rb
@@ -1,4 +1,5 @@
# frozen_string_literal: true
+
class IMICFPS
module LightManager
MAX_LIGHTS = OpenGL::GL_MAX_LIGHTS
@@ -7,7 +8,7 @@ class IMICFPS
@lights << model
end
- def find_light()
+ def find_light
end
def lights
@@ -15,7 +16,7 @@ class IMICFPS
end
def light_count
- @lights.count+1
+ @lights.count + 1
end
def clear_lights
@@ -24,6 +25,7 @@ class IMICFPS
def available_light
raise "Using to many lights, #{light_count}/#{LightManager::MAX_LIGHTS}" if light_count > LightManager::MAX_LIGHTS
+
puts "OpenGL::GL_LIGHT#{light_count}" if $window.config.get(:debug_options, :stats)
Object.const_get "OpenGL::GL_LIGHT#{light_count}"
end
diff --git a/lib/managers/physics_manager.rb b/lib/managers/physics_manager.rb
index 0277526..6dc31b4 100644
--- a/lib/managers/physics_manager.rb
+++ b/lib/managers/physics_manager.rb
@@ -1,4 +1,5 @@
# frozen_string_literal: true
+
class IMICFPS
class PhysicsManager
def initialize(collision_manager:)
@@ -16,7 +17,7 @@ class IMICFPS
end
def resolve(entity, other)
- entity.velocity.y = other.velocity.y if other.velocity.y < entity.velocity.y && entity.velocity.y < 0
+ entity.velocity.y = other.velocity.y if other.velocity.y < entity.velocity.y && entity.velocity.y.negative?
end
def simulate
@@ -33,9 +34,9 @@ class IMICFPS
entity.velocity.y = 0
else
entity.velocity.y -= @collision_manager.map.gravity * entity.delta_time if entity.manifest.physics
- entity.velocity.y = 0 if entity.velocity.y < 0
+ entity.velocity.y = 0 if entity.velocity.y.negative?
end
end
end
end
-end
\ No newline at end of file
+end
diff --git a/lib/managers/sound_manager.rb b/lib/managers/sound_manager.rb
index c8fbaaa..008a882 100644
--- a/lib/managers/sound_manager.rb
+++ b/lib/managers/sound_manager.rb
@@ -1,11 +1,12 @@
# frozen_string_literal: true
+
class IMICFPS
module SoundManager
extend CyberarmEngine::Common
- MASTERS = {}
- EFFECTS = []
- PLAYLISTS = {}
+ MASTERS = {}.freeze
+ EFFECTS = [].freeze
+ PLAYLISTS = {}.freeze
def self.master_volume
1.0
@@ -20,15 +21,15 @@ class IMICFPS
end
def self.load_master(package)
- return if MASTERS.dig(package)
+ return if MASTERS[package]
- yaml = YAML.load_file( "#{IMICFPS.assets_path}/#{package}/shared/sound/master.yaml" )
+ yaml = YAML.load_file("#{IMICFPS.assets_path}/#{package}/shared/sound/master.yaml")
MASTERS[package] = yaml
end
def self.sound(package, name)
if data = sound_data(package, name.to_s)
- get_sample("#{IMICFPS.assets_path}/#{package}/shared/sound/#{data["path"]}")
+ get_sample("#{IMICFPS.assets_path}/#{package}/shared/sound/#{data['path']}")
else
raise "Missing sound: '#{name}' in package '#{package}'"
end
@@ -36,11 +37,11 @@ class IMICFPS
def self.sound_data(package, name)
load_master(package)
- if master = MASTERS.dig(package)
+ if master = MASTERS[package]
return master["sounds"].find { |s| s["name"] == name }
end
- return nil
+ nil
end
def self.sound_effect(klass, options)
@@ -51,4 +52,4 @@ class IMICFPS
EFFECTS.each { |e| e.update; EFFECTS.delete(e) if e.done? }
end
end
-end
\ No newline at end of file
+end
diff --git a/lib/manifest.rb b/lib/manifest.rb
index 8a7ee8f..af88f48 100644
--- a/lib/manifest.rb
+++ b/lib/manifest.rb
@@ -1,34 +1,35 @@
# frozen_string_literal: true
+
class IMICFPS
class Manifest
attr_reader :name, :model, :collision, :collision_mesh, :collision_resolution, :physics, :scripts, :uses
- def initialize(manifest_file: nil, package: nil, name: nil)
+ def initialize(manifest_file: nil, package: nil, name: nil)
unless manifest_file
raise "Entity package not specified!" unless package
raise "Entity name not specified!" unless name
+
manifest_file = "#{IMICFPS.assets_path}/#{package}/#{name}/manifest.yaml"
end
- raise "No manifest found at: #{manifest_file}" unless File.exist?(manifest_file)
-
+ raise "No manifest found at: #{manifest_file}" unless File.exist?(manifest_file)
@file = manifest_file
parse(manifest_file)
end
def parse(file)
- data = YAML.load(File.read(file))
+ data = YAML.safe_load(File.read(file))
# required
@name = data["name"]
@model = data["model"]
# optional
- @collision = data["collision"] ? data["collision"] : nil
- @collision_mesh = data["collision_mesh"] ? data["collision_mesh"] : nil
+ @collision = data["collision"] || nil
+ @collision_mesh = data["collision_mesh"] || nil
@collision_resolution = data["collision_resolution"] ? data["collision_resolution"].to_sym : :static
- @physics = data["physics"] ? data["physics"] : false
+ @physics = data["physics"] || false
@scripts = data["scripts"] ? parse_scripts(data["scripts"]) : []
@uses = data["uses"] ? parse_dependencies(data["uses"]) : [] # List of entities that this Entity uses
end
@@ -40,7 +41,7 @@ class IMICFPS
if script.start_with?("!")
script = script.sub("!", "")
- path = File.expand_path("../shared/", file_path) + "/scripts/" + script
+ path = "#{File.expand_path('../shared/', file_path)}/scripts/#{script}"
else
path = "#{file_path}/scripts/#{script}"
end
@@ -48,7 +49,7 @@ class IMICFPS
list << Script.new(script, File.read("#{path}.rb"))
end
- return list
+ list
end
def parse_dependencies(list)
@@ -57,7 +58,7 @@ class IMICFPS
dependencies << Dependency.new(item["package"], item["name"])
end
- return dependencies
+ dependencies
end
def file_path
diff --git a/lib/map.rb b/lib/map.rb
index 94647af..e2996ef 100644
--- a/lib/map.rb
+++ b/lib/map.rb
@@ -1,4 +1,5 @@
# frozen_string_literal: true
+
class IMICFPS
class Map
include EntityManager
diff --git a/lib/map_parser.rb b/lib/map_parser.rb
index f7430f8..c0f7bf9 100644
--- a/lib/map_parser.rb
+++ b/lib/map_parser.rb
@@ -1,8 +1,9 @@
# frozen_string_literal: true
+
class IMICFPS
class MapParser
- attr_reader :metadata, :terrain, :skydome, :lights, :entities, :spawnpoints
- attr_reader :assets, :missing_assets
+ attr_reader :metadata, :terrain, :skydome, :lights, :entities, :spawnpoints, :assets, :missing_assets
+
def initialize(map_file:)
@metadata = MapParser::MetaData.new
@terrain = MapParser::Entity.new
diff --git a/lib/networking.rb b/lib/networking.rb
index 48191f9..22783dc 100644
--- a/lib/networking.rb
+++ b/lib/networking.rb
@@ -1,15 +1,16 @@
# frozen_string_literal: true
+
module CyberarmEngine
module Networking
MULTICAST_ADDRESS = "224.0.0.1"
MULTICAST_PORT = 30_000
REMOTE_GAMEHUB = "i-mic.cyberarm.dev"
- REMOTE_GAMEHUB_PORT = 98765
+ REMOTE_GAMEHUB_PORT = 98_765
DEFAULT_SERVER_HOSTNAME = "0.0.0.0"
- DEFAULT_SERVER_PORT = 56789
- DEFAULT_SERVER_QUERY_PORT = 28900
+ DEFAULT_SERVER_PORT = 56_789
+ DEFAULT_SERVER_QUERY_PORT = 28_900
RESERVED_PEER_ID = 0
DEFAULT_PEER_LIMIT = 32
@@ -30,4 +31,4 @@ module CyberarmEngine
def self.handle_lan_multicast
end
end
-end
\ No newline at end of file
+end
diff --git a/lib/networking/backend/channel.rb b/lib/networking/backend/channel.rb
index b3c6009..dadb00d 100644
--- a/lib/networking/backend/channel.rb
+++ b/lib/networking/backend/channel.rb
@@ -1,4 +1,5 @@
# frozen_string_literal: true
+
module CyberarmEngine
module Networking
class Channel
diff --git a/lib/networking/backend/connection.rb b/lib/networking/backend/connection.rb
index 36960a4..3f10f6b 100644
--- a/lib/networking/backend/connection.rb
+++ b/lib/networking/backend/connection.rb
@@ -1,4 +1,5 @@
# frozen_string_literal: true
+
module CyberarmEngine
module Networking
class Connection
@@ -63,9 +64,9 @@ module CyberarmEngine
@peer.total_data_received += data.length
@peer.last_read_time = Networking.milliseconds
- return true
+ true
rescue IO::WaitReadable
- return false
+ false
end
def write(packet:)
diff --git a/lib/networking/backend/packet.rb b/lib/networking/backend/packet.rb
index dea8f9f..98db675 100644
--- a/lib/networking/backend/packet.rb
+++ b/lib/networking/backend/packet.rb
@@ -1,4 +1,5 @@
# frozen_string_literal: true
+
module CyberarmEngine
module Networking
class Packet
diff --git a/lib/networking/backend/packet_handler.rb b/lib/networking/backend/packet_handler.rb
index 9e6d2e8..cfb6e7b 100644
--- a/lib/networking/backend/packet_handler.rb
+++ b/lib/networking/backend/packet_handler.rb
@@ -1,4 +1,5 @@
# frozen_string_literal: true
+
module CyberarmEngine
module Networking
module PacketHandler
diff --git a/lib/networking/backend/packets/control_packet.rb b/lib/networking/backend/packets/control_packet.rb
index 7061d2d..5daea9c 100644
--- a/lib/networking/backend/packets/control_packet.rb
+++ b/lib/networking/backend/packets/control_packet.rb
@@ -1,4 +1,5 @@
# frozen_string_literal: true
+
module CyberarmEngine
module Networking
class ControlPacket
diff --git a/lib/networking/backend/packets/raw_packet.rb b/lib/networking/backend/packets/raw_packet.rb
index 7476925..4fcb64e 100644
--- a/lib/networking/backend/packets/raw_packet.rb
+++ b/lib/networking/backend/packets/raw_packet.rb
@@ -1,4 +1,5 @@
# frozen_string_literal: true
+
module CyberarmEngine
module Networking
class RawPacket
diff --git a/lib/networking/backend/packets/reliable_packet.rb b/lib/networking/backend/packets/reliable_packet.rb
index c947b3b..d8e8abe 100644
--- a/lib/networking/backend/packets/reliable_packet.rb
+++ b/lib/networking/backend/packets/reliable_packet.rb
@@ -1,4 +1,5 @@
# frozen_string_literal: true
+
module CyberarmEngine
module Networking
class ReliablePacket
diff --git a/lib/networking/backend/peer.rb b/lib/networking/backend/peer.rb
index aadffef..9c2c2d1 100644
--- a/lib/networking/backend/peer.rb
+++ b/lib/networking/backend/peer.rb
@@ -1,4 +1,5 @@
# frozen_string_literal: true
+
module CyberarmEngine
module Networking
class Peer
diff --git a/lib/networking/backend/protocol.rb b/lib/networking/backend/protocol.rb
index 5ca06f9..b2460fe 100644
--- a/lib/networking/backend/protocol.rb
+++ b/lib/networking/backend/protocol.rb
@@ -1,4 +1,5 @@
# frozen_string_literal: true
+
module CyberarmEngine
module Networking
module Protocol
diff --git a/lib/networking/backend/server.rb b/lib/networking/backend/server.rb
index 00986ee..aa8fc3a 100644
--- a/lib/networking/backend/server.rb
+++ b/lib/networking/backend/server.rb
@@ -1,4 +1,5 @@
# frozen_string_literal: true
+
module CyberarmEngine
module Networking
class Server
@@ -85,7 +86,7 @@ module CyberarmEngine
end
def update
- while(read)
+ while read
end
# handle write queue
@@ -117,7 +118,7 @@ module CyberarmEngine
)
end
- while(packet = peer.write_queue.shift)
+ while (packet = peer.write_queue.shift)
write(peer: peer, packet: packet)
end
end
diff --git a/lib/networking/connection.rb b/lib/networking/connection.rb
index 0c30502..fa64afe 100644
--- a/lib/networking/connection.rb
+++ b/lib/networking/connection.rb
@@ -1,14 +1,15 @@
# frozen_string_literal: true
+
class IMICFPS
module Networking
class Connection
attr_reader :address, :port
attr_accessor :total_packets_sent, :total_packets_received, :total_data_sent, :total_data_received, :last_read_time, :last_write_time
+
def initialize(address:, port:)
@address = address
@port = port
-
@read_buffer = ReadBuffer.new
@packet_write_queue = []
@@ -39,50 +40,49 @@ class IMICFPS
)
end
- def send_packet( packet )
+ def send_packet(packet)
Packet.splinter(packet).each do |pkt|
@packet_write_queue << pkt
end
end
def update
- while(read)
+ while read
end
write
# puts "#{Networking.milliseconds} Total sent: #{@total_packets_sent} packets, #{@total_data_sent} data"
# puts "#{Networking.milliseconds} Total received: #{@total_packets_received} packets, #{@total_data_received} data"
- @read_buffer.reconstruct_packets.each do |packet, addr_info|
- if packet.peer_id == 0 && packet.type == Protocol::VERIFY_CONNECT
- @peer_id = packet.payload.unpack1("C")
- end
+ @read_buffer.reconstruct_packets.each do |packet, _addr_info|
+ @peer_id = packet.payload.unpack1("C") if packet.peer_id.zero? && packet.type == Protocol::VERIFY_CONNECT
end
- if @peer_id > 0 && Networking.milliseconds - @last_read_time >= Protocol::HEARTBEAT_INTERVAL
+ if @peer_id.positive? && Networking.milliseconds - @last_read_time >= Protocol::HEARTBEAT_INTERVAL
send_packet(Packet.new(peer_id: @peer_id, sequence: 0, type: Protocol::HEARTBEAT, payload: ""))
end
end
def close
- @socket.close if @socket
+ @socket&.close
end
private
+
def read
data, addr = @socket.recvfrom_nonblock(Protocol::MAX_PACKET_SIZE)
- @read_buffer.add(data, addr )
+ @read_buffer.add(data, addr)
@total_packets_received += 1
@total_data_received += data.length
@last_read_time = Networking.milliseconds
- return true
+ true
rescue IO::WaitReadable
- return false
+ false
end
def write
- while(packet = @packet_write_queue.shift)
+ while (packet = @packet_write_queue.shift)
@socket.send(packet.encode, 0, @address, @port)
@total_data_sent += packet.encode.length
@@ -91,4 +91,4 @@ class IMICFPS
end
end
end
-end
\ No newline at end of file
+end
diff --git a/lib/networking/director.rb b/lib/networking/director.rb
index 824a916..58923d0 100644
--- a/lib/networking/director.rb
+++ b/lib/networking/director.rb
@@ -1,4 +1,5 @@
# frozen_string_literal: true
+
class IMICFPS
module Networking
class Director
diff --git a/lib/networking/events.rb b/lib/networking/events.rb
index b9e4a4d..697413c 100644
--- a/lib/networking/events.rb
+++ b/lib/networking/events.rb
@@ -1,4 +1,5 @@
# frozen_string_literal: true
+
class IMICFPS
module Networking
module Events
@@ -9,4 +10,4 @@ class IMICFPS
end
end
end
-end
\ No newline at end of file
+end
diff --git a/lib/networking/packet_handler.rb b/lib/networking/packet_handler.rb
index 7d206c1..f7bf0ac 100644
--- a/lib/networking/packet_handler.rb
+++ b/lib/networking/packet_handler.rb
@@ -1,7 +1,8 @@
# frozen_string_literal: true
+
class IMICFPS
module Networking
class PacketHandler
end
end
-end
\ No newline at end of file
+end
diff --git a/lib/networking/packet_handlers/snapshot.rb b/lib/networking/packet_handlers/snapshot.rb
index cdac7c4..cb9683f 100644
--- a/lib/networking/packet_handlers/snapshot.rb
+++ b/lib/networking/packet_handlers/snapshot.rb
@@ -1,7 +1,8 @@
# frozen_string_literal: true
+
class IMICFPS
module Networking
class SnapshotPacket < CyberarmEngine::Networking::Packet
end
end
-end
\ No newline at end of file
+end
diff --git a/lib/networking/read_buffer.rb b/lib/networking/read_buffer.rb
index 952e9b5..b3d48c7 100644
--- a/lib/networking/read_buffer.rb
+++ b/lib/networking/read_buffer.rb
@@ -1,4 +1,5 @@
# frozen_string_literal: true
+
class IMICFPS
module Networking
class ReadBuffer
@@ -14,10 +15,11 @@ class IMICFPS
pairs = []
@buffer.each do |hash|
- buffer, addr = hash[:buffer], hash[:addr_info]
+ buffer = hash[:buffer]
+ addr = hash[:addr_info]
packet = Packet.from_stream(buffer)
- if true#packet.valid?
+ if true # packet.valid?
pairs << [packet, addr]
@buffer.delete(hash)
else
@@ -26,8 +28,8 @@ class IMICFPS
end
end
- return pairs
+ pairs
end
end
end
-end
\ No newline at end of file
+end
diff --git a/lib/networking/server.rb b/lib/networking/server.rb
index abf0c9b..33e0785 100644
--- a/lib/networking/server.rb
+++ b/lib/networking/server.rb
@@ -1,4 +1,5 @@
# frozen_string_literal: true
+
class IMICFPS
module Networking
class Server < CyberarmEngine::Networking::Server
diff --git a/lib/overlay.rb b/lib/overlay.rb
index 8070491..aa8f172 100644
--- a/lib/overlay.rb
+++ b/lib/overlay.rb
@@ -1,4 +1,5 @@
# frozen_string_literal: true
+
class IMICFPS
class Overlay
include CommonMethods
@@ -13,6 +14,7 @@ class IMICFPS
def draw
return if @text.text.empty?
+
width = @text.markup_width + 8
Gosu.draw_rect(0, 0, width, (@text.height + 4), Gosu::Color.rgba(0, 0, 0, 100))
@@ -30,7 +32,9 @@ class IMICFPS
if window.config.get(:options, :fps)
create_slot "FPS: #{Gosu.fps}"
- create_slot "Frame time: #{(Gosu.milliseconds - window.delta_time).to_s.rjust(3, "0")}ms" if window.config.get(:debug_options, :stats)
+ if window.config.get(:debug_options, :stats)
+ create_slot "Frame time: #{(Gosu.milliseconds - window.delta_time).to_s.rjust(3, '0')}ms"
+ end
end
if window.config.get(:debug_options, :stats)
@@ -49,7 +53,7 @@ class IMICFPS
@text.text = ""
@slots.each_with_index do |slot, i|
@text.text += "#{slot.value} • " unless i == @slots.size - 1
- @text.text += "#{slot.value}" if i == @slots.size - 1
+ @text.text += slot.value.to_s if i == @slots.size - 1
end
end
@@ -57,4 +61,4 @@ class IMICFPS
@slots << Slot.new(string, @text.textobject.text_width(string))
end
end
-end
\ No newline at end of file
+end
diff --git a/lib/publisher.rb b/lib/publisher.rb
index a51f4ad..d650704 100644
--- a/lib/publisher.rb
+++ b/lib/publisher.rb
@@ -1,8 +1,10 @@
# frozen_string_literal: true
+
class IMICFPS
class Publisher
def self.subscribe(subscription)
raise "Expected IMICFPS::Subscription not #{subscription.class}" unless subscription.is_a?(IMICFPS::Subscription)
+
Publisher.instance.add_sub(subscription)
end
@@ -22,13 +24,14 @@ class IMICFPS
def add_sub(subscription)
raise "Expected IMICFPS::Subscription not #{subscription.class}" unless subscription.is_a?(IMICFPS::Subscription)
+
@events[subscription.event] ||= []
@events[subscription.event] << subscription
end
def publish(event, context, *args)
- if subscribers = @events.dig(event)
+ if subscribers = @events[event]
return unless event_handler = EventHandler.get(event)
subscribers.each do |subscriber|
@@ -37,4 +40,4 @@ class IMICFPS
end
end
end
-end
\ No newline at end of file
+end
diff --git a/lib/scene.rb b/lib/scene.rb
index 176f558..e2c1b55 100644
--- a/lib/scene.rb
+++ b/lib/scene.rb
@@ -1,10 +1,11 @@
# frozen_string_literal: true
+
class IMICFPS
class Scene
attr_reader :camera, :entities, :lights
def initialize
- @camera = PerspectiveCamera.new(position: Vector.new, aspect_ratio: $window.aspect_ratio )
+ @camera = PerspectiveCamera.new(position: Vector.new, aspect_ratio: $window.aspect_ratio)
@entities = []
@lights = []
@@ -20,4 +21,4 @@ class IMICFPS
def update(dt)
end
end
-end
\ No newline at end of file
+end
diff --git a/lib/scenes/turn_table.rb b/lib/scenes/turn_table.rb
index b3c04ab..2691504 100644
--- a/lib/scenes/turn_table.rb
+++ b/lib/scenes/turn_table.rb
@@ -1,4 +1,5 @@
# frozen_string_literal: true
+
class IMICFPS
class TurnTableScene < Scene
def setup
@@ -25,7 +26,7 @@ class IMICFPS
"power_plant": 0.025,
"war_factory": 0.03,
"randomish_terrain": 0.004,
- "river_terrain": 0.004,
+ "river_terrain": 0.004
}
choice = options.keys.sample
@@ -45,4 +46,4 @@ class IMICFPS
@entity.orientation.y += 10 * dt
end
end
-end
\ No newline at end of file
+end
diff --git a/lib/scripting.rb b/lib/scripting.rb
index 4e108a9..e347dc0 100644
--- a/lib/scripting.rb
+++ b/lib/scripting.rb
@@ -1,9 +1,10 @@
# frozen_string_literal: true
+
class IMICFPS
module Scripting
def on
# self is a Scripting::SandBox
- Subscription.new(self.entity)
+ Subscription.new(entity)
end
def component(name)
@@ -14,4 +15,4 @@ class IMICFPS
$window.director.map
end
end
-end
\ No newline at end of file
+end
diff --git a/lib/scripting/sandbox.rb b/lib/scripting/sandbox.rb
index 77370f4..380a7c2 100644
--- a/lib/scripting/sandbox.rb
+++ b/lib/scripting/sandbox.rb
@@ -1,4 +1,5 @@
# frozen_string_literal: true
+
class IMICFPS
module Scripting
class SandBox
@@ -10,7 +11,7 @@ class IMICFPS
execute(script.source) if source_safe?(script.source)
end
- def source_safe?(source)
+ def source_safe?(_source)
true # TODO: implement whitelisting/safety checks
end
@@ -18,9 +19,7 @@ class IMICFPS
instance_eval(source)
end
- def entity
- @entity
- end
+ attr_reader :entity
end
end
-end
\ No newline at end of file
+end
diff --git a/lib/scripting/whitelist.rb b/lib/scripting/whitelist.rb
index 62199a5..58053a2 100644
--- a/lib/scripting/whitelist.rb
+++ b/lib/scripting/whitelist.rb
@@ -1,4 +1,5 @@
# frozen_string_literal: true
+
class IMICFPS
module Scripting
CONSTANTS_WHITELIST = [
@@ -7,8 +8,8 @@ class IMICFPS
# Ruby information
RUBY_VERSION, RUBY_ENGINE,
# Local
- Vector, BoundingBox, Ray,
- ]
+ Vector, BoundingBox, Ray
+ ].freeze
METHOD_WHITELIST = [
Subscription.subscribable_events,
@@ -45,16 +46,16 @@ class IMICFPS
:combination, :compact, :compact!, :compare_by_identity, :compare_by_identity?, :concat, :count, :cycle, :default, :default=, :default_proc,
:default_proc=, :delete, :delete_at, :delete_if, :detect, :difference, :dig, :drop, :drop_while, :each, :each_cons, :each_entry, :each_index,
:each_key, :each_pair, :each_slice, :each_value, :each_with_index, :each_with_object, :empty?, :entries, :eql?, :fetch, :fetch_values, :fill,
- :filter, :filter!, :find, :find_all, :find_index, :first, :flat_map, :flatten, :flatten!, :grep, :grep_v, :group_by, :has_key?, :has_value?,
- :hash, :include?, :index, :inject, :insert, :inspect, :invert, :join, :keep_if, :key, :key?, :keys, :last, :lazy, :length, :map, :map!,
- :max, :max_by, :member?, :merge, :merge!, :min, :min_by, :minmax, :minmax_by, :none?, :one?, :pack, :partition, :permutation, :pop, :prepend,
- :product, :push, :rassoc, :reduce, :rehash, :reject, :reject!, :repeated_combination, :repeated_permutation, :replace, :reverse, :reverse!,
- :reverse_each, :rindex, :rotate, :rotate!, :sample, :select, :select!, :shift, :shuffle, :shuffle!, :size, :slice, :slice!, :slice_after, :slice_before,
- :slice_when, :sort, :sort!, :sort_by, :sort_by!, :store, :sum, :take, :take_while, :to_a, :to_ary, :to_h, :to_hash, :to_proc, :to_s, :to_set,
- :transform_keys, :transform_keys!, :transform_values, :transform_values!, :transpose, :union, :uniq, :uniq!, :unshift, :update, :value?, :values,
- :values_at, :zip,
+ :filter, :filter!, :find, :find_all, :find_index, :first, :flat_map, :flatten, :flatten!, :grep, :grep_v, :group_by, :has_key?, :has_value?,
+ :hash, :include?, :index, :inject, :insert, :inspect, :invert, :join, :keep_if, :key, :key?, :keys, :last, :lazy, :length, :map, :map!,
+ :max, :max_by, :member?, :merge, :merge!, :min, :min_by, :minmax, :minmax_by, :none?, :one?, :pack, :partition, :permutation, :pop, :prepend,
+ :product, :push, :rassoc, :reduce, :rehash, :reject, :reject!, :repeated_combination, :repeated_permutation, :replace, :reverse, :reverse!,
+ :reverse_each, :rindex, :rotate, :rotate!, :sample, :select, :select!, :shift, :shuffle, :shuffle!, :size, :slice, :slice!, :slice_after, :slice_before,
+ :slice_when, :sort, :sort!, :sort_by, :sort_by!, :store, :sum, :take, :take_while, :to_a, :to_ary, :to_h, :to_hash, :to_proc, :to_s, :to_set,
+ :transform_keys, :transform_keys!, :transform_values, :transform_values!, :transpose, :union, :uniq, :uniq!, :unshift, :update, :value?, :values,
+ :values_at, :zip,
# Casting
- :to_c, :to_f, :to_i, :to_r, :to_str, :to_ary, :to_h, :to_hash, :to_proc, :to_a, :to_s, :to_sym,
+ :to_c, :to_f, :to_i, :to_r, :to_str, :to_ary, :to_h, :to_hash, :to_proc, :to_a, :to_s, :to_sym
].flatten
end
-end
\ No newline at end of file
+end
diff --git a/lib/sound_effect.rb b/lib/sound_effect.rb
index 6e7a06f..016d3d9 100644
--- a/lib/sound_effect.rb
+++ b/lib/sound_effect.rb
@@ -1,9 +1,12 @@
# frozen_string_literal: true
+
class IMICFPS
class SoundEffect
attr_reader :sound, :options
+
def initialize(options = {})
raise "expected Hash, got #{options.class}" unless options.is_a?(Hash)
+
@options = options
raise "sound not specified!" unless @options[:sound]
@@ -17,4 +20,4 @@ class IMICFPS
def update
end
end
-end
\ No newline at end of file
+end
diff --git a/lib/sound_effects/fade_in.rb b/lib/sound_effects/fade_in.rb
index 803ae94..0a77721 100644
--- a/lib/sound_effects/fade_in.rb
+++ b/lib/sound_effects/fade_in.rb
@@ -1,11 +1,12 @@
# frozen_string_literal: true
+
class IMICFPS
class SoundEffect
class FadeIn < SoundEffect
def setup
@start_time = Gosu.milliseconds
@duration = @options[:duration] # in milliseconds
- @initial_volume = @options[:volume] ? @options[:volume] : 0.0
+ @initial_volume = @options[:volume] || 0.0
@sound = @options[:sound]
raise "duration not specified!" unless @duration
@@ -30,4 +31,4 @@ class IMICFPS
end
end
end
-end
\ No newline at end of file
+end
diff --git a/lib/sound_effects/fade_in_and_out.rb b/lib/sound_effects/fade_in_and_out.rb
index d53d379..2e50e7d 100644
--- a/lib/sound_effects/fade_in_and_out.rb
+++ b/lib/sound_effects/fade_in_and_out.rb
@@ -1,9 +1,10 @@
# frozen_string_literal: true
+
class IMICFPS
class SoundEffect
class FadeInAndOut < FadeIn
def setup
- @hang_time = @options[:hang_time] ? @options[:hang_time] : 0.0
+ @hang_time = @options[:hang_time] || 0.0
super
end
@@ -20,4 +21,4 @@ class IMICFPS
end
end
end
-end
\ No newline at end of file
+end
diff --git a/lib/sound_effects/fade_out.rb b/lib/sound_effects/fade_out.rb
index 0fc36cf..39da6cd 100644
--- a/lib/sound_effects/fade_out.rb
+++ b/lib/sound_effects/fade_out.rb
@@ -1,4 +1,5 @@
# frozen_string_literal: true
+
class IMICFPS
class SoundEffect
class FadeOut < FadeIn
@@ -7,4 +8,4 @@ class IMICFPS
end
end
end
-end
\ No newline at end of file
+end
diff --git a/lib/sound_effects/shield_regen.rb b/lib/sound_effects/shield_regen.rb
index 92a9a44..9c1661c 100644
--- a/lib/sound_effects/shield_regen.rb
+++ b/lib/sound_effects/shield_regen.rb
@@ -1,4 +1,5 @@
# frozen_string_literal: true
+
class IMICFPS
class SoundEffect
class ShieldRegen < SoundEffect
@@ -23,4 +24,4 @@ class IMICFPS
end
end
end
-end
\ No newline at end of file
+end
diff --git a/lib/states/game_state.rb b/lib/states/game_state.rb
index 229bc59..ae9adff 100644
--- a/lib/states/game_state.rb
+++ b/lib/states/game_state.rb
@@ -1,8 +1,9 @@
# frozen_string_literal: true
+
class IMICFPS
class GameState < CyberarmEngine::GameState
include CommonMethods
attr_reader :options
end
-end
\ No newline at end of file
+end
diff --git a/lib/states/game_states/boot.rb b/lib/states/game_states/boot.rb
index 007879b..f807e2f 100644
--- a/lib/states/game_states/boot.rb
+++ b/lib/states/game_states/boot.rb
@@ -1,9 +1,10 @@
# frozen_string_literal: true
+
class IMICFPS
class Boot < GameState
def setup
@title = Text.new(IMICFPS::NAME, size: 100, z: 0, color: Gosu::Color.new(0xff000000), shadow: false, font: "Droid Serif")
- @logo = get_image(IMICFPS::GAME_ROOT_PATH + "/static/logo.png")
+ @logo = get_image("#{IMICFPS::GAME_ROOT_PATH}/static/logo.png")
@start_time = Gosu.milliseconds
@time_to_live = 3_000
@@ -34,7 +35,7 @@ class IMICFPS
@title.draw
- fill(Gosu::Color.rgba(0,0,0, 255 * (1.2 - fraction_left)))
+ fill(Gosu::Color.rgba(0, 0, 0, 255 * (1.2 - fraction_left)))
end
end
@@ -46,11 +47,11 @@ class IMICFPS
end
def button_up(id)
- if id == Gosu::KbEscape or
- (id >= Gosu::GP_LEFT and id >= Gosu::GP_BUTTON_15) or
- id == Gosu::MsLeft
+ if (id == Gosu::KbEscape) ||
+ ((id >= Gosu::GP_LEFT) && (id >= Gosu::GP_BUTTON_15)) ||
+ (id == Gosu::MsLeft)
push_state(MainMenu)
end
end
end
-end
\ No newline at end of file
+end
diff --git a/lib/states/game_states/close.rb b/lib/states/game_states/close.rb
index f02cf38..4d68d34 100644
--- a/lib/states/game_states/close.rb
+++ b/lib/states/game_states/close.rb
@@ -1,10 +1,11 @@
# frozen_string_literal: true
+
class IMICFPS
class Close < GameState
def setup
@slope = Menu::BAR_SLOPE
- @logo = get_image(IMICFPS::GAME_ROOT_PATH + "/static/logo.png")
+ @logo = get_image("#{IMICFPS::GAME_ROOT_PATH}/static/logo.png")
@start_time = Gosu.milliseconds
@time_to_live = 3_000
@@ -31,7 +32,7 @@ class IMICFPS
@logo.draw(window.width / 2 - @logo.width / 2, window.height / 2 - @logo.height / 2, 0)
- fill(Gosu::Color.rgba(0,0,0, 255 * (1.1 - fraction_left)))
+ fill(Gosu::Color.rgba(0, 0, 0, 255 * (1.1 - fraction_left)))
end
def update
@@ -40,11 +41,11 @@ class IMICFPS
end
def button_up(id)
- if id == Gosu::KbEscape or
- (id >= Gosu::GP_LEFT and id >= Gosu::GP_BUTTON_15) or
- id == Gosu::MsLeft
+ if (id == Gosu::KbEscape) ||
+ ((id >= Gosu::GP_LEFT) && (id >= Gosu::GP_BUTTON_15)) ||
+ (id == Gosu::MsLeft)
window.close!
end
end
end
-end
\ No newline at end of file
+end
diff --git a/lib/states/game_states/game.rb b/lib/states/game_states/game.rb
index 2e4aedb..d893b8e 100644
--- a/lib/states/game_states/game.rb
+++ b/lib/states/game_states/game.rb
@@ -1,4 +1,5 @@
# frozen_string_literal: true
+
class IMICFPS
class Game < GameState
attr_reader :map
@@ -7,7 +8,7 @@ class IMICFPS
window.director.load_map(map_parser: @options[:map_parser])
@player = window.director.map.find_entity_by(name: "character")
- @camera = PerspectiveCamera.new( position: @player.position.clone, aspect_ratio: window.aspect_ratio )
+ @camera = PerspectiveCamera.new(position: @player.position.clone, aspect_ratio: window.aspect_ratio)
@camera_controller = CameraController.new(mode: :fpv, camera: @camera, entity: @player)
# @connection = Networking::Connection.new(address: "localhost", port: Networking::DEFAULT_SERVER_PORT)
diff --git a/lib/states/game_states/loading_state.rb b/lib/states/game_states/loading_state.rb
index 5e0c01a..a435e08 100644
--- a/lib/states/game_states/loading_state.rb
+++ b/lib/states/game_states/loading_state.rb
@@ -1,4 +1,5 @@
# frozen_string_literal: true
+
class IMICFPS
class LoadingState < Menu
def setup
@@ -13,8 +14,8 @@ class IMICFPS
title IMICFPS::NAME
@subheading = Text.new("Loading Map: #{@map_parser.metadata.name}", y: 100, size: 50, alignment: :center, font: SANS_FONT)
- @description = Text.new("Map created by: #{@map_parser.metadata.authors.join(", ")}\n#{@map_parser.metadata.description}", y: 180, size: 24, alignment: :center, font: SANS_FONT)
- @state = Text.new("Preparing...", y: window.height/2-40, size: 40, alignment: :center, font: SANS_FONT)
+ @description = Text.new("Map created by: #{@map_parser.metadata.authors.join(', ')}\n#{@map_parser.metadata.description}", y: 180, size: 24, alignment: :center, font: SANS_FONT)
+ @state = Text.new("Preparing...", y: window.height / 2 - 40, size: 40, alignment: :center, font: SANS_FONT)
@percentage = Text.new("0%", y: window.height - 100 + 25, size: 50, alignment: :center, font: SANS_FONT)
@dummy_entity = nil
@@ -45,7 +46,6 @@ class IMICFPS
@description.draw
@state.draw
-
progressbar
end
@@ -75,18 +75,16 @@ class IMICFPS
@asset_index += 1
end
- unless @asset_index < @assets.count
- if @act && Gosu.milliseconds-@completed_for_ms > 250
- push_state(@options[:forward], map_parser: @map_parser)
- else
- @act = true
- @completed_for_ms = Gosu.milliseconds unless @lock
- @lock = true
- end
- else
+ if @asset_index < @assets.count
@state.text = "Loading #{@assets[@asset_index][:type]} #{@assets[@asset_index][:name].split('/').last}..."
- @state.x = (window.width/2)-(@state.width/2)
+ @state.x = (window.width / 2) - (@state.width / 2)
@cycled = true
+ elsif @act && Gosu.milliseconds - @completed_for_ms > 250
+ push_state(@options[:forward], map_parser: @map_parser)
+ else
+ @act = true
+ @completed_for_ms = Gosu.milliseconds unless @lock
+ @lock = true
end
end
@@ -95,9 +93,9 @@ class IMICFPS
when :model
manifest = Manifest.new(manifest_file: IMICFPS.assets_path + "/#{package}/#{name}/manifest.yaml")
add_required_assets(manifest)
- @assets << {type: type, manifest: manifest, package: package, name: name}
+ @assets << { type: type, manifest: manifest, package: package, name: name }
when :shader
- @assets << {type: type, manifest: manifest, package: package, name: name}
+ @assets << { type: type, manifest: manifest, package: package, name: name }
else
raise TypeError "Unable to load asset of type #{type}"
end
@@ -105,30 +103,28 @@ class IMICFPS
def add_required_assets(manifest)
manifest.uses.each do |dependency|
- known = @assets.detect {|asset| asset[:package] == dependency.package && asset[:name] == dependency.name}
- unless known
- add_asset(:model, dependency.package, dependency.name)
- end
+ known = @assets.detect { |asset| asset[:package] == dependency.package && asset[:name] == dependency.name }
+ add_asset(:model, dependency.package, dependency.name) unless known
end
end
- def progressbar(x = window.width/4, y = window.height - 104)
+ def progressbar(x = window.width / 4, y = window.height - 104)
@percentage.draw
- progress = (@asset_index.to_f/@assets.count)*window.width/2
+ progress = (@asset_index.to_f / @assets.count) * window.width / 2
height = 100
- dark_color= Gosu::Color.rgb(@primary_color.red - 100, @primary_color.green - 100, @primary_color.blue - 100)#Gosu::Color.rgb(64, 127, 255)
- color = Gosu::Color.rgb(@primary_color.red - 50, @primary_color.green - 50, @primary_color.blue - 50)#Gosu::Color.rgb(0,127,127)
- color_two = Gosu::Color.rgb(@primary_color.red + 50, @primary_color.green + 50, @primary_color.blue + 50)#Gosu::Color.rgb(64, 127, 255)
+ dark_color = Gosu::Color.rgb(@primary_color.red - 100, @primary_color.green - 100, @primary_color.blue - 100) # Gosu::Color.rgb(64, 127, 255)
+ color = Gosu::Color.rgb(@primary_color.red - 50, @primary_color.green - 50, @primary_color.blue - 50) # Gosu::Color.rgb(0,127,127)
+ color_two = Gosu::Color.rgb(@primary_color.red + 50, @primary_color.green + 50, @primary_color.blue + 50) # Gosu::Color.rgb(64, 127, 255)
- draw_rect(x, y-2, x + window.width/4, height+4, dark_color)
+ draw_rect(x, y - 2, x + window.width / 4, height + 4, dark_color)
Gosu.clip_to(x, y, progress, height) do
Gosu.draw_quad(
x, y, color,
- x + x + window.width/4, y, color_two,
+ x + x + window.width / 4, y, color_two,
x, y + height, color,
- x + x + window.width/4, y + height, color_two
+ x + x + window.width / 4, y + height, color_two
)
end
end
diff --git a/lib/subscription.rb b/lib/subscription.rb
index 4491623..85a32be 100644
--- a/lib/subscription.rb
+++ b/lib/subscription.rb
@@ -1,7 +1,9 @@
# frozen_string_literal: true
+
class IMICFPS
class Subscription
attr_reader :entity, :event, :args, :block
+
def initialize(entity)
@entity = entity
@@ -13,28 +15,28 @@ class IMICFPS
def method_missing(event, *args, &block)
return unless Subscription.subscribable_events.include?(event)
- @event, @args, @block = event, args, block
+ @event = event
+ @args = args
+ @block = block
Publisher.subscribe(self)
end
def trigger(event, *args)
- if @block
- @block.call(event, *args)
- end
+ @block&.call(event, *args)
end
def self.subscribable_events
- [
- :tick,
- :create, :move, :destroy,
- :entity_moved,
- :button_down, :button_up,
- :mouse_move,
- :interact,
- :player_join, :player_leave, :player_die,
- :pickup_item, :use_item, :drop_item,
- :enter_vehicle, :exit_vehicle,
+ %i[
+ tick
+ create move destroy
+ entity_moved
+ button_down button_up
+ mouse_move
+ interact
+ player_join player_leave player_die
+ pickup_item use_item drop_item
+ enter_vehicle exit_vehicle
]
end
end
-end
\ No newline at end of file
+end
diff --git a/lib/tools/asset_viewer.rb b/lib/tools/asset_viewer.rb
index f8bbd3a..6bd46a6 100644
--- a/lib/tools/asset_viewer.rb
+++ b/lib/tools/asset_viewer.rb
@@ -1,3 +1,4 @@
# frozen_string_literal: true
+
require_relative "asset_viewer/lib/main_menu"
-require_relative "asset_viewer/lib/turn_table"
\ No newline at end of file
+require_relative "asset_viewer/lib/turn_table"
diff --git a/lib/tools/asset_viewer/lib/main_menu.rb b/lib/tools/asset_viewer/lib/main_menu.rb
index bccfdfd..60fc210 100644
--- a/lib/tools/asset_viewer/lib/main_menu.rb
+++ b/lib/tools/asset_viewer/lib/main_menu.rb
@@ -1,4 +1,5 @@
# frozen_string_literal: true
+
class IMICFPS
class AssetViewerTool
class MainMenu < Menu
@@ -6,17 +7,17 @@ class IMICFPS
window.needs_cursor = true
@manifests = []
- Dir.glob(GAME_ROOT_PATH + "/assets/**/manifest.yaml").each do |manifest|
+ Dir.glob("#{GAME_ROOT_PATH}/assets/**/manifest.yaml").each do |manifest|
begin
@manifests << Manifest.new(manifest_file: manifest)
- rescue
+ rescue StandardError
warn "Broken manifest: #{manifest}"
end
end
@manifests.sort_by! { |m| m.name.downcase }
- label "#{IMICFPS::NAME}", text_size: 100, color: Gosu::Color::BLACK
+ label IMICFPS::NAME.to_s, text_size: 100, color: Gosu::Color::BLACK
label "Asset Viewer", text_size: 50
flow(width: 1.0, height: 1.0) do
@@ -45,4 +46,4 @@ class IMICFPS
end
end
end
-end
\ No newline at end of file
+end
diff --git a/lib/tools/asset_viewer/lib/turn_table.rb b/lib/tools/asset_viewer/lib/turn_table.rb
index 51c5165..2429f7b 100644
--- a/lib/tools/asset_viewer/lib/turn_table.rb
+++ b/lib/tools/asset_viewer/lib/turn_table.rb
@@ -1,10 +1,12 @@
# frozen_string_literal: true
+
class IMICFPS
class AssetViewerTool
class TurnTable < CyberarmEngine::GuiState
include LightManager
attr_reader :map
+
def setup
window.needs_cursor = false
@manifest = @options[:manifest]
@@ -42,7 +44,7 @@ class IMICFPS
0, 0, color_top,
window.width, 0, color_top,
window.width, window.height, color_bottom,
- 0, window.height, color_bottom,
+ 0, window.height, color_bottom
)
Gosu.gl do
@@ -83,9 +85,10 @@ class IMICFPS
include EntityManager
attr_reader :entities
+
def initialize
@entities = []
end
end
end
-end
\ No newline at end of file
+end
diff --git a/lib/tools/map_editor.rb b/lib/tools/map_editor.rb
index 7a429be..b080386 100644
--- a/lib/tools/map_editor.rb
+++ b/lib/tools/map_editor.rb
@@ -1,3 +1,4 @@
# frozen_string_literal: true
+
require_relative "map_editor/lib/main_menu"
-require_relative "map_editor/lib/editor"
\ No newline at end of file
+require_relative "map_editor/lib/editor"
diff --git a/lib/tools/map_editor/lib/editor.rb b/lib/tools/map_editor/lib/editor.rb
index f384446..e27aab1 100644
--- a/lib/tools/map_editor/lib/editor.rb
+++ b/lib/tools/map_editor/lib/editor.rb
@@ -1,4 +1,5 @@
# frozen_string_literal: true
+
class IMICFPS
class MapEditorTool
class Editor < CyberarmEngine::GuiState
@@ -10,8 +11,8 @@ class IMICFPS
# and refactor Game to use it.
Publisher.new
@map = Map.new(map_parser: @options[:map_parser])
- @camera = PerspectiveCamera.new( position: Vector.new, aspect_ratio: window.aspect_ratio )
- @editor = IMICFPS::Editor.new( manifest: Manifest.new(package: "base", name: "editor") )
+ @camera = PerspectiveCamera.new(position: Vector.new, aspect_ratio: window.aspect_ratio)
+ @editor = IMICFPS::Editor.new(manifest: Manifest.new(package: "base", name: "editor"))
@camera_controller = CameraController.new(camera: @camera, entity: @editor)
@crosshair = Crosshair.new
@@ -36,7 +37,7 @@ class IMICFPS
end
def control_editor
- InputMapper.keys.each do |key, pressed|
+ InputMapper.each_key do |key, pressed|
next unless pressed
actions = InputMapper.actions(key)
diff --git a/lib/tools/map_editor/lib/main_menu.rb b/lib/tools/map_editor/lib/main_menu.rb
index 117462e..ec01f35 100644
--- a/lib/tools/map_editor/lib/main_menu.rb
+++ b/lib/tools/map_editor/lib/main_menu.rb
@@ -1,18 +1,19 @@
# frozen_string_literal: true
+
class IMICFPS
class MapEditorTool
class MainMenu < Menu
def setup
window.needs_cursor = true
- label "#{IMICFPS::NAME}", text_size: 50
+ label IMICFPS::NAME.to_s, text_size: 50
label "Map Editor", text_size: 28
@maps = []
- Dir.glob(GAME_ROOT_PATH + "/maps/*.json").each do |map|
+ Dir.glob("#{GAME_ROOT_PATH}/maps/*.json").each do |map|
begin
@maps << MapParser.new(map_file: map)
- rescue
+ rescue StandardError
warn "Broken map file: #{map}"
end
end
@@ -48,4 +49,4 @@ class IMICFPS
end
end
end
-end
\ No newline at end of file
+end
diff --git a/lib/trees/aabb_node.rb b/lib/trees/aabb_node.rb
index c3a7985..757e7bc 100644
--- a/lib/trees/aabb_node.rb
+++ b/lib/trees/aabb_node.rb
@@ -1,9 +1,11 @@
# frozen_string_literal: true
+
class IMICFPS
class AABBTree
class AABBNode
attr_accessor :bounding_box, :parent, :object
attr_reader :a, :b
+
def initialize(parent:, object:, bounding_box:)
@parent = parent
@object = object
@@ -34,7 +36,7 @@ class IMICFPS
new_node.a = self
new_node.b = leaf
- return new_node
+ new_node
else
cost_a = @a.bounding_box.volume + @b.bounding_box.union(leaf.bounding_box).volume
cost_b = @b.bounding_box.volume + @a.bounding_box.union(leaf.bounding_box).volume
@@ -52,7 +54,7 @@ class IMICFPS
@bounding_box = @bounding_box.union(leaf.bounding_box)
- return self
+ self
end
end
@@ -66,21 +68,19 @@ class IMICFPS
end
end
- return items
+ items
end
def remove_subtree(leaf)
if leaf
- return self
+ self
+ elsif leaf.parent == self
+ other_child = other(leaf)
+ other_child.parent = @parent
+ other_child
else
- if leaf.parent == self
- other_child = other(leaf)
- other_child.parent = @parent
- return other_child
- else
- leaf.parent.disown_child(leaf)
- return self
- end
+ leaf.parent.disown_child(leaf)
+ self
end
end
@@ -116,11 +116,11 @@ class IMICFPS
unless node.leaf?
node.bounding_box = node.a.bounding_box.union(node.b.bounding_box)
- while(node = node.parent)
+ while (node = node.parent)
node.bounding_box = node.a.bounding_box.union(node.b.bounding_box)
end
end
end
end
end
-end
\ No newline at end of file
+end
diff --git a/lib/trees/aabb_tree.rb b/lib/trees/aabb_tree.rb
index 9e0ccfa..0a753b4 100644
--- a/lib/trees/aabb_tree.rb
+++ b/lib/trees/aabb_tree.rb
@@ -1,9 +1,11 @@
# frozen_string_literal: true
+
class IMICFPS
class AABBTree
include IMICFPS::AABBTreeDebug
attr_reader :root, :objects, :branches, :leaves
+
def initialize
@objects = {}
@root = nil
@@ -23,11 +25,11 @@ class IMICFPS
end
def insert_leaf(leaf)
- if @root
- @root = @root.insert_subtree(leaf)
- else
- @root = leaf
- end
+ @root = if @root
+ @root.insert_subtree(leaf)
+ else
+ leaf
+ end
end
def update(object, bounding_box)
@@ -41,17 +43,17 @@ class IMICFPS
items = []
if @root
items = @root.search_subtree(collider)
- items.map! {|e| e.object} unless return_nodes
+ items.map!(&:object) unless return_nodes
end
- return items
+ items
end
def remove(object)
leaf = @objects.delete(object)
@root = @root.remove_subtree(leaf) if leaf
- return leaf
+ leaf
end
end
-end
\ No newline at end of file
+end
diff --git a/lib/trees/aabb_tree_debug.rb b/lib/trees/aabb_tree_debug.rb
index d17ae60..059291c 100644
--- a/lib/trees/aabb_tree_debug.rb
+++ b/lib/trees/aabb_tree_debug.rb
@@ -1,9 +1,11 @@
# frozen_string_literal: true
+
class IMICFPS
# Gets included into AABBTree
module AABBTreeDebug
def inspect
- @branches, @leaves = 0, 0
+ @branches = 0
+ @leaves = 0
if @root
node = @root
@@ -11,7 +13,7 @@ class IMICFPS
debug_search(node.b)
end
- puts "<#{self.class}:#{self.object_id}> has #{@branches} branches and #{@leaves} leaves"
+ puts "<#{self.class}:#{object_id}> has #{@branches} branches and #{@leaves} leaves"
end
def debug_search(node)
@@ -24,4 +26,4 @@ class IMICFPS
end
end
end
-end
\ No newline at end of file
+end
diff --git a/lib/ui/command.rb b/lib/ui/command.rb
index dc09321..76e7a4a 100644
--- a/lib/ui/command.rb
+++ b/lib/ui/command.rb
@@ -1,16 +1,20 @@
# frozen_string_literal: true
+
class IMICFPS
class Commands
module Style
def self.error(string)
"#{string}"
end
+
def self.warn(string)
"#{string}"
end
+
def self.notice(string)
"#{string}"
end
+
def self.highlight(string, color = "5555ff")
"#{string}"
end
@@ -28,7 +32,9 @@ class IMICFPS
@commands = []
@list.each do |subclass|
cmd = subclass.new
- raise "Command '#{cmd.command}' from '#{cmd.class}' already exists!" if @commands.detect { |c| c.command == cmd.command }
+ if @commands.detect { |c| c.command == cmd.command }
+ raise "Command '#{cmd.command}' from '#{cmd.class}' already exists!"
+ end
@commands << cmd
end
@@ -59,15 +65,19 @@ class IMICFPS
setup
end
- def setup; end
+ def setup
+ end
def subcommand(command, type)
- raise "Subcommand '#{command}' for '#{self.command}' already exists!" if @subcommands.detect { |subcmd| subcmd.command == command.to_sym }
+ if @subcommands.detect { |subcmd| subcmd.command == command.to_sym }
+ raise "Subcommand '#{command}' for '#{self.command}' already exists!"
+ end
+
@subcommands << SubCommand.new(self, command, type)
end
def get(key)
- @store.dig(key)
+ @store[key]
end
def set(key, value)
@@ -89,15 +99,16 @@ class IMICFPS
def autocomplete(console)
split = console.text_input.text.split(" ")
- if @subcommands.size > 0
+ if @subcommands.size.positive?
if !console.text_input.text.end_with?(" ") && split.size == 2
- list = console.abbrev_search(@subcommands.map { |cmd| cmd.command.to_s}, split.last)
+ list = console.abbrev_search(@subcommands.map { |cmd| cmd.command.to_s }, split.last)
if list.size == 1
console.text_input.text = "#{split.first} #{list.first} "
else
- return unless list.size > 0
- console.stdin("#{list.map { |cmd| Commands::Style.highlight(cmd)}.join(", ")}")
+ return unless list.size.positive?
+
+ console.stdin(list.map { |cmd| Commands::Style.highlight(cmd) }.join(", ").to_s)
end
# List available options on subcommand
@@ -106,26 +117,26 @@ class IMICFPS
if subcommand
if split.size == 2
- console.stdin("Available options: #{subcommand.values.map { |value| Commands::Style.highlight(value) }.join(",")}")
+ console.stdin("Available options: #{subcommand.values.map { |value| Commands::Style.highlight(value) }.join(',')}")
else
list = console.abbrev_search(subcommand.values, split.last)
if list.size == 1
console.text_input.text = "#{split.first} #{split[1]} #{list.first} "
- else
- console.stdin("Available options: #{list.map { |value| Commands::Style.highlight(value) }.join(",")}") if list.size > 0
+ elsif list.size.positive?
+ console.stdin("Available options: #{list.map { |value| Commands::Style.highlight(value) }.join(',')}")
end
end
end
# List available subcommands if command was entered and has only a space after it
elsif console.text_input.text.end_with?(" ") && split.size == 1
- console.stdin("Available subcommands: #{@subcommands.map { |cmd| Commands::Style.highlight(cmd.command)}.join(", ")}")
+ console.stdin("Available subcommands: #{@subcommands.map { |cmd| Commands::Style.highlight(cmd.command) }.join(', ')}")
end
end
end
def handle_subcommand(arguments, console)
- if arguments.size == 0
+ if arguments.size.zero?
console.stdin(usage)
return
end
@@ -144,4 +155,4 @@ class IMICFPS
end
end
end
-end
\ No newline at end of file
+end
diff --git a/lib/ui/commands/connect_command.rb b/lib/ui/commands/connect_command.rb
index 53fc1e0..2bc652e 100644
--- a/lib/ui/commands/connect_command.rb
+++ b/lib/ui/commands/connect_command.rb
@@ -1,4 +1,5 @@
# frozen_string_literal: true
+
class IMICFPS
class Commands
class ConnectCommand < Command
@@ -14,8 +15,8 @@ class IMICFPS
end
def usage
- "Connect to a server.\n#{Style.highlight("connect")} #{Style.notice("[example.com:56789]")}"
+ "Connect to a server.\n#{Style.highlight('connect')} #{Style.notice('[example.com:56789]')}"
end
end
end
-end
\ No newline at end of file
+end
diff --git a/lib/ui/commands/debug_command.rb b/lib/ui/commands/debug_command.rb
index fd38f10..23da6e0 100644
--- a/lib/ui/commands/debug_command.rb
+++ b/lib/ui/commands/debug_command.rb
@@ -1,4 +1,5 @@
# frozen_string_literal: true
+
class IMICFPS
class Commands
class DebugCommand < Command
@@ -39,7 +40,7 @@ class IMICFPS
end
def usage
- "debug\n #{@subcommands.map { |sub| sub.usage }.join("\n ")}"
+ "debug\n #{@subcommands.map(&:usage).join("\n ")}"
end
end
end
diff --git a/lib/ui/commands/disconnect_command.rb b/lib/ui/commands/disconnect_command.rb
index 4fac17b..c29cddf 100644
--- a/lib/ui/commands/disconnect_command.rb
+++ b/lib/ui/commands/disconnect_command.rb
@@ -1,4 +1,5 @@
# frozen_string_literal: true
+
class IMICFPS
class Commands
class DisconnectCommand < Command
@@ -18,4 +19,4 @@ class IMICFPS
end
end
end
-end
\ No newline at end of file
+end
diff --git a/lib/ui/commands/fps_command.rb b/lib/ui/commands/fps_command.rb
index 7014a7a..23111fb 100644
--- a/lib/ui/commands/fps_command.rb
+++ b/lib/ui/commands/fps_command.rb
@@ -1,4 +1,5 @@
# frozen_string_literal: true
+
class IMICFPS
class Commands
class FPSCommand < Command
@@ -12,13 +13,13 @@ class IMICFPS
def handle(arguments, console)
if arguments.size > 1
- console.stdin("to many arguments for #{Style.highlight("#{command}")}, got #{Style.error(arguments.size)} expected #{Style.notice(1)}.")
+ console.stdin("to many arguments for #{Style.highlight(command.to_s)}, got #{Style.error(arguments.size)} expected #{Style.notice(1)}.")
return
end
case arguments.last
when "", nil
- console.stdin("#{Style.highlight("fps")}: #{$window.config.get(:options, :fps)}")
+ console.stdin("#{Style.highlight('fps')}: #{$window.config.get(:options, :fps)}")
when "on"
var = $window.config[:options, :fps] = true
console.stdin("fps => #{Style.highlight(var)}")
@@ -26,12 +27,12 @@ class IMICFPS
var = $window.config[:options, :fps] = false
console.stdin("fps => #{Style.highlight(var)}")
else
- console.stdin("Invalid argument for #{Style.highlight("#{command}")}, got #{Style.error(arguments.last)} expected #{Style.notice("on")}, or #{Style.notice("off")}.")
+ console.stdin("Invalid argument for #{Style.highlight(command.to_s)}, got #{Style.error(arguments.last)} expected #{Style.notice('on')}, or #{Style.notice('off')}.")
end
end
def usage
- "#{Style.highlight("fps")} #{Style.notice("[on|off]")}"
+ "#{Style.highlight('fps')} #{Style.notice('[on|off]')}"
end
end
end
diff --git a/lib/ui/commands/help_command.rb b/lib/ui/commands/help_command.rb
index 9095629..351a49f 100644
--- a/lib/ui/commands/help_command.rb
+++ b/lib/ui/commands/help_command.rb
@@ -1,4 +1,5 @@
# frozen_string_literal: true
+
class IMICFPS
class Commands
class HelpCommand < Command
@@ -21,7 +22,7 @@ class IMICFPS
if list.size == 1
console.text_input.text = "#{split.first} #{list.first} "
elsif list.size > 1
- console.stdin(list.map { |cmd| Style.highlight(cmd) }.join(', '))
+ console.stdin(list.map { |cmd| Style.highlight(cmd) }.join(", "))
end
end
end
@@ -34,9 +35,9 @@ class IMICFPS
"#{Style.error(command)} is not a command"
end
else
- "Available commands:\n#{Command.list_commands.map { |cmd| "#{Style.highlight(cmd.command)}" }.join(', ')}"
+ "Available commands:\n#{Command.list_commands.map { |cmd| Style.highlight(cmd.command).to_s }.join(', ')}"
end
end
end
end
-end
\ No newline at end of file
+end
diff --git a/lib/ui/commands/reload_shader_command.rb b/lib/ui/commands/reload_shader_command.rb
index 9b997e3..4309f3e 100644
--- a/lib/ui/commands/reload_shader_command.rb
+++ b/lib/ui/commands/reload_shader_command.rb
@@ -1,4 +1,5 @@
# frozen_string_literal: true
+
class IMICFPS
class Commands
class ReloadShaderCommand < Command
@@ -12,7 +13,7 @@ class IMICFPS
def handle(arguments, console)
if arguments.size > 2
- console.stdin("to many arguments for #{Style.highlight("#{command}")}, got #{Style.error(arguments.size)} expected #{Style.notice(1)}.")
+ console.stdin("to many arguments for #{Style.highlight(command.to_s)}, got #{Style.error(arguments.size)} expected #{Style.notice(1)}.")
return
end
@@ -22,7 +23,7 @@ class IMICFPS
case arguments.size
when 0
- console.stdin( usage )
+ console.stdin(usage)
return
when 1
name = arguments.first
@@ -50,9 +51,9 @@ class IMICFPS
string = $stdout.string
if shader.compiled?
- console.stdin("#{Style.notice("Successfully reloaded shader")}: #{shader.name}")
+ console.stdin("#{Style.notice('Successfully reloaded shader')}: #{shader.name}")
else
- console.stdin("#{Style.error("Failed to reload #{shader.name}")}")
+ console.stdin(Style.error("Failed to reload #{shader.name}").to_s)
console.stdin(string)
end
ensure
@@ -61,7 +62,7 @@ class IMICFPS
end
def usage
- "#{Style.highlight(command)} #{Style.notice("vertex_name [fragment_name]")}"
+ "#{Style.highlight(command)} #{Style.notice('vertex_name [fragment_name]')}"
end
end
end
diff --git a/lib/ui/commands/renderer_info_command.rb b/lib/ui/commands/renderer_info_command.rb
index 1dd2b6c..b44c7b1 100644
--- a/lib/ui/commands/renderer_info_command.rb
+++ b/lib/ui/commands/renderer_info_command.rb
@@ -1,4 +1,5 @@
# frozen_string_literal: true
+
class IMICFPS
class Commands
class RendererInfoCommand < Command
@@ -10,7 +11,7 @@ class IMICFPS
:renderer_info
end
- def handle(arguments, console)
+ def handle(_arguments, console)
console.stdin("OpenGL Vendor: #{Style.notice(glGetString(GL_VENDOR))}")
console.stdin("OpenGL Renderer: #{Style.notice(glGetString(GL_RENDERER))}")
console.stdin("OpenGL Version: #{Style.notice(glGetString(GL_VERSION))}")
@@ -18,7 +19,7 @@ class IMICFPS
end
def usage
- "#{Style.highlight("renderer_info")} #{Style.notice("Returns OpenGL renderer information")}"
+ "#{Style.highlight('renderer_info')} #{Style.notice('Returns OpenGL renderer information')}"
end
end
end
diff --git a/lib/ui/console.rb b/lib/ui/console.rb
index be0d60b..7821274 100644
--- a/lib/ui/console.rb
+++ b/lib/ui/console.rb
@@ -1,4 +1,5 @@
# frozen_string_literal: true
+
class IMICFPS
class Console
Z = 100_000
@@ -6,6 +7,7 @@ class IMICFPS
include CommonMethods
attr_reader :text_input
+
def initialize
@text_input = Gosu::TextInput.new
@width = window.width / 4 * 3
@@ -47,7 +49,9 @@ class IMICFPS
@history.draw
@input.draw
# Caret
- draw_rect(@input.x + caret_from_left, @input.y, Console::PADDING, @input.height, @caret_color, Console::Z + 2) if @show_caret
+ if @show_caret
+ draw_rect(@input.x + caret_from_left, @input.y, Console::PADDING, @input.height, @caret_color, Console::Z + 2)
+ end
# Caret selection
if caret_start != caret_end
if caret_start < @text_input.selection_start
@@ -59,8 +63,9 @@ class IMICFPS
end
def caret_from_left
- return 0 if @text_input.caret_pos == 0
- @input.textobject.text_width(@text_input.text[0..@text_input.caret_pos-1])
+ return 0 if @text_input.caret_pos.zero?
+
+ @input.textobject.text_width(@text_input.text[0..@text_input.caret_pos - 1])
end
def caret_selection_width
@@ -99,7 +104,8 @@ class IMICFPS
def button_down(id)
case id
when Gosu::KbEnter, Gosu::KbReturn
- return unless @text_input.text.length > 0
+ return unless @text_input.text.length.positive?
+
@history.text += "\n> #{@text_input.text}"
@command_history << @text_input.text
@command_history_index = @command_history.size
@@ -109,7 +115,7 @@ class IMICFPS
when Gosu::KbUp
@command_history_index -= 1
- @command_history_index = 0 if @command_history_index < 0
+ @command_history_index = 0 if @command_history_index.negative?
@text_input.text = @command_history[@command_history_index]
when Gosu::KbDown
@@ -125,26 +131,24 @@ class IMICFPS
split = @text_input.text.split(" ")
if !@text_input.text.end_with?(" ") && split.size == 1
- list = abbrev_search(Commands::Command.list_commands.map { |cmd| cmd.command.to_s}, @text_input.text)
+ list = abbrev_search(Commands::Command.list_commands.map { |cmd| cmd.command.to_s }, @text_input.text)
if list.size == 1
@text_input.text = "#{list.first} "
- else
- stdin("\n#{list.map { |cmd| Commands::Style.highlight(cmd)}.join(", ")}") if list.size > 0
- end
- else
- if split.size > 0 && cmd = Commands::Command.find(split.first)
- cmd.autocomplete(self)
+ elsif list.size.positive?
+ stdin("\n#{list.map { |cmd| Commands::Style.highlight(cmd) }.join(', ')}")
end
+ elsif split.size.positive? && cmd = Commands::Command.find(split.first)
+ cmd.autocomplete(self)
end
when Gosu::KbBacktick
# Remove backtick character from input
- if @text_input.text.size > 1
- @text_input.text = @text_input.text[0..@text_input.text.size - 2]
- else
- @text_input.text = ""
- end
+ @text_input.text = if @text_input.text.size > 1
+ @text_input.text[0..@text_input.text.size - 2]
+ else
+ ""
+ end
# Copy
when Gosu::KbC
@@ -187,9 +191,7 @@ class IMICFPS
# Clear history
when Gosu::KbL
- if control_down?
- @history.text = ""
- end
+ @history.text = "" if control_down?
end
end
@@ -197,29 +199,29 @@ class IMICFPS
end
def update_history_y
- @history.y = @height - (PADDING * 2) - @input.height - (@history.text.lines.count * (@history.textobject.height))
+ @history.y = @height - (PADDING * 2) - @input.height - (@history.text.lines.count * @history.textobject.height)
end
def handle_command
string = @text_input.text
split = string.split(" ")
command = split.first
- arguments = split.length > 0 ? split[1..split.length - 1] : []
+ arguments = split.length.positive? ? split[1..split.length - 1] : []
IMICFPS::Commands::Command.use(command, arguments, self)
end
def abbrev_search(array, text)
- return [] unless text.length > 0
+ return [] unless text.length.positive?
list = []
Abbrev.abbrev(array).each do |abbrev, value|
- next unless abbrev && abbrev.start_with?(text)
+ next unless abbrev&.start_with?(text)
list << value
end
- return list.uniq
+ list.uniq
end
def stdin(string)
@@ -245,4 +247,4 @@ class IMICFPS
window.needs_cursor = @showing_cursor
end
end
-end
\ No newline at end of file
+end
diff --git a/lib/ui/menu.rb b/lib/ui/menu.rb
index bc72c0c..5c1929d 100644
--- a/lib/ui/menu.rb
+++ b/lib/ui/menu.rb
@@ -1,4 +1,5 @@
# frozen_string_literal: true
+
class IMICFPS
class Menu < IMICFPS::GuiState
include CommonMethods
@@ -67,7 +68,7 @@ class IMICFPS
@_subtitle = @elements.last
end
- def link(text, color = Gosu::Color.rgb(0,127,127), &block)
+ def link(text, color = Gosu::Color.rgb(0, 127, 127), &block)
text = Text.new(text, color: color, size: 50, x: 0, y: 100 + (60 * @elements.count), font: BOLD_SANS_FONT)
@elements << Link.new(text, self, block)
end
@@ -94,14 +95,12 @@ class IMICFPS
draw_rect(
window.width / 4, 0,
window.width / 2, window.height,
- Gosu::Color.new(0x11ffffff),
+ Gosu::Color.new(0x11ffffff)
)
end
def draw_menu
- @elements.each do |e|
- e.draw
- end
+ @elements.each(&:draw)
end
def update
@@ -110,9 +109,7 @@ class IMICFPS
e.update
end
- if window.scene
- window.scene.update(window.dt)
- end
+ window.scene&.update(window.dt)
super
@@ -124,9 +121,8 @@ class IMICFPS
if id == Gosu::MsLeft
@elements.each do |e|
next unless e.is_a?(Link)
- if mouse_over?(e)
- e.clicked
- end
+
+ e.clicked if mouse_over?(e)
end
end
@@ -134,36 +130,59 @@ class IMICFPS
end
def mouse_over?(object)
- mouse_x.between?(object.x, object.x+object.width) &&
- mouse_y.between?(object.y, object.y+object.height)
+ mouse_x.between?(object.x, object.x + object.width) &&
+ mouse_y.between?(object.y, object.y + object.height)
end
class Link
attr_reader :text, :block
+
def initialize(text, host, block)
- @text, @host, @block = text, host, block
+ @text = text
+ @host = host
+ @block = block
@color = @text.color
@hover_color = Gosu::Color.rgb(64, 128, 255)
- @text.shadow_color= Gosu::Color::BLACK
+ @text.shadow_color = Gosu::Color::BLACK
@text.shadow_size = 2
@text.shadow_alpha = 100
end
def update
- if @host.mouse_over?(self)
- @text.color = @hover_color
- else
- @text.color = @color
- end
+ @text.color = if @host.mouse_over?(self)
+ @hover_color
+ else
+ @color
+ end
end
- def x; text.x; end
- def x=(n); text.x = n; end
- def y; text.y; end
- def width; text.width; end
- def height; text.height; end
- def draw; text.draw; end
- def clicked; @block.call if @block; end
+ def x
+ text.x
+ end
+
+ def x=(n)
+ text.x = n
+ end
+
+ def y
+ text.y
+ end
+
+ def width
+ text.width
+ end
+
+ def height
+ text.height
+ end
+
+ def draw
+ text.draw
+ end
+
+ def clicked
+ @block&.call
+ end
end
end
end
diff --git a/lib/ui/menus/extras_menu.rb b/lib/ui/menus/extras_menu.rb
index 2ad42cd..15da8e6 100644
--- a/lib/ui/menus/extras_menu.rb
+++ b/lib/ui/menus/extras_menu.rb
@@ -1,4 +1,5 @@
# frozen_string_literal: true
+
class IMICFPS
class ExtrasMenu < Menu
def setup
@@ -18,4 +19,4 @@ class IMICFPS
end
end
end
-end
\ No newline at end of file
+end
diff --git a/lib/ui/menus/game_pause_menu.rb b/lib/ui/menus/game_pause_menu.rb
index 22a4183..e9673b5 100644
--- a/lib/ui/menus/game_pause_menu.rb
+++ b/lib/ui/menus/game_pause_menu.rb
@@ -1,4 +1,5 @@
# frozen_string_literal: true
+
class IMICFPS
class GamePauseMenu < Menu
def setup
diff --git a/lib/ui/menus/level_select_menu.rb b/lib/ui/menus/level_select_menu.rb
index 3e2396e..3949df2 100644
--- a/lib/ui/menus/level_select_menu.rb
+++ b/lib/ui/menus/level_select_menu.rb
@@ -1,11 +1,12 @@
# frozen_string_literal: true
+
class IMICFPS
class LevelSelectMenu < Menu
def setup
title IMICFPS::NAME
subtitle "Choose a Map"
- Dir.glob(GAME_ROOT_PATH + "/maps/*.json").map { |file| [file, MapParser.new(map_file: file)]}.each do |file, map|
+ Dir.glob("#{GAME_ROOT_PATH}/maps/*.json").map { |file| [file, MapParser.new(map_file: file)] }.each do |file, map|
link map.metadata.name do
push_state(
LoadingState.new(forward: Game, map_file: file)
diff --git a/lib/ui/menus/main_menu.rb b/lib/ui/menus/main_menu.rb
index d759f93..7690670 100644
--- a/lib/ui/menus/main_menu.rb
+++ b/lib/ui/menus/main_menu.rb
@@ -1,4 +1,5 @@
# frozen_string_literal: true
+
class IMICFPS
class MainMenu < Menu
def setup
@@ -25,16 +26,16 @@ class IMICFPS
end
gl_version = glGetString(GL_VERSION).to_s
- major, minor = gl_version.split(" ").first.split(".").map { |v| v.to_i }
+ major, minor = gl_version.split(" ").first.split(".").map(&:to_i)
unless (major == 3 && minor >= 3) || (major > 3)
-message =
-"[Notice] Your computer is reporting support for OpenGL #{major}.#{minor},
+ message =
+ "[Notice] Your computer is reporting support for OpenGL #{major}.#{minor},
however OpenGL 3.3 or higher is required.
Fallback immediate mode renderer will be used."
-linux_mesa_message =
-"
+ linux_mesa_message =
+ "
(Linux Only) For MESA based drivers append --mesa-override
as a commandline argument to override reported version."
@@ -46,9 +47,7 @@ as a commandline argument to override reported version."
def draw
super
- if @old_gl_warning
- @old_gl_warning.draw(window.width / 2 - @old_gl_warning.width / 2, window.height - (@old_gl_warning.height + 10), Float::INFINITY)
- end
+ @old_gl_warning&.draw(window.width / 2 - @old_gl_warning.width / 2, window.height - (@old_gl_warning.height + 10), Float::INFINITY)
end
end
end
diff --git a/lib/ui/menus/multiplayer_menu.rb b/lib/ui/menus/multiplayer_menu.rb
index 060302c..4e30ce0 100644
--- a/lib/ui/menus/multiplayer_menu.rb
+++ b/lib/ui/menus/multiplayer_menu.rb
@@ -1,4 +1,5 @@
# frozen_string_literal: true
+
class IMICFPS
class MultiplayerMenu < Menu
def setup
@@ -17,4 +18,4 @@ class IMICFPS
end
end
end
-end
\ No newline at end of file
+end
diff --git a/lib/ui/menus/multiplayer_profile_menu.rb b/lib/ui/menus/multiplayer_profile_menu.rb
index 08caf45..b65a281 100644
--- a/lib/ui/menus/multiplayer_profile_menu.rb
+++ b/lib/ui/menus/multiplayer_profile_menu.rb
@@ -1,4 +1,5 @@
# frozen_string_literal: true
+
class IMICFPS
class MultiplayerProfileMenu < Menu
def setup
@@ -49,4 +50,4 @@ class IMICFPS
end
end
end
-end
\ No newline at end of file
+end
diff --git a/lib/ui/menus/multiplayer_server_browser_menu.rb b/lib/ui/menus/multiplayer_server_browser_menu.rb
index 5399c08..2503d10 100644
--- a/lib/ui/menus/multiplayer_server_browser_menu.rb
+++ b/lib/ui/menus/multiplayer_server_browser_menu.rb
@@ -1,4 +1,5 @@
# frozen_string_literal: true
+
class IMICFPS
class MultiplayerServerBrowserMenu < Menu
def setup
@@ -80,4 +81,4 @@ class IMICFPS
end
end
end
-end
\ No newline at end of file
+end
diff --git a/lib/ui/menus/settings_menu.rb b/lib/ui/menus/settings_menu.rb
index e53c4e5..39feb14 100644
--- a/lib/ui/menus/settings_menu.rb
+++ b/lib/ui/menus/settings_menu.rb
@@ -1,21 +1,28 @@
# frozen_string_literal: true
+
class IMICFPS
class SettingsMenu < Menu
include CommonMethods
def self.set_defaults
- $window.config[:options, :audio, :volume_sound] = 1.0 if $window.config.get(:options, :audio, :volume_sound).nil?
- $window.config[:options, :audio, :volume_music] = 0.7 if $window.config.get(:options, :audio, :volume_music).nil?
- $window.config[:options, :audio, :volume_dialogue] = 0.7 if $window.config.get(:options, :audio, :volume_dialogue).nil?
+ if $window.config.get(:options, :audio, :volume_sound).nil?
+ $window.config[:options, :audio, :volume_sound] = 1.0
+ end
+ if $window.config.get(:options, :audio, :volume_music).nil?
+ $window.config[:options, :audio, :volume_music] = 0.7
+ end
+ if $window.config.get(:options, :audio, :volume_dialogue).nil?
+ $window.config[:options, :audio, :volume_dialogue] = 0.7
+ end
end
def setup
- @categories = [
- "Display",
- "Graphics",
- "Audio",
- "Controls",
- "Multiplayer"
+ @categories = %w[
+ Display
+ Graphics
+ Audio
+ Controls
+ Multiplayer
]
@pages = {}
@current_page = nil
@@ -40,9 +47,7 @@ class IMICFPS
@pages[:"#{category}".downcase] = element
element.hide
- if respond_to?(:"create_page_#{category}".downcase)
- self.send(:"create_page_#{category}".downcase)
- end
+ send(:"create_page_#{category}".downcase) if respond_to?(:"create_page_#{category}".downcase)
end
end
end
@@ -51,8 +56,8 @@ class IMICFPS
end
def show_page(page)
- if element = @pages.dig(page)
- @current_page.hide if @current_page
+ if element = @pages[page]
+ @current_page&.hide
@current_page = element
element.show
end
@@ -68,8 +73,8 @@ class IMICFPS
label "Height"
end
stack do
- edit_line "#{window.width}"
- edit_line "#{window.height}"
+ edit_line window.width.to_s
+ edit_line window.height.to_s
end
end
@@ -80,7 +85,7 @@ class IMICFPS
flow do
label "Gamma Correction".ljust(longest_string.length, " ")
@display_gamma_correction = slider range: 0.0..1.0, value: 0.5
- @display_gamma_correction.subscribe(:changed) do |sender, value|
+ @display_gamma_correction.subscribe(:changed) do |_sender, value|
@display_gamma_correction_label.value = value.round(1).to_s
end
@display_gamma_correction_label = label "0.0"
@@ -88,14 +93,15 @@ class IMICFPS
flow do
label "Brightness".ljust(longest_string.length, " ")
@display_brightness = slider range: 0.0..1.0, value: 0.5
- @display_brightness.subscribe(:changed) do |sender, value|
+ @display_brightness.subscribe(:changed) do |_sender, value|
@display_brightness_label.value = value.round(1).to_s
end
- @display_brightness_label = label "0.0" end
+ @display_brightness_label = label "0.0"
+ end
flow do
label "Contrast".ljust(longest_string.length, " ")
@display_contrast = slider range: 0.0..1.0, value: 0.5
- @display_contrast.subscribe(:changed) do |sender, value|
+ @display_contrast.subscribe(:changed) do |_sender, value|
@display_contrast_label.value = value.round(1).to_s
end
@display_contrast_label = label "0.0"
@@ -106,7 +112,7 @@ class IMICFPS
def create_page_audio
label "Audio", text_size: 50
longest_string = "Dialogue".length
- volumes = [:sound, :music, :dialogue]
+ volumes = %i[sound music dialogue]
stack do
volumes.each do |volume|
@@ -115,11 +121,11 @@ class IMICFPS
flow do
label volume.to_s.split("_").join(" ").capitalize.ljust(longest_string, " ")
instance_variable_set(:"@volume_#{volume}", slider(range: 0.0..1.0, value: config_value))
- instance_variable_get(:"@volume_#{volume}").subscribe(:changed) do |sender, value|
- instance_variable_get(:"@volume_#{volume}_label").value = "%03.2f%%" % [value * 100.0]
+ instance_variable_get(:"@volume_#{volume}").subscribe(:changed) do |_sender, value|
+ instance_variable_get(:"@volume_#{volume}_label").value = format("%03.2f%%", value * 100.0)
window.config[:options, :audio, :"volume_#{volume}"] = value
end
- instance_variable_set(:"@volume_#{volume}_label", label("%03.2f%%" % [config_value * 100.0]))
+ instance_variable_set(:"@volume_#{volume}_label", label(format("%03.2f%%", config_value * 100.0)))
end
end
end
@@ -130,7 +136,7 @@ class IMICFPS
InputMapper.keymap.each do |key, values|
flow do
- label "#{key}"
+ label key.to_s
[values].flatten.each do |value|
if name = Gosu.button_name(value)
@@ -156,7 +162,7 @@ class IMICFPS
flow do
label "Field of View".ljust(longest_string.length, " ")
@fov = slider range: 70.0..110.0
- @fov.subscribe(:changed) do |sender, value|
+ @fov.subscribe(:changed) do |_sender, value|
@fov_label.value = value.round.to_s
end
@fov_label = label "90.0"
@@ -164,7 +170,7 @@ class IMICFPS
flow do
label "Detail".ljust(longest_string.length, " ")
- list_box items: [:high, :medium, :low], width: 250
+ list_box items: %i[high medium low], width: 250
end
label ""
@@ -177,27 +183,27 @@ class IMICFPS
stack do
flow do
label "Geometry Detail".ljust(longest_string.length, " ")
- list_box items: [:high, :medium, :low], width: 250
+ list_box items: %i[high medium low], width: 250
end
flow do
label "Shadow Detail".ljust(longest_string.length, " ")
- list_box items: [:high, :medium, :low, :off], width: 250
+ list_box items: %i[high medium low off], width: 250
end
flow do
label "Texture Detail".ljust(longest_string.length, " ")
- list_box items: [:high, :medium, :low], width: 250
+ list_box items: %i[high medium low], width: 250
end
flow do
label "Particle Detail".ljust(longest_string.length, " ")
- list_box items: [:high, :medium, :low, :off], width: 250
+ list_box items: %i[high medium low off], width: 250
end
flow do
label "Surface Effect Detail".ljust(longest_string.length, " ")
- list_box items: [:high, :medium, :low], width: 250
+ list_box items: %i[high medium low], width: 250
end
flow do
label "Lighting Mode".ljust(longest_string.length, " ")
- list_box items: [:per_pixel, :per_vertex], width: 250
+ list_box items: %i[per_pixel per_vertex], width: 250
end
flow do
label "Texture Filtering".ljust(longest_string.length, " ")
@@ -206,7 +212,7 @@ class IMICFPS
end
end
- advanced_mode.subscribe(:changed) do |element, value|
+ advanced_mode.subscribe(:changed) do |_element, value|
advanced_settings.show if value
advanced_settings.hide unless value
end
@@ -222,4 +228,4 @@ class IMICFPS
check_box "Show player names"
end
end
-end
\ No newline at end of file
+end
diff --git a/lib/ui/subcommand.rb b/lib/ui/subcommand.rb
index 7dc3b5f..b3758f5 100644
--- a/lib/ui/subcommand.rb
+++ b/lib/ui/subcommand.rb
@@ -1,4 +1,5 @@
# frozen_string_literal: true
+
class IMICFPS
class Commands
class Command
@@ -9,13 +10,11 @@ class IMICFPS
@type = type
end
- def command
- @command
- end
+ attr_reader :command
def handle(arguments, console)
if arguments.size > 1
- console.stdin("to many arguments for #{Style.highlight("#{command}")}, got #{Style.error(arguments.size)} expected #{Style.notice(1)}.")
+ console.stdin("to many arguments for #{Style.highlight(command.to_s)}, got #{Style.error(arguments.size)} expected #{Style.notice(1)}.")
return
end
@@ -23,7 +22,7 @@ class IMICFPS
when :boolean
case arguments.last
when "", nil
- var = @parent.get(command.to_sym) ? @parent.get(command.to_sym) : false
+ var = @parent.get(command.to_sym) || false
console.stdin("#{command}: #{Style.highlight(var)}")
when "on"
var = @parent.set(command.to_sym, true)
@@ -32,12 +31,12 @@ class IMICFPS
var = @parent.set(command.to_sym, false)
console.stdin("#{command} => #{Style.highlight(var)}")
else
- console.stdin("Invalid argument for #{Style.highlight("#{command}")}, got #{Style.error(arguments.last)} expected #{Style.notice("on")}, or #{Style.notice("off")}.")
+ console.stdin("Invalid argument for #{Style.highlight(command.to_s)}, got #{Style.error(arguments.last)} expected #{Style.notice('on')}, or #{Style.notice('off')}.")
end
when :string
case arguments.last
when "", nil
- var = @parent.get(command.to_sym) ? @parent.get(command.to_sym) : "\"\""
+ var = @parent.get(command.to_sym) || "\"\""
console.stdin("#{command}: #{Style.highlight(var)}")
else
var = @parent.set(command.to_sym, arguments.last)
@@ -46,7 +45,7 @@ class IMICFPS
when :integer
case arguments.last
when "", nil
- var = @parent.get(command.to_sym) ? @parent.get(command.to_sym) : "nil"
+ var = @parent.get(command.to_sym) || "nil"
console.stdin("#{command}: #{Style.highlight(var)}")
else
begin
@@ -59,7 +58,7 @@ class IMICFPS
when :decimal
case arguments.last
when "", nil
- var = @parent.get(command.to_sym) ? @parent.get(command.to_sym) : "nil"
+ var = @parent.get(command.to_sym) || "nil"
console.stdin("#{command}: #{Style.highlight(var)}")
else
begin
@@ -77,7 +76,7 @@ class IMICFPS
def values
case @type
when :boolean
- ["on", "off"]
+ %w[on off]
else
[]
end
@@ -86,16 +85,16 @@ class IMICFPS
def usage
case @type
when :boolean
- "#{Style.highlight(command)} #{Style.notice("[on|off]")}"
+ "#{Style.highlight(command)} #{Style.notice('[on|off]')}"
when :string
- "#{Style.highlight(command)} #{Style.notice("[string]")}"
+ "#{Style.highlight(command)} #{Style.notice('[string]')}"
when :integer
- "#{Style.highlight(command)} #{Style.notice("[0]")}"
+ "#{Style.highlight(command)} #{Style.notice('[0]')}"
when :decimal
- "#{Style.highlight(command)} #{Style.notice("[0.0]")}"
+ "#{Style.highlight(command)} #{Style.notice('[0.0]')}"
end
end
end
end
end
-end
\ No newline at end of file
+end
diff --git a/lib/version.rb b/lib/version.rb
index fb80609..8cf818a 100644
--- a/lib/version.rb
+++ b/lib/version.rb
@@ -1,6 +1,7 @@
# frozen_string_literal: true
+
class IMICFPS
NAME = "I-MIC FPS"
RELEASE_NAME = "InDev"
VERSION = "0.1.0"
-end
\ No newline at end of file
+end
diff --git a/lib/window.rb b/lib/window.rb
index c60f568..b970f2b 100644
--- a/lib/window.rb
+++ b/lib/window.rb
@@ -1,16 +1,16 @@
# frozen_string_literal: true
+
class IMICFPS
class Window < CyberarmEngine::Window
attr_accessor :number_of_vertices, :needs_cursor
- attr_reader :renderer, :scene, :config, :director
+ attr_reader :renderer, :scene, :config, :director, :console, :delta_time
- attr_reader :console, :delta_time
def initialize(window_width = 1280, window_height = 720, fullscreen = false)
- fps_target = (ARGV.first.to_i != 0) ? ARGV.first.to_i : 60
+ fps_target = ARGV.first.to_i != 0 ? ARGV.first.to_i : 60
if ARGV.join.include?("--native")
- super(width: Gosu.screen_width, height: Gosu.screen_height, fullscreen: true, resizable: true, update_interval: 1000.0/fps_target)
+ super(width: Gosu.screen_width, height: Gosu.screen_height, fullscreen: true, resizable: true, update_interval: 1000.0 / fps_target)
else
- super(width: window_width, height: window_height, fullscreen: fullscreen, resizable: true, update_interval: 1000.0/fps_target)
+ super(width: window_width, height: window_height, fullscreen: fullscreen, resizable: true, update_interval: 1000.0 / fps_target)
end
$window = self
I18n.load_path << Dir["#{GAME_ROOT_PATH}/locales/*.yml"]
@@ -19,14 +19,14 @@ class IMICFPS
I18n.locale = language if I18n.available_locales.include?(language)
@needs_cursor = false
- @cursor = Gosu::Image.new(IMICFPS::GAME_ROOT_PATH + "/static/cursors/pointer.png")
+ @cursor = Gosu::Image.new("#{IMICFPS::GAME_ROOT_PATH}/static/cursors/pointer.png")
@number_of_vertices = 0
self.caption = "#{IMICFPS::NAME} v#{IMICFPS::VERSION} (#{IMICFPS::RELEASE_NAME})"
@director = Networking::Director.new
- @config = CyberarmEngine::ConfigFile.new(file: IMICFPS::GAME_ROOT_PATH + "/data/config.json")
+ @config = CyberarmEngine::ConfigFile.new(file: "#{IMICFPS::GAME_ROOT_PATH}/data/config.json")
@show_console = false
@console = Console.new
Commands::Command.setup
@@ -37,7 +37,7 @@ class IMICFPS
@scene = TurnTableScene.new
@overlay = Overlay.new
- @canvas_size = Vector.new(self.width, self.height)
+ @canvas_size = Vector.new(width, height)
at_exit do
@config.save!
@@ -49,7 +49,7 @@ class IMICFPS
end
def preload_default_shaders
- shaders = ["g_buffer", "lighting"]
+ shaders = %w[g_buffer lighting]
shaders.each do |shader|
Shader.new(
name: shader,
@@ -71,9 +71,9 @@ class IMICFPS
@overlay.draw
draw_cursor if needs_cursor
- _canvas_size = Vector.new(self.width, self.height)
+ _canvas_size = Vector.new(width, height)
if @canvas_size != _canvas_size
- @renderer = Renderer.new#@renderer.canvas_size_changed
+ @renderer = Renderer.new # @renderer.canvas_size_changed
@canvas_size = _canvas_size
end
end
diff --git a/new_server_test.rb b/new_server_test.rb
index e9f48d4..35032e1 100644
--- a/new_server_test.rb
+++ b/new_server_test.rb
@@ -1,17 +1,18 @@
# frozen_string_literal: true
+
def require_all(directory)
files = Dir["#{directory}/**/*.rb"].sort!
- begin
+ loop do
failed = []
first_name_error = nil
files.each do |file|
begin
require_relative file
- rescue NameError => name_error
+ rescue NameError => e
failed << file
- first_name_error ||= name_error
+ first_name_error ||= e
end
end
@@ -20,7 +21,8 @@ def require_all(directory)
else
files = failed
end
- end until(failed.empty?)
+ break if failed.empty?
+ end
end
require "socket"
diff --git a/rakelib/release.rake b/rakelib/release.rake
index 11f50c2..4812a1b 100644
--- a/rakelib/release.rake
+++ b/rakelib/release.rake
@@ -1,14 +1,15 @@
# frozen_string_literal: true
+
PACKAGING_LOCKFILE = File.expand_path("i-mic-fps-packaging.lock", Dir.tmpdir)
GITHUB_API_URL = "https://api.github.com/repos/cyberarm/i-mic-fps"
USERAGENT = "cyberarm +i-mic-fps"
-DEFAULT_HEADERS = {"Authorization": "token #{ENV["GITHUB_TOKEN"]}", "User-Agent": USERAGENT}
+DEFAULT_HEADERS = { "Authorization": "token #{ENV['GITHUB_TOKEN']}", "User-Agent": USERAGENT }.freeze
def sh_with_status(command)
- outbuf = IO.popen(command, :err => [:child, :out], &:read)
- status = $?
+ outbuf = IO.popen(command, err: %i[child out], &:read)
+ status = $CHILD_STATUS
- return [outbuf, status]
+ [outbuf, status]
end
def version
@@ -20,7 +21,7 @@ def version_tag
end
def release_name
- "#{IMICFPS::NAME}_#{version}".downcase.gsub(/[\ |\-|\.]/, "_")
+ "#{IMICFPS::NAME}_#{version}".downcase.gsub(/[\ |\-|.]/, "_")
end
def clean?
@@ -46,22 +47,24 @@ end
def already_tagged?
return false unless sh_with_status("git tag")[0].split(/\n/).include?(version_tag)
+
abort " Tag #{version_tag} has already been created."
end
def create_lockfile
File.open(PACKAGING_LOCKFILE, "w") { |f| f.write version }
end
+
def remove_lockfile
File.delete(PACKAGING_LOCKFILE)
- rescue Errno::ENOENT
+rescue Errno::ENOENT
end
def create_directory(dir)
levels = dir.split("/")
location = ""
levels.each do |level|
- location +="#{level}/"
+ location += "#{level}/"
mkdir_p location unless File.exist?(location)
end
end
@@ -82,7 +85,7 @@ def create_archive(folder, archive)
abort " Archive already exists!" if File.exist?(archive)
Zip::File.open(archive, Zip::File::CREATE) do |zipfile|
Dir["#{folder}/**/**"].each do |file|
- zipfile.add(file.sub(folder + '/', ''), file)
+ zipfile.add(file.sub("#{folder}/", ""), file)
end
end
end
@@ -92,8 +95,8 @@ def get_release
request = Excon.get(url, headers: DEFAULT_HEADERS)
if request.status == 200
- release = JSON.parse(request.body).find { |r| r["tag_name"] == version_tag }
- return release
+ JSON.parse(request.body).find { |r| r["tag_name"] == version_tag }
+
else
abort " Getting repo releases failed! (#{request.status})"
end
@@ -104,7 +107,7 @@ def upload_asset(asset)
abort " GITHUB_TOKEN not set!" unless github_token
release = get_release
- upload_url = release["upload_url"].split("{?").first + "?name=#{asset.split("/").last}"
+ upload_url = release["upload_url"].split("{?").first + "?name=#{asset.split('/').last}"
file = File.read(asset)
@@ -124,7 +127,8 @@ namespace "game" do
"release:package",
"release:patch",
"release:create_archive",
- "release:deploy"] do
+ "release:deploy"
+ ] do
end
desc "Check working directory for uncommited changes"
@@ -198,4 +202,4 @@ namespace "game" do
puts "Done."
end
end
-end
\ No newline at end of file
+end
diff --git a/rakelib/test.rake b/rakelib/test.rake
index 637e8f6..411cc72 100644
--- a/rakelib/test.rake
+++ b/rakelib/test.rake
@@ -1,4 +1,5 @@
# frozen_string_literal: true
+
desc "Run tests"
task :default do
puts "No tests implemented yet!"