mirror of
https://github.com/cyberarm/i-mic-fps.git
synced 2025-12-15 15:42:35 +00:00
Moved menu files to be under /ui directory, added support for commands to Console!
This commit is contained in:
17
i-mic-fps.rb
17
i-mic-fps.rb
@@ -63,6 +63,10 @@ end
|
|||||||
|
|
||||||
$debug = ARGV.join.include?("--debug") ? true : false
|
$debug = ARGV.join.include?("--debug") ? true : false
|
||||||
|
|
||||||
|
class IMICFPS
|
||||||
|
GAME_ROOT_PATH = File.expand_path(File.dirname(__FILE__))
|
||||||
|
end
|
||||||
|
|
||||||
include CyberarmEngine
|
include CyberarmEngine
|
||||||
require_relative "lib/version"
|
require_relative "lib/version"
|
||||||
require_relative "lib/common_methods"
|
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/renderer/bounding_box_renderer"
|
||||||
|
|
||||||
require_relative "lib/states/game_state"
|
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/game"
|
||||||
require_relative "lib/states/game_states/loading_state"
|
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/entity"
|
||||||
require_relative "lib/objects/model_loader"
|
require_relative "lib/objects/model_loader"
|
||||||
|
|||||||
45
lib/ui/command.rb
Normal file
45
lib/ui/command.rb
Normal file
@@ -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 <c=ff5555>#{command}</c> 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
|
||||||
24
lib/ui/commands/help_command.rb
Normal file
24
lib/ui/commands/help_command.rb
Normal file
@@ -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
|
||||||
@@ -62,8 +62,9 @@ class IMICFPS
|
|||||||
case id
|
case id
|
||||||
when Gosu::KbEnter, Gosu::KbReturn
|
when Gosu::KbEnter, Gosu::KbReturn
|
||||||
return unless @text_input.text.length > 0
|
return unless @text_input.text.length > 0
|
||||||
@history.text += "\n> #{@text_input.text}"
|
@history.text += "\n<c=999999>> #{@text_input.text}</c>"
|
||||||
update_history
|
update_history
|
||||||
|
handle_command
|
||||||
@text_input.text = ""
|
@text_input.text = ""
|
||||||
when Gosu::KbBacktick
|
when Gosu::KbBacktick
|
||||||
# Removed backtick character from input
|
# Removed backtick character from input
|
||||||
@@ -82,6 +83,20 @@ class IMICFPS
|
|||||||
@history.y = @history_height - (@history.text.lines.count * (@history.textobject.height))
|
@history.y = @history_height - (@history.text.lines.count * (@history.textobject.height))
|
||||||
end
|
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
|
def focus
|
||||||
@active_text_input = window.text_input
|
@active_text_input = window.text_input
|
||||||
window.text_input = @text_input
|
window.text_input = @text_input
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
class IMICFPS
|
class IMICFPS
|
||||||
class Menu < GameState
|
class Menu < IMICFPS::GameState
|
||||||
def initialize(*args)
|
def initialize(*args)
|
||||||
@elements = []
|
@elements = []
|
||||||
@size = 50
|
@size = 50
|
||||||
@@ -1,5 +1,6 @@
|
|||||||
class IMICFPS
|
class IMICFPS
|
||||||
GRAVITY = 9.8 # m/s
|
GRAVITY = 9.8 # m/s
|
||||||
|
|
||||||
class Window < CyberarmEngine::Engine
|
class Window < CyberarmEngine::Engine
|
||||||
attr_accessor :number_of_vertices, :needs_cursor
|
attr_accessor :number_of_vertices, :needs_cursor
|
||||||
attr_reader :camera
|
attr_reader :camera
|
||||||
@@ -19,6 +20,7 @@ class IMICFPS
|
|||||||
|
|
||||||
@show_console = false
|
@show_console = false
|
||||||
@console = Console.new
|
@console = Console.new
|
||||||
|
Commands::Command.setup
|
||||||
|
|
||||||
push_state(MainMenu)
|
push_state(MainMenu)
|
||||||
end
|
end
|
||||||
|
|||||||
Reference in New Issue
Block a user