minigl 2.3.8 → 2.4.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +9 -4
- data/lib/minigl/forms.rb +9 -11
- data/lib/minigl/game_object.rb +4 -1
- data/lib/minigl/global.rb +49 -12
- data/lib/minigl/localization.rb +79 -0
- data/lib/minigl.rb +1 -0
- data/test/data/text/english.txt +6 -0
- data/test/data/text/portuguese.txt +6 -0
- data/test/game.rb +1 -1
- data/test/localization_tests.rb +41 -0
- metadata +9 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c0de5c7f62aa915f3f4b27bb395d9521f93f21e855192da3e0ae7e9de90b91b6
|
4
|
+
data.tar.gz: 1f771f1c1281032ed119d3f4717bbd181c838b124b666df6c70b1e130b298ef3
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 745596ac394298301ef9cb3d9490aa447931a160de16505634715c888ac31d267b6b059120b15cb48d6ef7f792f889dde07bb0b5c0e41af44204c72232cc6dd0
|
7
|
+
data.tar.gz: 8306f0e0f22122ccd0e7df3ccf318539132b96028aee6f724ff355a9fc2fb63245f1aed8650e3bfdc9910b3868595c7a05719b04578d04034874b3ba32e8e601
|
data/README.md
CHANGED
@@ -16,9 +16,14 @@ to victordavidsantos@gmail.com.
|
|
16
16
|
|
17
17
|
## Made with MiniGL
|
18
18
|
|
19
|
-
Below are
|
19
|
+
Below are some games built with MiniGL, all available for free download and also open source.
|
20
20
|
* [Super Bombinhas](https://github.com/victords/super-bombinhas)
|
21
21
|
* [ConnecMan](https://github.com/victords/connecman)
|
22
|
+
* [SokoAdventure](https://github.com/victords/sokoadventure)
|
23
|
+
* [Spheres](https://github.com/victords/spheres)
|
24
|
+
* [Willy the droid](https://github.com/gavr-games/willy_the_droid)
|
25
|
+
|
26
|
+
Download Super Bombinhas, ConnecMan, SokoAdventure and Spheres in my [itch.io page](https://victords.itch.io).
|
22
27
|
|
23
28
|
If you create a project using MiniGL, feel free to open a PR to include it in this list.
|
24
29
|
|
@@ -37,10 +42,10 @@ After installing the Gosu dependencies, you can just `gem install minigl`.
|
|
37
42
|
* The [wiki](https://github.com/victords/minigl/wiki) is a work in progress with tutorials and examples.
|
38
43
|
* Test package and examples aren't complete!
|
39
44
|
|
40
|
-
## Version 2.
|
45
|
+
## Version 2.4.1
|
41
46
|
|
42
|
-
*
|
43
|
-
*
|
47
|
+
* Expose `Sprite`'s `img` attribute.
|
48
|
+
* Fix `Effect#draw`'s `z_index` parameter.
|
44
49
|
|
45
50
|
## Contributing
|
46
51
|
|
data/lib/minigl/forms.rb
CHANGED
@@ -317,12 +317,12 @@ module MiniGL
|
|
317
317
|
super x, y, font, text, text_color, disabled_text_color
|
318
318
|
@over_text_color = over_text_color
|
319
319
|
@down_text_color = down_text_color
|
320
|
-
if center_x; @text_x = x + @w / 2 if @w
|
321
|
-
else; @text_x = x + margin_x * @scale_x; end
|
322
|
-
if center_y; @text_y = y + @h / 2 if @h
|
323
|
-
else; @text_y = y + margin_y * @scale_y; end
|
324
320
|
@center_x = center_x
|
325
321
|
@center_y = center_y
|
322
|
+
@margin_x = margin_x
|
323
|
+
@margin_y = margin_y
|
324
|
+
set_position(x, y)
|
325
|
+
|
326
326
|
@action = action
|
327
327
|
@params = params
|
328
328
|
|
@@ -393,10 +393,10 @@ module MiniGL
|
|
393
393
|
# [x] The new x-coordinate for the button.
|
394
394
|
# [y] The new y-coordinate for the button.
|
395
395
|
def set_position(x, y)
|
396
|
-
|
397
|
-
|
398
|
-
|
399
|
-
|
396
|
+
@text_x = @center_x ? x + @w / 2 : x
|
397
|
+
@text_y = @center_y ? y + @h / 2 : y
|
398
|
+
@text_x += @margin_x
|
399
|
+
@text_y += @margin_y
|
400
400
|
@x = x; @y = y
|
401
401
|
end
|
402
402
|
|
@@ -445,7 +445,7 @@ module MiniGL
|
|
445
445
|
private
|
446
446
|
|
447
447
|
def perform_action
|
448
|
-
@action.call
|
448
|
+
@action.call(@params) if @action
|
449
449
|
end
|
450
450
|
end
|
451
451
|
|
@@ -514,8 +514,6 @@ module MiniGL
|
|
514
514
|
else; height * @scale_y; end
|
515
515
|
_, x, y = FormUtils.check_anchor(anchor, @anchor_offset_x, @anchor_offset_y, @w, @h)
|
516
516
|
set_position(x, y)
|
517
|
-
@text_x = x + @w / 2 if center_x
|
518
|
-
@text_y = y + @h / 2 if center_y
|
519
517
|
@checked = checked
|
520
518
|
end
|
521
519
|
|
data/lib/minigl/game_object.rb
CHANGED
@@ -3,6 +3,9 @@ require_relative 'movement'
|
|
3
3
|
module MiniGL
|
4
4
|
# This class represents an (optionally animated) image inside the game screen.
|
5
5
|
class Sprite
|
6
|
+
# The list of images of this sprite (i.e. the spritesheet).
|
7
|
+
attr_reader :img
|
8
|
+
|
6
9
|
# The index of the current sprite in the spritesheet being drawn.
|
7
10
|
attr_reader :img_index
|
8
11
|
|
@@ -384,7 +387,7 @@ module MiniGL
|
|
384
387
|
@dead = true if @elapsed_time == @lifetime
|
385
388
|
end
|
386
389
|
|
387
|
-
def draw(map = nil, scale_x = 1, scale_y = 1, alpha = 0xff, color = 0xffffff, angle = nil, z_index = 0)
|
390
|
+
def draw(map = nil, scale_x = 1, scale_y = 1, alpha = 0xff, color = 0xffffff, angle = nil, flip = nil, z_index = 0, round = false)
|
388
391
|
super unless @dead
|
389
392
|
end
|
390
393
|
|
data/lib/minigl/global.rb
CHANGED
@@ -245,6 +245,16 @@ module MiniGL
|
|
245
245
|
def toggle_fullscreen
|
246
246
|
self.fullscreen = !fullscreen?
|
247
247
|
end
|
248
|
+
|
249
|
+
def button_down(id)
|
250
|
+
super
|
251
|
+
Mouse.register_button_down(id)
|
252
|
+
end
|
253
|
+
|
254
|
+
def button_up(id)
|
255
|
+
super
|
256
|
+
Mouse.register_button_up(id)
|
257
|
+
end
|
248
258
|
end
|
249
259
|
|
250
260
|
# Exposes methods for controlling keyboard and gamepad events.
|
@@ -387,6 +397,7 @@ module MiniGL
|
|
387
397
|
def initialize
|
388
398
|
@down = {}
|
389
399
|
@prev_down = {}
|
400
|
+
@next_down = {}
|
390
401
|
@dbl_click = {}
|
391
402
|
@dbl_click_timer = {}
|
392
403
|
end
|
@@ -394,7 +405,8 @@ module MiniGL
|
|
394
405
|
# Updates the mouse position and the state of all buttons.
|
395
406
|
def update
|
396
407
|
@prev_down = @down.clone
|
397
|
-
@down.
|
408
|
+
@down = @next_down.clone
|
409
|
+
@next_down.delete_if { |_, v| v.zero? }
|
398
410
|
@dbl_click.clear
|
399
411
|
|
400
412
|
if @click
|
@@ -403,19 +415,19 @@ module MiniGL
|
|
403
415
|
end
|
404
416
|
|
405
417
|
@dbl_click_timer.each do |k, v|
|
406
|
-
if v < G.double_click_delay
|
407
|
-
|
418
|
+
if v < G.double_click_delay
|
419
|
+
@dbl_click_timer[k] += 1
|
420
|
+
else
|
421
|
+
@dbl_click_timer.delete(k)
|
422
|
+
end
|
408
423
|
end
|
409
424
|
|
410
|
-
|
411
|
-
|
412
|
-
|
413
|
-
|
414
|
-
|
415
|
-
@
|
416
|
-
@dbl_click_timer.delete k2[i]
|
417
|
-
elsif @prev_down[k2[i]]
|
418
|
-
@dbl_click_timer[k2[i]] = 0
|
425
|
+
%i[left middle right].each do |key|
|
426
|
+
if @down[key]
|
427
|
+
@dbl_click[key] = true if @dbl_click_timer[key]
|
428
|
+
@dbl_click_timer.delete(key)
|
429
|
+
elsif @prev_down[key]
|
430
|
+
@dbl_click_timer[key] = 0
|
419
431
|
end
|
420
432
|
end
|
421
433
|
|
@@ -486,6 +498,31 @@ module MiniGL
|
|
486
498
|
|
487
499
|
@click = { z_index: z_index, action: action }
|
488
500
|
end
|
501
|
+
|
502
|
+
# :nodoc:
|
503
|
+
def register_button_down(id)
|
504
|
+
key = key_from_id(id)
|
505
|
+
@next_down[key] = 1 if key
|
506
|
+
end
|
507
|
+
|
508
|
+
# :nodoc:
|
509
|
+
def register_button_up(id)
|
510
|
+
key = key_from_id(id)
|
511
|
+
@next_down[key] = 0 if key && @next_down[key]
|
512
|
+
end
|
513
|
+
|
514
|
+
private
|
515
|
+
|
516
|
+
def key_from_id(id)
|
517
|
+
case id
|
518
|
+
when Gosu::MS_LEFT
|
519
|
+
:left
|
520
|
+
when Gosu::MS_RIGHT
|
521
|
+
:right
|
522
|
+
when Gosu::MS_MIDDLE
|
523
|
+
:middle
|
524
|
+
end
|
525
|
+
end
|
489
526
|
end
|
490
527
|
end
|
491
528
|
|
@@ -0,0 +1,79 @@
|
|
1
|
+
module MiniGL
|
2
|
+
# This class provides methods to easily retrieve string translations from
|
3
|
+
# text files.
|
4
|
+
class Localization
|
5
|
+
class << self
|
6
|
+
# The list of available languages. These are symbols corresponding to the
|
7
|
+
# names of the files in data/text, without the '.txt' extension.
|
8
|
+
attr_reader :languages
|
9
|
+
|
10
|
+
# The current language. It's a symbol corresponding to the name of the
|
11
|
+
# file in data/text for that language, without the '.txt' extension.
|
12
|
+
attr_reader :language
|
13
|
+
|
14
|
+
# Initializes the localization system. If you're using a custom
|
15
|
+
# +Res.prefix+, call this _after_ setting it.
|
16
|
+
#
|
17
|
+
# The localization system will look for files with extension '.txt' in
|
18
|
+
# the <code>[Res.prefix]/data/text</code> folder. In each file,
|
19
|
+
# each string should be specified in one line, with the following format:
|
20
|
+
#
|
21
|
+
# <code>identifier content content content...</code>
|
22
|
+
#
|
23
|
+
# Use tab characters between the identifier and the text, not white
|
24
|
+
# spaces. This makes it easier to make all the texts aligned and is
|
25
|
+
# required for the localization system to work. The identifiers will be
|
26
|
+
# used as symbols when retrieving strings.
|
27
|
+
#
|
28
|
+
# The text contents support placeholders, i.e., markers that can be
|
29
|
+
# replaced by arguments you pass to +Localization.text+. To specify a
|
30
|
+
# placeholder, simply use the '$' character. For example, if your string
|
31
|
+
# is:
|
32
|
+
#
|
33
|
+
# <code>my_string Values: $ and $</code>
|
34
|
+
#
|
35
|
+
# the call <code>Localization.text(:my_string, 'test', 10)</code> will
|
36
|
+
# result in "Values: test and 10."
|
37
|
+
#
|
38
|
+
# To include a literal '$'
|
39
|
+
# in the text, use '\\$' (without the quotes). Similarly, use '\\\\' to
|
40
|
+
# represent a literal backslash, and just '\\' to represent a line break
|
41
|
+
# (i.e. a "\\n" in the resulting string).
|
42
|
+
def initialize
|
43
|
+
@languages = []
|
44
|
+
@texts = {}
|
45
|
+
files = Dir["#{Res.prefix}text/*.txt"].sort
|
46
|
+
files.each do |f|
|
47
|
+
lang = f.split('/')[-1].chomp('.txt').to_sym
|
48
|
+
@languages << lang
|
49
|
+
@texts[lang] = {}
|
50
|
+
File.open(f).each do |l|
|
51
|
+
parts = l.split("\t")
|
52
|
+
@texts[lang][parts[0].to_sym] = parts[-1].chomp
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
@language = @languages[0]
|
57
|
+
end
|
58
|
+
|
59
|
+
# Sets the current language. +value+ must be a symbol corresponding to
|
60
|
+
# the name of a file in data/text, without the '.txt' extension.
|
61
|
+
def language=(value)
|
62
|
+
raise "Can't set to invalid language #{value}" unless @languages.include?(value)
|
63
|
+
|
64
|
+
@language = value
|
65
|
+
end
|
66
|
+
|
67
|
+
# Retrieves the string identified by +id+ in the current language.
|
68
|
+
#
|
69
|
+
# See +Localization.initialize+ for details on how to use +args+.
|
70
|
+
def text(id, *args)
|
71
|
+
value = @texts[@language][id] || '<MISSING STRING>'
|
72
|
+
args.each do |arg|
|
73
|
+
value = value.sub(/(^|[^\\])\$/, "\\1#{arg}")
|
74
|
+
end
|
75
|
+
value.gsub('\\$', '$').gsub(/\\(.|$)/) { |m| m[1] == '\\' ? '\\' : "\n#{m[1]}" }
|
76
|
+
end
|
77
|
+
end
|
78
|
+
end
|
79
|
+
end
|
data/lib/minigl.rb
CHANGED
data/test/game.rb
CHANGED
@@ -19,7 +19,7 @@ class MyGame < GameWindow
|
|
19
19
|
@font2 = Res.font :font1, 50
|
20
20
|
@writer1 = TextHelper.new @font1, 5
|
21
21
|
@writer2 = TextHelper.new @font2, 5
|
22
|
-
@btn = Button.new(10, 560, @font1, 'Test', :btn, 0x008000, 0x808080, 0xffffff, 0xff9980, true,
|
22
|
+
@btn = Button.new(10, 560, @font1, 'Test', :btn, 0x008000, 0x808080, 0xffffff, 0xff9980, true, false, -10, 4, 0, 0, 'friends', nil, 2, 2) { |x| puts "hello #{x}" }
|
23
23
|
@btn.enabled = false
|
24
24
|
@chk =
|
25
25
|
ToggleButton.new(x: 0, y: 30, font: @font1, text: 'Click me', img: :check, center_x: false, margin_x: 36, params: 'friends', anchor: :south) { |c, x|
|
@@ -0,0 +1,41 @@
|
|
1
|
+
require 'test/unit'
|
2
|
+
require_relative '../lib/minigl'
|
3
|
+
include MiniGL
|
4
|
+
|
5
|
+
class LocalizationTest < Test::Unit::TestCase
|
6
|
+
def setup
|
7
|
+
Res.prefix = File.expand_path(File.dirname(__FILE__)) + '/data'
|
8
|
+
Localization.initialize
|
9
|
+
end
|
10
|
+
|
11
|
+
def test_languages
|
12
|
+
assert_equal([:english, :portuguese], Localization.languages)
|
13
|
+
end
|
14
|
+
|
15
|
+
def test_language
|
16
|
+
assert_equal(:english, Localization.language)
|
17
|
+
Localization.language = :portuguese
|
18
|
+
assert_equal(:portuguese, Localization.language)
|
19
|
+
assert_raise { Localization.language = :invalid }
|
20
|
+
assert_equal(:portuguese, Localization.language)
|
21
|
+
end
|
22
|
+
|
23
|
+
def test_strings
|
24
|
+
assert_equal('Common string.', Localization.text(:str1))
|
25
|
+
assert_equal('String with $ dollar sign.', Localization.text(:str2))
|
26
|
+
assert_equal('something should be replaced.', Localization.text(:str3, 'something'))
|
27
|
+
assert_equal('Should replace both 5 and true.', Localization.text(:str4, 5, true))
|
28
|
+
assert_equal('String with \\ backslash.', Localization.text(:str5))
|
29
|
+
assert_equal("String with\nline breaks.\n", Localization.text(:str6))
|
30
|
+
assert_equal('<MISSING STRING>', Localization.text(:str7))
|
31
|
+
|
32
|
+
Localization.language = :portuguese
|
33
|
+
assert_equal('String comum.', Localization.text(:str1))
|
34
|
+
assert_equal('String com $ cifrão.', Localization.text(:str2))
|
35
|
+
assert_equal('algo deve ser substituído.', Localization.text(:str3, 'algo'))
|
36
|
+
assert_equal('Deve substituir 5 e true.', Localization.text(:str4, 5, true))
|
37
|
+
assert_equal('String com \\ barra invertida.', Localization.text(:str5))
|
38
|
+
assert_equal("String com\nquebras de linha.\n", Localization.text(:str6))
|
39
|
+
assert_equal('<MISSING STRING>', Localization.text(:str7))
|
40
|
+
end
|
41
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: minigl
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.
|
4
|
+
version: 2.4.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Victor David Santos
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2022-
|
11
|
+
date: 2022-06-23 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: gosu
|
@@ -43,6 +43,7 @@ files:
|
|
43
43
|
- lib/minigl/forms.rb
|
44
44
|
- lib/minigl/game_object.rb
|
45
45
|
- lib/minigl/global.rb
|
46
|
+
- lib/minigl/localization.rb
|
46
47
|
- lib/minigl/map.rb
|
47
48
|
- lib/minigl/movement.rb
|
48
49
|
- lib/minigl/text.rb
|
@@ -70,10 +71,13 @@ files:
|
|
70
71
|
- test/data/img/tile2.svg
|
71
72
|
- test/data/img/tile2b.png
|
72
73
|
- test/data/sound/1.wav
|
74
|
+
- test/data/text/english.txt
|
75
|
+
- test/data/text/portuguese.txt
|
73
76
|
- test/data/tileset/tileset1.png
|
74
77
|
- test/game.rb
|
75
78
|
- test/game_object_tests.rb
|
76
79
|
- test/iso_game.rb
|
80
|
+
- test/localization_tests.rb
|
77
81
|
- test/map_tests.rb
|
78
82
|
- test/mov_game.rb
|
79
83
|
- test/movement_tests.rb
|
@@ -107,6 +111,7 @@ test_files:
|
|
107
111
|
- test/game.rb
|
108
112
|
- test/game_object_tests.rb
|
109
113
|
- test/iso_game.rb
|
114
|
+
- test/localization_tests.rb
|
110
115
|
- test/map_tests.rb
|
111
116
|
- test/mov_game.rb
|
112
117
|
- test/movement_tests.rb
|
@@ -136,5 +141,7 @@ test_files:
|
|
136
141
|
- test/data/img/tile2.svg
|
137
142
|
- test/data/img/tile2b.png
|
138
143
|
- test/data/sound/1.wav
|
144
|
+
- test/data/text/english.txt
|
145
|
+
- test/data/text/portuguese.txt
|
139
146
|
- test/data/tileset/tileset1.png
|
140
147
|
- test/data/img/sub/image.png
|