gameoverseer 0.1.2 → 0.1.3
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 +7 -0
- data/.gitignore +4 -3
- data/Gemfile +3 -10
- data/Gemfile.lock +30 -34
- data/README.md +51 -48
- data/gameoverseer.gemspec +2 -2
- data/lib/gameoverseer/channels/channel_manager.rb +49 -36
- data/lib/gameoverseer/clients/client_manager.rb +66 -50
- data/lib/gameoverseer/console/console.rb +206 -207
- data/lib/gameoverseer/encryption_handler/encryption_handler.rb +40 -0
- data/lib/gameoverseer/input_handler/input_handler.rb +36 -30
- data/lib/gameoverseer/messages/message_manager.rb +42 -36
- data/lib/gameoverseer/packet_handler/packet_handler.rb +35 -0
- data/lib/gameoverseer/server/renet_server.rb +126 -84
- data/lib/gameoverseer/services/service.rb +111 -90
- data/lib/gameoverseer/services/services.rb +38 -31
- data/lib/gameoverseer/version.rb +4 -4
- data/lib/gameoverseer.rb +59 -57
- data/test/test_helper.rb +1 -0
- data/test-clients/protocol-lib.rb +13 -13
- data/test-clients/test-client-alpha.rb +36 -36
- data/test-clients/test-client-beta.rb +37 -37
- data/test-clients/test-client-gamma.rb +62 -59
- metadata +23 -30
- data/lib/gameoverseer/server/encryption.rb +0 -31
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: dc1d90c8155b62e40a08e8c8987686264990b2e7
|
4
|
+
data.tar.gz: 1d2d48e384a4c599fb75bb93c6698aeaaaf5a7c8
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 520d1046beb53d18155082fad0c6c1a53997af2775f1d705343a6d9b58ad11f0b687e8a9ef25ae0976c5caaa06d113ea5ffa5df26bf23d437f324f5bd83f7f4d
|
7
|
+
data.tar.gz: 63649b30b5d5fdf85050a20aa5df3f059a6636336f495434c1fb9549bd2b58dc69d2da7a7fa5baf9c2c7658e43224bee8010c8561a270bf03f89cf5a00d3021b
|
data/.gitignore
CHANGED
@@ -1,3 +1,4 @@
|
|
1
|
-
log-*.txt
|
2
|
-
|
3
|
-
|
1
|
+
log-*.txt
|
2
|
+
.yardoc/*
|
3
|
+
protocol.md
|
4
|
+
*.gem
|
data/Gemfile
CHANGED
@@ -1,10 +1,3 @@
|
|
1
|
-
source "https://rubygems.org"
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
gem "gosu"
|
6
|
-
gem "nio4r", git: "https://github.com/MagLev/nio4r.git", branch: "johnnyt/recursive-lock-fix"
|
7
|
-
gem "celluloid"
|
8
|
-
gem "renet"# use rubygems version for now, git: "https://github.com/jvranish/rENet.git"
|
9
|
-
gem "multi_json"
|
10
|
-
gem "net-ssh"
|
1
|
+
source "https://rubygems.org"
|
2
|
+
|
3
|
+
gemspec
|
data/Gemfile.lock
CHANGED
@@ -1,34 +1,30 @@
|
|
1
|
-
|
2
|
-
remote:
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
renet (0.1
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
multi_json
|
32
|
-
net-ssh
|
33
|
-
nio4r!
|
34
|
-
renet
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
gameoverseer (0.1.2)
|
5
|
+
concurrent-ruby
|
6
|
+
gosu (= 0.10.6)
|
7
|
+
multi_json
|
8
|
+
renet
|
9
|
+
|
10
|
+
GEM
|
11
|
+
remote: https://rubygems.org/
|
12
|
+
specs:
|
13
|
+
concurrent-ruby (1.0.1)
|
14
|
+
concurrent-ruby (1.0.1-java)
|
15
|
+
gosu (0.10.6)
|
16
|
+
gosu (0.10.6-x64-mingw32)
|
17
|
+
gosu (0.10.6-x86-mingw32)
|
18
|
+
multi_json (1.11.3)
|
19
|
+
renet (0.2.1)
|
20
|
+
|
21
|
+
PLATFORMS
|
22
|
+
java
|
23
|
+
x64-mingw32
|
24
|
+
x86-mingw32
|
25
|
+
|
26
|
+
DEPENDENCIES
|
27
|
+
gameoverseer!
|
28
|
+
|
29
|
+
BUNDLED WITH
|
30
|
+
1.11.2
|
data/README.md
CHANGED
@@ -1,48 +1,51 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
```
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
```
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
1
|
+
[](https://codeclimate.com/github/cyberarm/rewrite-gameoverseer)
|
2
|
+
[](http://inch-ci.org/github/cyberarm/rewrite-gameoverseer)
|
3
|
+
|
4
|
+
# GameOverseer
|
5
|
+
A game server, designed to be able to play host to up to 4 players in Planet Wars.
|
6
|
+
|
7
|
+
This repo is a complete rewrite of [GameOverseer](https://github.com/cyberarm/gameoverseer).
|
8
|
+
|
9
|
+
# Status
|
10
|
+
In development.
|
11
|
+
Any examples given are subject to be outdated at anytime.
|
12
|
+
|
13
|
+
# Install
|
14
|
+
### Using bundler
|
15
|
+
Add this to your Gemfile
|
16
|
+
``` ruby
|
17
|
+
gem "gameoverseer"
|
18
|
+
```
|
19
|
+
and run to install.
|
20
|
+
```
|
21
|
+
bundle install
|
22
|
+
```
|
23
|
+
|
24
|
+
### Or using RubyGems
|
25
|
+
```
|
26
|
+
gem install gameoverseer
|
27
|
+
```
|
28
|
+
|
29
|
+
# Usage
|
30
|
+
``` ruby
|
31
|
+
require 'gameoverseer'
|
32
|
+
|
33
|
+
# Write a service for your game
|
34
|
+
class GameWorld < GameOverseer::Service
|
35
|
+
def setup
|
36
|
+
channel_manager.register_channel('game_world', self)
|
37
|
+
end
|
38
|
+
|
39
|
+
def process(data)
|
40
|
+
# Do stuff with the data hash.
|
41
|
+
end
|
42
|
+
|
43
|
+
def version
|
44
|
+
"1.3.75"
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
host = "localhost"
|
49
|
+
port = 56789
|
50
|
+
GameOverseer.activate(host, port)
|
51
|
+
```
|
data/gameoverseer.gemspec
CHANGED
@@ -16,8 +16,8 @@ Gem::Specification.new do |s|
|
|
16
16
|
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
17
17
|
s.require_paths = ["lib", "bin"]
|
18
18
|
|
19
|
-
s.add_runtime_dependency "gosu"
|
20
|
-
s.add_runtime_dependency "
|
19
|
+
s.add_runtime_dependency "gosu", "0.10.6"
|
20
|
+
s.add_runtime_dependency "concurrent-ruby"
|
21
21
|
s.add_runtime_dependency "renet"
|
22
22
|
s.add_runtime_dependency "multi_json"
|
23
23
|
end
|
@@ -1,36 +1,49 @@
|
|
1
|
-
module GameOverseer
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
end
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
@
|
34
|
-
|
35
|
-
|
36
|
-
|
1
|
+
module GameOverseer
|
2
|
+
|
3
|
+
# Handles routing packets to the services that subscribe to channels
|
4
|
+
class ChannelManager
|
5
|
+
CHAT = 0
|
6
|
+
WORLD= 1
|
7
|
+
HANDSHAKE = 2
|
8
|
+
FAULT=3
|
9
|
+
|
10
|
+
def initialize
|
11
|
+
@channels = {}
|
12
|
+
ChannelManager.instance = self
|
13
|
+
end
|
14
|
+
|
15
|
+
# Enables a service to subscribe to a channel
|
16
|
+
# @param channel [String]
|
17
|
+
# @param service [Service]
|
18
|
+
def register_channel(channel, service)
|
19
|
+
_channel = channel.downcase
|
20
|
+
unless @channels[_channel]
|
21
|
+
@channels[_channel] = service
|
22
|
+
GameOverseer::Console.log("ChannelManager> mapped '#{_channel}' to '#{service.class}'.")
|
23
|
+
else
|
24
|
+
raise "Could not map channel '#{_channel}' because '#{@channels[data[_channel]].class}' is already using it."
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
# Routes packet to {Service}
|
29
|
+
# @param client_id [Integer] ID of client that sent the packet
|
30
|
+
# @param data [Hash] data from packet
|
31
|
+
def send_to_service(client_id, data)
|
32
|
+
GameOverseer::Console.log("ChannelManager> sent '#{data}' to '#{@channels[data['channel']].class}'.")
|
33
|
+
@channels[data['channel']].client_id = client_id
|
34
|
+
@channels[data['channel']].process(data)
|
35
|
+
end
|
36
|
+
|
37
|
+
# Returns instance of active {ChannelManager}
|
38
|
+
# @return [ChannelManager]
|
39
|
+
def self.instance
|
40
|
+
@instance
|
41
|
+
end
|
42
|
+
|
43
|
+
# Sets instance of {ChannelManager} that is used through out the system
|
44
|
+
# @param _instance [ChannelManager]
|
45
|
+
def self.instance=_instance
|
46
|
+
@instance = _instance
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
@@ -1,50 +1,66 @@
|
|
1
|
-
module GameOverseer
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
def
|
16
|
-
@clients
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
1
|
+
module GameOverseer
|
2
|
+
|
3
|
+
# Stores client data
|
4
|
+
class ClientManager
|
5
|
+
attr_accessor :clients
|
6
|
+
|
7
|
+
def initialize
|
8
|
+
ClientManager.instance = self
|
9
|
+
@clients = []
|
10
|
+
end
|
11
|
+
|
12
|
+
# Add client to clients list
|
13
|
+
# @param client_id [Integer]
|
14
|
+
# @param ip_address [String]
|
15
|
+
def add(client_id, ip_address)
|
16
|
+
@clients << {client_id: client_id, ip_address: ip_address}
|
17
|
+
GameOverseer::Services.client_connected(client_id, ip_address)
|
18
|
+
end
|
19
|
+
|
20
|
+
# Store client specific data in a {Hash}
|
21
|
+
# @param client_id [Integer] ID of client
|
22
|
+
# @param key [String|Symbol]
|
23
|
+
# @param value What the key should equal
|
24
|
+
def update(client_id, key, value)
|
25
|
+
@clients.each do |hash|
|
26
|
+
if hash[:client_id] == client_id
|
27
|
+
hash[key] = value
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
# Gets client data
|
33
|
+
# @param client_id [Integer]
|
34
|
+
# @return [Hash] hash containing client data
|
35
|
+
def get(client_id)
|
36
|
+
_hash = @clients.detect do |hash|
|
37
|
+
if hash[:client_id] == client_id
|
38
|
+
true
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
return _hash
|
43
|
+
end
|
44
|
+
|
45
|
+
# Removes client data and disconnects client
|
46
|
+
# @param client_id [Integer] ID of client
|
47
|
+
def remove(client_id)
|
48
|
+
@clients.each do |hash|
|
49
|
+
if hash[:client_id] == client_id
|
50
|
+
@clients.delete(hash)
|
51
|
+
GameOverseer::Services.client_disconnected(client_id)
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
# @return [ClientManager]
|
57
|
+
def self.instance
|
58
|
+
@instance
|
59
|
+
end
|
60
|
+
|
61
|
+
# @param _instance [ClientManager]
|
62
|
+
def self.instance=_instance
|
63
|
+
@instance = _instance
|
64
|
+
end
|
65
|
+
end
|
66
|
+
end
|
@@ -1,207 +1,206 @@
|
|
1
|
-
module GameOverseer
|
2
|
-
class Console < Gosu::Window
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
$window =
|
11
|
-
$window.
|
12
|
-
|
13
|
-
|
14
|
-
@
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
@
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
draw_rect(0,
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
message[:
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
@
|
71
|
-
@render_caret =
|
72
|
-
|
73
|
-
|
74
|
-
@caret_tick
|
75
|
-
|
76
|
-
|
77
|
-
value
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
@log_file
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
retry_limit
|
166
|
-
|
167
|
-
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
-
|
172
|
-
|
173
|
-
|
174
|
-
|
175
|
-
|
176
|
-
|
177
|
-
|
178
|
-
|
179
|
-
|
180
|
-
|
181
|
-
|
182
|
-
|
183
|
-
|
184
|
-
|
185
|
-
|
186
|
-
|
187
|
-
|
188
|
-
|
189
|
-
|
190
|
-
|
191
|
-
|
192
|
-
|
193
|
-
|
194
|
-
|
195
|
-
|
196
|
-
|
197
|
-
|
198
|
-
|
199
|
-
|
200
|
-
|
201
|
-
|
202
|
-
|
203
|
-
|
204
|
-
|
205
|
-
|
206
|
-
|
207
|
-
end
|
1
|
+
module GameOverseer
|
2
|
+
class Console < Gosu::Window
|
3
|
+
# TODO: Use Gosu::Window.record to lower number of objects that need to be drawn
|
4
|
+
|
5
|
+
PENDING_LOG = []
|
6
|
+
def initialize
|
7
|
+
GameOverseer::Console.instance = self
|
8
|
+
super(720, 480, false)
|
9
|
+
$window = self
|
10
|
+
$window.caption = "GameOverseer Console"
|
11
|
+
$window.text_input = Gosu::TextInput.new
|
12
|
+
|
13
|
+
@default_text_instance = Gosu::Font.new($window, 'Consolas', 18)
|
14
|
+
@messages = []
|
15
|
+
setup_ui
|
16
|
+
end
|
17
|
+
|
18
|
+
def needs_cursor?
|
19
|
+
true
|
20
|
+
end
|
21
|
+
|
22
|
+
def draw
|
23
|
+
@ui_image.draw(0,0,0) if defined?(@ui_image)
|
24
|
+
end
|
25
|
+
|
26
|
+
def update
|
27
|
+
update_ui
|
28
|
+
@ui_image = $window.record(720, 480) {draw_ui}
|
29
|
+
end
|
30
|
+
|
31
|
+
def setup_ui
|
32
|
+
@current_text = text_instance
|
33
|
+
@current_text_x = 4
|
34
|
+
|
35
|
+
# Required first message
|
36
|
+
@messages << {
|
37
|
+
text: '',
|
38
|
+
instance: text_instance,
|
39
|
+
color: Gosu::Color::WHITE,
|
40
|
+
x: 4,
|
41
|
+
y: 480-26-18,
|
42
|
+
z: 1
|
43
|
+
}
|
44
|
+
|
45
|
+
submit_text("#{Time.now.strftime('%c')}", false)
|
46
|
+
end
|
47
|
+
|
48
|
+
def draw_ui
|
49
|
+
draw_rect(0,0, 720, 26, Gosu::Color.rgb(200, 75, 25))
|
50
|
+
draw_rect(0,454, 720, 480, Gosu::Color::WHITE)
|
51
|
+
text_instance.draw("GameOverSeer Console. GameOverseer version #{GameOverseer::VERSION} #{GameOverseer::RELEASE_NAME} #{@messages.count}", 4, 4, 3)
|
52
|
+
@current_text.draw("#{$window.text_input.text}", @current_text_x, 458, 3, 1, 1, Gosu::Color::BLACK)
|
53
|
+
draw_rect(@caret+@current_text_x, 456, 2.0+@caret+@current_text_x, 474, Gosu::Color::BLUE, 4) if defined?(@caret) && @render_caret
|
54
|
+
|
55
|
+
@messages.each do |message|
|
56
|
+
message[:instance].draw(message[:text],message[:x],message[:y],message[:z], 1, 1, message[:color])
|
57
|
+
p message[:color] unless message[:color] == Gosu::Color::WHITE
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
61
|
+
def update_ui
|
62
|
+
PENDING_LOG.each do |log_message|
|
63
|
+
submit_text(log_message, false) if log_message.strip.length > 0
|
64
|
+
PENDING_LOG.delete(log_message)
|
65
|
+
end
|
66
|
+
|
67
|
+
@caret = @current_text.text_width($window.text_input.text[0...$window.text_input.caret_pos])
|
68
|
+
|
69
|
+
@caret_tick = 0 unless defined?(@caret_tick)
|
70
|
+
@render_caret = true if @caret_tick < 15
|
71
|
+
@render_caret = false if @caret_tick > 30
|
72
|
+
|
73
|
+
@caret_tick = 0 unless @caret_tick < 45
|
74
|
+
@caret_tick+=1
|
75
|
+
|
76
|
+
value = @current_text.text_width($window.text_input.text)+@current_text_x
|
77
|
+
if value >= 720
|
78
|
+
@current_text_x-=4
|
79
|
+
elsif value <= 715
|
80
|
+
@current_text_x+=4 unless @current_text_x >= 4
|
81
|
+
end
|
82
|
+
end
|
83
|
+
|
84
|
+
def text_instance
|
85
|
+
@default_text_instance
|
86
|
+
end
|
87
|
+
|
88
|
+
def draw_rect(x1,y1, x2,y2, color = Gosu::Color::GRAY, z = 2)
|
89
|
+
$window.draw_quad(x1, y1, color, x2, y1, color, x1, y2, color, x2, y2, color, z)
|
90
|
+
end
|
91
|
+
|
92
|
+
def scroll(direction)
|
93
|
+
case direction
|
94
|
+
when :down
|
95
|
+
if @messages.last[:y] >= 480 - 26 - 18
|
96
|
+
@messages.each do |message|
|
97
|
+
message[:y]-=18
|
98
|
+
end
|
99
|
+
end
|
100
|
+
when :up
|
101
|
+
if @messages.first[:y] <= 26#<= 480 - 26 - 32
|
102
|
+
@messages.each do |message|
|
103
|
+
message[:y]+=18
|
104
|
+
end
|
105
|
+
end
|
106
|
+
end
|
107
|
+
end
|
108
|
+
|
109
|
+
def clean_messages(count)
|
110
|
+
if @messages.count >= count
|
111
|
+
@messages.delete(@messages.first)
|
112
|
+
end
|
113
|
+
end
|
114
|
+
|
115
|
+
def button_up(id)
|
116
|
+
case id
|
117
|
+
when 41 # Escape
|
118
|
+
# Quit?
|
119
|
+
when 40 # Enter
|
120
|
+
submit_text($window.text_input.text)
|
121
|
+
when 88 # Numpad Enter
|
122
|
+
submit_text($window.text_input.text)
|
123
|
+
when 259 # Mouse wheel
|
124
|
+
scroll(:up)
|
125
|
+
when 260 # Mouse wheel
|
126
|
+
scroll(:down)
|
127
|
+
end
|
128
|
+
end
|
129
|
+
|
130
|
+
def self.instance
|
131
|
+
@instance
|
132
|
+
end
|
133
|
+
|
134
|
+
def self.instance=_instance
|
135
|
+
@instance = _instance
|
136
|
+
end
|
137
|
+
|
138
|
+
def self.log(string)
|
139
|
+
self.log_it(string) if string.strip.length > 0
|
140
|
+
begin
|
141
|
+
GameOverseer::Console.instance.submit_text(string, false)
|
142
|
+
rescue NoMethodError
|
143
|
+
self.defer_log(string)
|
144
|
+
end
|
145
|
+
end
|
146
|
+
|
147
|
+
def self.log_with_color(string, color = Gosu::Color::WHITE)
|
148
|
+
self.log_it(string) if string.strip.length > 0
|
149
|
+
GameOverseer::Console.instance.submit_text(string, false, color)
|
150
|
+
end
|
151
|
+
|
152
|
+
def self.defer_log(string)
|
153
|
+
PENDING_LOG << string
|
154
|
+
end
|
155
|
+
|
156
|
+
def self.log_it(string)
|
157
|
+
puts string
|
158
|
+
retry_limit = 0
|
159
|
+
begin
|
160
|
+
@log_file = File.open("#{Dir.pwd}/logs/log-#{Time.now.strftime('%B-%d-%Y')}.txt", 'a+') unless defined? @log_file
|
161
|
+
@log_file.write "[#{Time.now.strftime('%c')}] #{string}\n"
|
162
|
+
rescue Errno::ENOENT
|
163
|
+
Dir.mkdir("#{Dir.pwd}/logs") unless File.exist?("#{Dir.pwd}/logs") && File.directory?("#{Dir.pwd}/logs")
|
164
|
+
retry_limit+=1
|
165
|
+
retry unless retry_limit >= 2
|
166
|
+
end
|
167
|
+
end
|
168
|
+
|
169
|
+
protected
|
170
|
+
def submit_text(text, from_console = true, color = Gosu::Color::WHITE)
|
171
|
+
if text.strip.length > 0
|
172
|
+
clean_messages(300)
|
173
|
+
text = "Console> #{text}" if from_console
|
174
|
+
GameOverseer::Console.log_it(text)
|
175
|
+
if text.length > 83
|
176
|
+
temp_text = text[0..83]
|
177
|
+
@messages.each do |message|
|
178
|
+
message[:y]-=18
|
179
|
+
end
|
180
|
+
@messages << {
|
181
|
+
text: temp_text,
|
182
|
+
instance: text_instance,
|
183
|
+
color: color,
|
184
|
+
x: 4,
|
185
|
+
y: @messages.last[:y] + 18,
|
186
|
+
z: 1
|
187
|
+
}
|
188
|
+
submit_text(text[83..text.length], false)
|
189
|
+
else
|
190
|
+
@messages.each do |message|
|
191
|
+
message[:y]-=18
|
192
|
+
end
|
193
|
+
@messages << {
|
194
|
+
text: text,
|
195
|
+
instance: text_instance,
|
196
|
+
color: color,
|
197
|
+
x: 4,
|
198
|
+
y: @messages.last[:y] + 18,
|
199
|
+
z: 1
|
200
|
+
}
|
201
|
+
end
|
202
|
+
$window.text_input = Gosu::TextInput.new if from_console
|
203
|
+
end
|
204
|
+
end
|
205
|
+
end
|
206
|
+
end
|