cyberarm_engine 0.16.0 → 0.19.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +5 -4
- data/assets/textures/logo.png +0 -0
- data/cyberarm_engine.gemspec +2 -2
- data/lib/cyberarm_engine/animator.rb +172 -9
- data/lib/cyberarm_engine/background_nine_slice.rb +51 -34
- data/lib/cyberarm_engine/builtin/intro_state.rb +131 -0
- data/lib/cyberarm_engine/common.rb +19 -2
- data/lib/cyberarm_engine/console/command.rb +158 -0
- data/lib/cyberarm_engine/console/commands/help_command.rb +43 -0
- data/lib/cyberarm_engine/console/subcommand.rb +100 -0
- data/lib/cyberarm_engine/console.rb +248 -0
- data/lib/cyberarm_engine/game_state.rb +5 -0
- data/lib/cyberarm_engine/model.rb +6 -1
- data/lib/cyberarm_engine/opengl/perspective_camera.rb +2 -2
- data/lib/cyberarm_engine/opengl/renderer/opengl_renderer.rb +9 -0
- data/lib/cyberarm_engine/opengl/texture.rb +1 -1
- data/lib/cyberarm_engine/text.rb +82 -45
- data/lib/cyberarm_engine/ui/dsl.rb +3 -2
- data/lib/cyberarm_engine/ui/element.rb +236 -47
- data/lib/cyberarm_engine/ui/elements/button.rb +0 -63
- data/lib/cyberarm_engine/ui/elements/check_box.rb +4 -1
- data/lib/cyberarm_engine/ui/elements/container.rb +65 -35
- data/lib/cyberarm_engine/ui/elements/edit_line.rb +20 -13
- data/lib/cyberarm_engine/ui/elements/text_block.rb +13 -7
- data/lib/cyberarm_engine/ui/event.rb +9 -2
- data/lib/cyberarm_engine/ui/gui_state.rb +37 -4
- data/lib/cyberarm_engine/ui/style.rb +14 -3
- data/lib/cyberarm_engine/ui/theme.rb +26 -1
- data/lib/cyberarm_engine/version.rb +1 -1
- data/lib/cyberarm_engine/window.rb +7 -1
- data/lib/cyberarm_engine.rb +11 -4
- metadata +12 -7
- data/lib/cyberarm_engine/ui/elements/label.rb +0 -156
@@ -0,0 +1,158 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module CyberarmEngine
|
4
|
+
class Console
|
5
|
+
module Style
|
6
|
+
def self.error(string)
|
7
|
+
"<c=ff5555>#{string}</c>"
|
8
|
+
end
|
9
|
+
|
10
|
+
def self.warn(string)
|
11
|
+
"<c=ff7700>#{string}</c>"
|
12
|
+
end
|
13
|
+
|
14
|
+
def self.notice(string)
|
15
|
+
"<c=55ff55>#{string}</c>"
|
16
|
+
end
|
17
|
+
|
18
|
+
def self.highlight(string, color = "5555ff")
|
19
|
+
"<c=#{color}>#{string}</c>"
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
class Command
|
24
|
+
def self.inherited(subclass)
|
25
|
+
@list ||= []
|
26
|
+
@commands ||= []
|
27
|
+
@list << subclass
|
28
|
+
end
|
29
|
+
|
30
|
+
def self.setup
|
31
|
+
@list ||= []
|
32
|
+
@commands = []
|
33
|
+
@list.each do |subclass|
|
34
|
+
cmd = subclass.new
|
35
|
+
if @commands.detect { |c| c.command == cmd.command }
|
36
|
+
raise "Command '#{cmd.command}' from '#{cmd.class}' already exists!"
|
37
|
+
end
|
38
|
+
|
39
|
+
@commands << cmd
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
def self.use(command, arguments, console)
|
44
|
+
found_command = @commands.detect { |cmd| cmd.command == command.to_sym }
|
45
|
+
|
46
|
+
if found_command
|
47
|
+
found_command.handle(arguments, console)
|
48
|
+
else
|
49
|
+
console.stdin("Command #{Style.error(command)} not found.")
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
def self.find(command)
|
54
|
+
@commands.detect { |cmd| cmd.command == command.to_sym }
|
55
|
+
end
|
56
|
+
|
57
|
+
def self.list_commands
|
58
|
+
@commands
|
59
|
+
end
|
60
|
+
|
61
|
+
def initialize
|
62
|
+
@store = {}
|
63
|
+
@subcommands = []
|
64
|
+
|
65
|
+
setup
|
66
|
+
end
|
67
|
+
|
68
|
+
def setup
|
69
|
+
end
|
70
|
+
|
71
|
+
def subcommand(command, type)
|
72
|
+
if @subcommands.detect { |subcmd| subcmd.command == command.to_sym }
|
73
|
+
raise "Subcommand '#{command}' for '#{self.command}' already exists!"
|
74
|
+
end
|
75
|
+
|
76
|
+
@subcommands << SubCommand.new(self, command, type)
|
77
|
+
end
|
78
|
+
|
79
|
+
def get(key)
|
80
|
+
@store[key]
|
81
|
+
end
|
82
|
+
|
83
|
+
def set(key, value)
|
84
|
+
@store[key] = value
|
85
|
+
end
|
86
|
+
|
87
|
+
def group
|
88
|
+
raise NotImplementedError
|
89
|
+
end
|
90
|
+
|
91
|
+
def command
|
92
|
+
raise NotImplementedError
|
93
|
+
end
|
94
|
+
|
95
|
+
def handle(arguments, console)
|
96
|
+
raise NotImplementedError
|
97
|
+
end
|
98
|
+
|
99
|
+
def autocomplete(console)
|
100
|
+
split = console.text_input.text.split(" ")
|
101
|
+
|
102
|
+
if @subcommands.size.positive?
|
103
|
+
if !console.text_input.text.end_with?(" ") && split.size == 2
|
104
|
+
list = console.abbrev_search(@subcommands.map { |cmd| cmd.command.to_s }, split.last)
|
105
|
+
|
106
|
+
if list.size == 1
|
107
|
+
console.text_input.text = "#{split.first} #{list.first} "
|
108
|
+
else
|
109
|
+
return unless list.size.positive?
|
110
|
+
|
111
|
+
console.stdin(list.map { |cmd| Console::Style.highlight(cmd) }.join(", ").to_s)
|
112
|
+
end
|
113
|
+
|
114
|
+
# List available options on subcommand
|
115
|
+
elsif (console.text_input.text.end_with?(" ") && split.size == 2) || !console.text_input.text.end_with?(" ") && split.size == 3
|
116
|
+
subcommand = @subcommands.detect { |cmd| cmd.command.to_s == (split[1]) }
|
117
|
+
|
118
|
+
if subcommand
|
119
|
+
if split.size == 2
|
120
|
+
console.stdin("Available options: #{subcommand.values.map { |value| Console::Style.highlight(value) }.join(',')}")
|
121
|
+
else
|
122
|
+
list = console.abbrev_search(subcommand.values, split.last)
|
123
|
+
if list.size == 1
|
124
|
+
console.text_input.text = "#{split.first} #{split[1]} #{list.first} "
|
125
|
+
elsif list.size.positive?
|
126
|
+
console.stdin("Available options: #{list.map { |value| Console::Style.highlight(value) }.join(',')}")
|
127
|
+
end
|
128
|
+
end
|
129
|
+
end
|
130
|
+
|
131
|
+
# List available subcommands if command was entered and has only a space after it
|
132
|
+
elsif console.text_input.text.end_with?(" ") && split.size == 1
|
133
|
+
console.stdin("Available subcommands: #{@subcommands.map { |cmd| Console::Style.highlight(cmd.command) }.join(', ')}")
|
134
|
+
end
|
135
|
+
end
|
136
|
+
end
|
137
|
+
|
138
|
+
def handle_subcommand(arguments, console)
|
139
|
+
if arguments.size.zero?
|
140
|
+
console.stdin(usage)
|
141
|
+
return
|
142
|
+
end
|
143
|
+
subcommand = arguments.delete_at(0)
|
144
|
+
|
145
|
+
found_command = @subcommands.detect { |cmd| cmd.command == subcommand.to_sym }
|
146
|
+
if found_command
|
147
|
+
found_command.handle(arguments, console)
|
148
|
+
else
|
149
|
+
console.stdin("Unknown subcommand #{Style.error(subcommand)} for #{Style.highlight(command)}")
|
150
|
+
end
|
151
|
+
end
|
152
|
+
|
153
|
+
def usage
|
154
|
+
raise NotImplementedError
|
155
|
+
end
|
156
|
+
end
|
157
|
+
end
|
158
|
+
end
|
@@ -0,0 +1,43 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module CyberarmEngine
|
4
|
+
class Console
|
5
|
+
class HelpCommand < CyberarmEngine::Console::Command
|
6
|
+
def group
|
7
|
+
:global
|
8
|
+
end
|
9
|
+
|
10
|
+
def command
|
11
|
+
:help
|
12
|
+
end
|
13
|
+
|
14
|
+
def handle(arguments, console)
|
15
|
+
console.stdin(usage(arguments.first))
|
16
|
+
end
|
17
|
+
|
18
|
+
def autocomplete(console)
|
19
|
+
split = console.text_input.text.split(" ")
|
20
|
+
if !console.text_input.text.start_with?(" ") && split.size == 2
|
21
|
+
list = console.abbrev_search(Command.list_commands.map { |cmd| cmd.command.to_s }, split.last)
|
22
|
+
if list.size == 1
|
23
|
+
console.text_input.text = "#{split.first} #{list.first} "
|
24
|
+
elsif list.size > 1
|
25
|
+
console.stdin(list.map { |cmd| Style.highlight(cmd) }.join(", "))
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
def usage(command = nil)
|
31
|
+
if command
|
32
|
+
if cmd = Command.find(command)
|
33
|
+
cmd.usage
|
34
|
+
else
|
35
|
+
"#{Style.error(command)} is not a command"
|
36
|
+
end
|
37
|
+
else
|
38
|
+
"Available commands:\n#{Command.list_commands.map { |cmd| Style.highlight(cmd.command).to_s }.join(', ')}"
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
@@ -0,0 +1,100 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module CyberarmEngine
|
4
|
+
class Console
|
5
|
+
class Command
|
6
|
+
class SubCommand
|
7
|
+
def initialize(parent, command, type)
|
8
|
+
@parent = parent
|
9
|
+
@command = command
|
10
|
+
@type = type
|
11
|
+
end
|
12
|
+
|
13
|
+
attr_reader :command
|
14
|
+
|
15
|
+
def handle(arguments, console)
|
16
|
+
if arguments.size > 1
|
17
|
+
console.stdin("to many arguments for #{Style.highlight(command.to_s)}, got #{Style.error(arguments.size)} expected #{Style.notice(1)}.")
|
18
|
+
return
|
19
|
+
end
|
20
|
+
|
21
|
+
case @type
|
22
|
+
when :boolean
|
23
|
+
case arguments.last
|
24
|
+
when "", nil
|
25
|
+
var = @parent.get(command.to_sym) || false
|
26
|
+
console.stdin("#{command}: #{Style.highlight(var)}")
|
27
|
+
when "on"
|
28
|
+
var = @parent.set(command.to_sym, true)
|
29
|
+
console.stdin("#{command} => #{Style.highlight(var)}")
|
30
|
+
when "off"
|
31
|
+
var = @parent.set(command.to_sym, false)
|
32
|
+
console.stdin("#{command} => #{Style.highlight(var)}")
|
33
|
+
else
|
34
|
+
console.stdin("Invalid argument for #{Style.highlight(command.to_s)}, got #{Style.error(arguments.last)} expected #{Style.notice('on')}, or #{Style.notice('off')}.")
|
35
|
+
end
|
36
|
+
when :string
|
37
|
+
case arguments.last
|
38
|
+
when "", nil
|
39
|
+
var = @parent.get(command.to_sym) || "\"\""
|
40
|
+
console.stdin("#{command}: #{Style.highlight(var)}")
|
41
|
+
else
|
42
|
+
var = @parent.set(command.to_sym, arguments.last)
|
43
|
+
console.stdin("#{command} => #{Style.highlight(var)}")
|
44
|
+
end
|
45
|
+
when :integer
|
46
|
+
case arguments.last
|
47
|
+
when "", nil
|
48
|
+
var = @parent.get(command.to_sym) || "nil"
|
49
|
+
console.stdin("#{command}: #{Style.highlight(var)}")
|
50
|
+
else
|
51
|
+
begin
|
52
|
+
var = @parent.set(command.to_sym, Integer(arguments.last))
|
53
|
+
console.stdin("#{command} => #{Style.highlight(var)}")
|
54
|
+
rescue ArgumentError
|
55
|
+
console.stdin("Error: #{Style.error("Expected an integer, got '#{arguments.last}'")}")
|
56
|
+
end
|
57
|
+
end
|
58
|
+
when :decimal
|
59
|
+
case arguments.last
|
60
|
+
when "", nil
|
61
|
+
var = @parent.get(command.to_sym) || "nil"
|
62
|
+
console.stdin("#{command}: #{Style.highlight(var)}")
|
63
|
+
else
|
64
|
+
begin
|
65
|
+
var = @parent.set(command.to_sym, Float(arguments.last))
|
66
|
+
console.stdin("#{command} => #{Style.highlight(var)}")
|
67
|
+
rescue ArgumentError
|
68
|
+
console.stdin("Error: #{Style.error("Expected a decimal or integer, got '#{arguments.last}'")}")
|
69
|
+
end
|
70
|
+
end
|
71
|
+
else
|
72
|
+
raise RuntimeError
|
73
|
+
end
|
74
|
+
end
|
75
|
+
|
76
|
+
def values
|
77
|
+
case @type
|
78
|
+
when :boolean
|
79
|
+
%w[on off]
|
80
|
+
else
|
81
|
+
[]
|
82
|
+
end
|
83
|
+
end
|
84
|
+
|
85
|
+
def usage
|
86
|
+
case @type
|
87
|
+
when :boolean
|
88
|
+
"#{Style.highlight(command)} #{Style.notice('[on|off]')}"
|
89
|
+
when :string
|
90
|
+
"#{Style.highlight(command)} #{Style.notice('[string]')}"
|
91
|
+
when :integer
|
92
|
+
"#{Style.highlight(command)} #{Style.notice('[0]')}"
|
93
|
+
when :decimal
|
94
|
+
"#{Style.highlight(command)} #{Style.notice('[0.0]')}"
|
95
|
+
end
|
96
|
+
end
|
97
|
+
end
|
98
|
+
end
|
99
|
+
end
|
100
|
+
end
|
@@ -0,0 +1,248 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module CyberarmEngine
|
4
|
+
class Console
|
5
|
+
Z = 100_000
|
6
|
+
PADDING = 2
|
7
|
+
include Common
|
8
|
+
|
9
|
+
attr_reader :text_input
|
10
|
+
|
11
|
+
def initialize(font: Gosu.default_font_name)
|
12
|
+
@text_input = Gosu::TextInput.new
|
13
|
+
@width = window.width / 4 * 3
|
14
|
+
@height = window.height / 4 * 3
|
15
|
+
|
16
|
+
@input = Text.new("", x: 4, y: @height - (PADDING * 2), z: Console::Z + 1, font: font)
|
17
|
+
@input.y -= @input.height
|
18
|
+
|
19
|
+
@history = Text.new("", x: 4, z: Console::Z + 1, font: font, border: true, border_color: Gosu::Color::BLACK)
|
20
|
+
update_history_y
|
21
|
+
|
22
|
+
@command_history = []
|
23
|
+
@command_history_index = 0
|
24
|
+
|
25
|
+
@memory = ""
|
26
|
+
|
27
|
+
@background_color = Gosu::Color.rgba(0, 0, 0, 200)
|
28
|
+
@foreground_color = Gosu::Color.rgba(100, 100, 100, 100)
|
29
|
+
@input_color = Gosu::Color.rgba(100, 100, 100, 200)
|
30
|
+
|
31
|
+
@showing_cursor = false
|
32
|
+
@active_text_input = nil
|
33
|
+
|
34
|
+
@show_caret = true
|
35
|
+
@caret_last_change = Gosu.milliseconds
|
36
|
+
@caret_interval = 250
|
37
|
+
@caret_color = Gosu::Color::WHITE
|
38
|
+
@selection_color = Gosu::Color.new(0x5522ff22)
|
39
|
+
end
|
40
|
+
|
41
|
+
def draw
|
42
|
+
# Background/Border
|
43
|
+
draw_rect(0, 0, @width, @height, @background_color, Console::Z)
|
44
|
+
# Foregound/History
|
45
|
+
draw_rect(PADDING, PADDING, @width - (PADDING * 2), @height - (PADDING * 2), @foreground_color, Console::Z)
|
46
|
+
# Text bar
|
47
|
+
draw_rect(2, @input.y, @width - (PADDING * 2), @input.height, @input_color, Console::Z)
|
48
|
+
|
49
|
+
@history.draw
|
50
|
+
@input.draw
|
51
|
+
# Caret
|
52
|
+
if @show_caret
|
53
|
+
draw_rect(@input.x + caret_from_left, @input.y, Console::PADDING, @input.height, @caret_color, Console::Z + 2)
|
54
|
+
end
|
55
|
+
# Caret selection
|
56
|
+
if caret_start != caret_end
|
57
|
+
if caret_start < @text_input.selection_start
|
58
|
+
draw_rect(@input.x + caret_from_left, @input.y, caret_selection_width, @input.height, @selection_color, Console::Z)
|
59
|
+
else
|
60
|
+
draw_rect((@input.x + caret_from_left) - caret_selection_width, @input.y, caret_selection_width, @input.height, @selection_color, Console::Z)
|
61
|
+
end
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
65
|
+
def caret_from_left
|
66
|
+
return 0 if @text_input.caret_pos.zero?
|
67
|
+
|
68
|
+
@input.textobject.text_width(@text_input.text[0..@text_input.caret_pos - 1])
|
69
|
+
end
|
70
|
+
|
71
|
+
def caret_selection_width
|
72
|
+
@input.textobject.text_width(@text_input.text[caret_start..(caret_end - 1)])
|
73
|
+
end
|
74
|
+
|
75
|
+
def caret_pos
|
76
|
+
@text_input.caret_pos
|
77
|
+
end
|
78
|
+
|
79
|
+
def caret_start
|
80
|
+
@text_input.selection_start < @text_input.caret_pos ? @text_input.selection_start : @text_input.caret_pos
|
81
|
+
end
|
82
|
+
|
83
|
+
def caret_end
|
84
|
+
@text_input.selection_start > @text_input.caret_pos ? @text_input.selection_start : @text_input.caret_pos
|
85
|
+
end
|
86
|
+
|
87
|
+
def update
|
88
|
+
if Gosu.milliseconds - @caret_last_change >= @caret_interval
|
89
|
+
@caret_last_change = Gosu.milliseconds
|
90
|
+
@show_caret = !@show_caret
|
91
|
+
end
|
92
|
+
|
93
|
+
if @width != window.width || @height != @height
|
94
|
+
@width = window.width / 4 * 3
|
95
|
+
@height = window.height / 4 * 3
|
96
|
+
|
97
|
+
@input.y = @height - (PADDING * 2 + @input.height)
|
98
|
+
update_history_y
|
99
|
+
end
|
100
|
+
|
101
|
+
@input.text = @text_input.text
|
102
|
+
end
|
103
|
+
|
104
|
+
def button_down(id)
|
105
|
+
case id
|
106
|
+
when Gosu::KbEnter, Gosu::KbReturn
|
107
|
+
return unless @text_input.text.length.positive?
|
108
|
+
|
109
|
+
@history.text += "\n<c=999999>> #{@text_input.text}</c>"
|
110
|
+
@command_history << @text_input.text
|
111
|
+
@command_history_index = @command_history.size
|
112
|
+
update_history_y
|
113
|
+
handle_command
|
114
|
+
@text_input.text = ""
|
115
|
+
|
116
|
+
when Gosu::KbUp
|
117
|
+
@command_history_index -= 1
|
118
|
+
@command_history_index = 0 if @command_history_index.negative?
|
119
|
+
@text_input.text = @command_history[@command_history_index]
|
120
|
+
|
121
|
+
when Gosu::KbDown
|
122
|
+
@command_history_index += 1
|
123
|
+
if @command_history_index > @command_history.size - 1
|
124
|
+
@text_input.text = "" unless @command_history_index > @command_history.size
|
125
|
+
@command_history_index = @command_history.size
|
126
|
+
else
|
127
|
+
@text_input.text = @command_history[@command_history_index]
|
128
|
+
end
|
129
|
+
|
130
|
+
when Gosu::KbTab
|
131
|
+
split = @text_input.text.split(" ")
|
132
|
+
|
133
|
+
if !@text_input.text.end_with?(" ") && split.size == 1
|
134
|
+
list = abbrev_search(Console::Command.list_commands.map { |cmd| cmd.command.to_s }, @text_input.text)
|
135
|
+
|
136
|
+
if list.size == 1
|
137
|
+
@text_input.text = "#{list.first} "
|
138
|
+
elsif list.size.positive?
|
139
|
+
stdin("\n#{list.map { |cmd| Console::Style.highlight(cmd) }.join(', ')}")
|
140
|
+
end
|
141
|
+
elsif split.size.positive? && cmd = Console::Command.find(split.first)
|
142
|
+
cmd.autocomplete(self)
|
143
|
+
end
|
144
|
+
|
145
|
+
when Gosu::KbBacktick
|
146
|
+
# Remove backtick character from input
|
147
|
+
@text_input.text = if @text_input.text.size > 1
|
148
|
+
@text_input.text[0..@text_input.text.size - 2]
|
149
|
+
else
|
150
|
+
""
|
151
|
+
end
|
152
|
+
|
153
|
+
# Copy
|
154
|
+
when Gosu::KbC
|
155
|
+
if control_down? && shift_down?
|
156
|
+
@memory = @text_input.text[caret_start..caret_end - 1] if caret_start != caret_end
|
157
|
+
p @memory
|
158
|
+
elsif control_down?
|
159
|
+
@text_input.text = ""
|
160
|
+
end
|
161
|
+
|
162
|
+
# Paste
|
163
|
+
when Gosu::KbV
|
164
|
+
if control_down? && shift_down?
|
165
|
+
string = @text_input.text.chars.insert(caret_pos, @memory).join
|
166
|
+
_caret_pos = caret_pos
|
167
|
+
@text_input.text = string
|
168
|
+
@text_input.caret_pos = _caret_pos + @memory.length
|
169
|
+
@text_input.selection_start = _caret_pos + @memory.length
|
170
|
+
end
|
171
|
+
|
172
|
+
# Cut
|
173
|
+
when Gosu::KbX
|
174
|
+
if control_down? && shift_down?
|
175
|
+
@memory = @text_input.text[caret_start..caret_end - 1] if caret_start != caret_end
|
176
|
+
string = @text_input.text.chars
|
177
|
+
Array(caret_start..caret_end - 1).each_with_index do |i, j|
|
178
|
+
string.delete_at(i - j)
|
179
|
+
end
|
180
|
+
|
181
|
+
@text_input.text = string.join
|
182
|
+
end
|
183
|
+
|
184
|
+
# Delete word to left of caret
|
185
|
+
when Gosu::KbW
|
186
|
+
if control_down?
|
187
|
+
split = @text_input.text.split(" ")
|
188
|
+
split.delete(split.last)
|
189
|
+
@text_input.text = split.join(" ")
|
190
|
+
end
|
191
|
+
|
192
|
+
# Clear history
|
193
|
+
when Gosu::KbL
|
194
|
+
@history.text = "" if control_down?
|
195
|
+
end
|
196
|
+
end
|
197
|
+
|
198
|
+
def button_up(id)
|
199
|
+
end
|
200
|
+
|
201
|
+
def update_history_y
|
202
|
+
@history.y = @height - (PADDING * 2) - @input.height - (@history.text.lines.count * @history.textobject.height)
|
203
|
+
end
|
204
|
+
|
205
|
+
def handle_command
|
206
|
+
string = @text_input.text
|
207
|
+
split = string.split(" ")
|
208
|
+
command = split.first
|
209
|
+
arguments = split.length.positive? ? split[1..split.length - 1] : []
|
210
|
+
|
211
|
+
CyberarmEngine::Console::Command.use(command, arguments, self)
|
212
|
+
end
|
213
|
+
|
214
|
+
def abbrev_search(array, text)
|
215
|
+
return [] unless text.length.positive?
|
216
|
+
|
217
|
+
list = []
|
218
|
+
Abbrev.abbrev(array).each do |abbrev, value|
|
219
|
+
next unless abbrev&.start_with?(text)
|
220
|
+
|
221
|
+
list << value
|
222
|
+
end
|
223
|
+
|
224
|
+
list.uniq
|
225
|
+
end
|
226
|
+
|
227
|
+
def stdin(string)
|
228
|
+
@history.text += "\n#{string}"
|
229
|
+
update_history_y
|
230
|
+
end
|
231
|
+
|
232
|
+
def focus
|
233
|
+
@active_text_input = window.text_input
|
234
|
+
window.text_input = @text_input
|
235
|
+
|
236
|
+
@showing_cursor = window.needs_cursor
|
237
|
+
window.needs_cursor = true
|
238
|
+
|
239
|
+
@show_caret = true
|
240
|
+
@caret_last_change = Gosu.milliseconds
|
241
|
+
end
|
242
|
+
|
243
|
+
def blur
|
244
|
+
window.text_input = @active_text_input
|
245
|
+
window.needs_cursor = @showing_cursor
|
246
|
+
end
|
247
|
+
end
|
248
|
+
end
|
@@ -3,7 +3,8 @@ module CyberarmEngine
|
|
3
3
|
attr_accessor :objects, :materials, :vertices, :uvs, :texures, :normals, :faces, :colors, :bones, :material_file,
|
4
4
|
:current_material, :current_object, :vertex_count, :smoothing
|
5
5
|
attr_reader :position, :bounding_box, :textured_material, :file_path, :positions_buffer_id, :colors_buffer_id,
|
6
|
-
:normals_buffer_id, :uvs_buffer_id, :textures_buffer_id, :vertex_array_id, :aabb_tree
|
6
|
+
:normals_buffer_id, :uvs_buffer_id, :textures_buffer_id, :vertex_array_id, :aabb_tree,
|
7
|
+
:vertices_count
|
7
8
|
|
8
9
|
def initialize(file_path:)
|
9
10
|
@file_path = file_path
|
@@ -23,6 +24,8 @@ module CyberarmEngine
|
|
23
24
|
@bones = []
|
24
25
|
@smoothing = 0
|
25
26
|
|
27
|
+
@vertices_count = 0
|
28
|
+
|
26
29
|
@bounding_box = BoundingBox.new
|
27
30
|
start_time = Process.clock_gettime(Process::CLOCK_MONOTONIC, :float_millisecond)
|
28
31
|
|
@@ -32,6 +35,8 @@ module CyberarmEngine
|
|
32
35
|
|
33
36
|
parse(parser)
|
34
37
|
|
38
|
+
@vertices_count = @vertices.size
|
39
|
+
|
35
40
|
@has_texture = false
|
36
41
|
|
37
42
|
@materials.each do |_key, material|
|
@@ -3,8 +3,8 @@ module CyberarmEngine
|
|
3
3
|
attr_accessor :position, :orientation, :aspect_ratio, :field_of_view,
|
4
4
|
:min_view_distance, :max_view_distance
|
5
5
|
|
6
|
-
def initialize(position:, aspect_ratio:, orientation: Vector.new(0, 0,
|
7
|
-
|
6
|
+
def initialize(position:, aspect_ratio:, orientation: Vector.new(0, 0, 0),
|
7
|
+
field_of_view: 70.0, min_view_distance: 0.1, max_view_distance: 1024.0)
|
8
8
|
@position = position
|
9
9
|
@orientation = orientation
|
10
10
|
|
@@ -3,12 +3,15 @@ module CyberarmEngine
|
|
3
3
|
@@immediate_mode_warning = false
|
4
4
|
|
5
5
|
attr_accessor :show_wireframe
|
6
|
+
attr_reader :number_of_vertices
|
6
7
|
|
7
8
|
def initialize(width:, height:, show_wireframe: false)
|
8
9
|
@width = width
|
9
10
|
@height = height
|
10
11
|
@show_wireframe = show_wireframe
|
11
12
|
|
13
|
+
@number_of_vertices = 0
|
14
|
+
|
12
15
|
@g_buffer = GBuffer.new(width: @width, height: @height)
|
13
16
|
end
|
14
17
|
|
@@ -20,6 +23,8 @@ module CyberarmEngine
|
|
20
23
|
end
|
21
24
|
|
22
25
|
def render(camera, lights, entities)
|
26
|
+
@number_of_vertices = 0
|
27
|
+
|
23
28
|
glViewport(0, 0, @width, @height)
|
24
29
|
glEnable(GL_DEPTH_TEST)
|
25
30
|
|
@@ -44,6 +49,8 @@ module CyberarmEngine
|
|
44
49
|
gl_error?
|
45
50
|
draw_model(entity.model, shader)
|
46
51
|
entity.draw
|
52
|
+
|
53
|
+
@number_of_vertices += entity.model.vertices_count
|
47
54
|
end
|
48
55
|
end
|
49
56
|
|
@@ -90,6 +97,8 @@ module CyberarmEngine
|
|
90
97
|
draw_mesh(entity.model)
|
91
98
|
entity.draw
|
92
99
|
glPopMatrix
|
100
|
+
|
101
|
+
@number_of_vertices += entity.model.vertices_count
|
93
102
|
end
|
94
103
|
end
|
95
104
|
|
@@ -54,7 +54,7 @@ module CyberarmEngine
|
|
54
54
|
texture_id = tex_names_buf.unpack1("L2")
|
55
55
|
|
56
56
|
glBindTexture(GL_TEXTURE_2D, texture_id)
|
57
|
-
glTexImage2D(GL_TEXTURE_2D, 0,
|
57
|
+
glTexImage2D(GL_TEXTURE_2D, 0, GL_SRGB_ALPHA, image.width, image.height, 0, GL_RGBA, GL_UNSIGNED_BYTE, array_of_pixels)
|
58
58
|
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT)
|
59
59
|
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT)
|
60
60
|
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST) if @retro
|