diff --git a/i-mic-fps.rb b/i-mic-fps.rb
index 9f9d8f0..9a69d81 100644
--- a/i-mic-fps.rb
+++ b/i-mic-fps.rb
@@ -63,6 +63,10 @@ end
$debug = ARGV.join.include?("--debug") ? true : false
+class IMICFPS
+ GAME_ROOT_PATH = File.expand_path(File.dirname(__FILE__))
+end
+
include CyberarmEngine
require_relative "lib/version"
require_relative "lib/common_methods"
@@ -84,12 +88,17 @@ require_relative "lib/renderer/opengl_renderer"
require_relative "lib/renderer/bounding_box_renderer"
require_relative "lib/states/game_state"
-require_relative "lib/states/menu"
+require_relative "lib/ui/menu"
+
+require_relative "lib/ui/command"
+Dir.glob("#{IMICFPS::GAME_ROOT_PATH}/lib/ui/commands/*.rb").each do |cmd|
+ require_relative cmd
+end
+require_relative "lib/ui/console"
+require_relative "lib/ui/menus/main_menu"
+
require_relative "lib/states/game_states/game"
require_relative "lib/states/game_states/loading_state"
-require_relative "lib/states/menus/main_menu"
-
-require_relative "lib/ui/console"
require_relative "lib/objects/entity"
require_relative "lib/objects/model_loader"
diff --git a/lib/ui/command.rb b/lib/ui/command.rb
new file mode 100644
index 0000000..e07de8c
--- /dev/null
+++ b/lib/ui/command.rb
@@ -0,0 +1,45 @@
+class IMICFPS
+ class Commands
+ class Command
+ def self.inherited(subclass)
+ @list ||= []
+ @commands ||= []
+ @list << subclass
+ end
+
+ def self.setup
+ @list ||= []
+ @commands = []
+ @list.each do |subclass|
+ @commands << subclass.new
+ end
+ end
+
+ def self.use(command, arguments, console)
+ found_command = @commands.detect { |cmd| cmd.command == command.to_sym }
+
+ if found_command
+ found_command.handle(arguments, console)
+ else
+ console.stdin("Command #{command} not found.")
+ end
+ end
+
+ def group
+ raise NotImplementedError
+ end
+
+ def command
+ raise NotImplementedError
+ end
+
+ def handle(arguments, console)
+ raise NotImplementedError
+ end
+
+ def usage
+ raise NotImplementedError
+ end
+ end
+ end
+end
\ No newline at end of file
diff --git a/lib/ui/commands/help_command.rb b/lib/ui/commands/help_command.rb
new file mode 100644
index 0000000..6179f2b
--- /dev/null
+++ b/lib/ui/commands/help_command.rb
@@ -0,0 +1,24 @@
+class IMICFPS
+ class Commands
+ class HelpCommand < Command
+ def initialize
+ end
+
+ def group
+ :global
+ end
+
+ def command
+ :help
+ end
+
+ def handle(arguments, console)
+ console.stdin(usage)
+ end
+
+ def usage
+ "HELP\ncommand [arguments]\ncommand subcommand [argument]"
+ end
+ end
+ end
+end
\ No newline at end of file
diff --git a/lib/ui/console.rb b/lib/ui/console.rb
index 9323fac..7da4ca3 100644
--- a/lib/ui/console.rb
+++ b/lib/ui/console.rb
@@ -62,8 +62,9 @@ class IMICFPS
case id
when Gosu::KbEnter, Gosu::KbReturn
return unless @text_input.text.length > 0
- @history.text += "\n> #{@text_input.text}"
+ @history.text += "\n> #{@text_input.text}"
update_history
+ handle_command
@text_input.text = ""
when Gosu::KbBacktick
# Removed backtick character from input
@@ -82,6 +83,20 @@ class IMICFPS
@history.y = @history_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] : []
+
+ IMICFPS::Commands::Command.use(command, arguments, self)
+ end
+
+ def stdin(string)
+ @history.text += "\n#{string}"
+ update_history
+ end
+
def focus
@active_text_input = window.text_input
window.text_input = @text_input
diff --git a/lib/states/menu.rb b/lib/ui/menu.rb
similarity index 99%
rename from lib/states/menu.rb
rename to lib/ui/menu.rb
index 25a7550..aeb1c88 100644
--- a/lib/states/menu.rb
+++ b/lib/ui/menu.rb
@@ -1,5 +1,5 @@
class IMICFPS
- class Menu < GameState
+ class Menu < IMICFPS::GameState
def initialize(*args)
@elements = []
@size = 50
diff --git a/lib/states/menus/main_menu.rb b/lib/ui/menus/main_menu.rb
similarity index 100%
rename from lib/states/menus/main_menu.rb
rename to lib/ui/menus/main_menu.rb
diff --git a/lib/window.rb b/lib/window.rb
index 5ca0047..ea369f6 100644
--- a/lib/window.rb
+++ b/lib/window.rb
@@ -1,5 +1,6 @@
class IMICFPS
GRAVITY = 9.8 # m/s
+
class Window < CyberarmEngine::Engine
attr_accessor :number_of_vertices, :needs_cursor
attr_reader :camera
@@ -19,6 +20,7 @@ class IMICFPS
@show_console = false
@console = Console.new
+ Commands::Command.setup
push_state(MainMenu)
end