rich_engine 0.0.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.
@@ -0,0 +1,183 @@
1
+ # frozen_string_literal: true
2
+
3
+ module RichEngine
4
+ module StringColors
5
+ refine String do
6
+ def fg(color)
7
+ send(color)
8
+ end
9
+
10
+ def bg(color)
11
+ send("on_#{color}")
12
+ end
13
+
14
+ # Colors
15
+
16
+ def transparent
17
+ gsub(/./, " ")
18
+ end
19
+
20
+ def black
21
+ color(30)
22
+ end
23
+
24
+ def red
25
+ color(31)
26
+ end
27
+
28
+ def green
29
+ color(32)
30
+ end
31
+
32
+ def yellow
33
+ color(33)
34
+ end
35
+
36
+ def blue
37
+ color(34)
38
+ end
39
+
40
+ def magenta
41
+ color(35)
42
+ end
43
+
44
+ def cyan
45
+ color(36)
46
+ end
47
+
48
+ def white
49
+ color(37)
50
+ end
51
+
52
+ def bright_black
53
+ color(90)
54
+ end
55
+
56
+ def bright_red
57
+ color(91)
58
+ end
59
+
60
+ def bright_green
61
+ color(92)
62
+ end
63
+
64
+ def bright_yellow
65
+ color(93)
66
+ end
67
+
68
+ def bright_blue
69
+ color(94)
70
+ end
71
+
72
+ def bright_magenta
73
+ color(95)
74
+ end
75
+
76
+ def bright_cyan
77
+ color(96)
78
+ end
79
+
80
+ def bright_white
81
+ color(97)
82
+ end
83
+
84
+ # Background colors
85
+
86
+ def on_black
87
+ color(40)
88
+ end
89
+
90
+ def on_red
91
+ color(41)
92
+ end
93
+
94
+ def on_green
95
+ color(42)
96
+ end
97
+
98
+ def on_yellow
99
+ color(43)
100
+ end
101
+
102
+ def on_blue
103
+ color(44)
104
+ end
105
+
106
+ def on_magenta
107
+ color(45)
108
+ end
109
+
110
+ def on_cyan
111
+ color(46)
112
+ end
113
+
114
+ def on_gray
115
+ color(47)
116
+ end
117
+
118
+ def on_transparent
119
+ color(49)
120
+ end
121
+
122
+ def on_bright_black
123
+ color(100)
124
+ end
125
+
126
+ def on_bright_red
127
+ color(101)
128
+ end
129
+
130
+ def on_bright_green
131
+ color(102)
132
+ end
133
+
134
+ def on_bright_yellow
135
+ color(103)
136
+ end
137
+
138
+ def on_bright_blue
139
+ color(104)
140
+ end
141
+
142
+ def on_bright_magenta
143
+ color(105)
144
+ end
145
+
146
+ def on_bright_cyan
147
+ color(106)
148
+ end
149
+
150
+ def on_bright_white
151
+ color(107)
152
+ end
153
+
154
+ # STYLES
155
+
156
+ def bold
157
+ "\e[1m#{self}\e[22m"
158
+ end
159
+
160
+ def italic
161
+ "\e[3m#{self}\e[23m"
162
+ end
163
+
164
+ def underline
165
+ "\e[4m#{self}\e[24m"
166
+ end
167
+
168
+ def blink
169
+ "\e[5m#{self}\e[25m"
170
+ end
171
+
172
+ def reverse_color
173
+ "\e[7m#{self}\e[27m"
174
+ end
175
+
176
+ private
177
+
178
+ def color(n)
179
+ "\e[#{n}m#{self}\e[0m"
180
+ end
181
+ end
182
+ end
183
+ end
@@ -0,0 +1,21 @@
1
+ # frozen_string_literal: true
2
+
3
+ module RichEngine
4
+ module Terminal
5
+ module Cursor
6
+ extend self
7
+
8
+ def hide
9
+ system("tput civis")
10
+ end
11
+
12
+ def display
13
+ system("tput cnorm")
14
+ end
15
+
16
+ def goto(x, y)
17
+ $stdout.goto(x, y)
18
+ end
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,29 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "terminal/cursor"
4
+
5
+ module RichEngine
6
+ module Terminal
7
+ module_function
8
+
9
+ def clear
10
+ $stdout.clear_screen
11
+ end
12
+
13
+ def hide_cursor
14
+ Cursor.hide
15
+ end
16
+
17
+ def display_cursor
18
+ Cursor.display
19
+ end
20
+
21
+ def disable_echo
22
+ $stdin.echo = false
23
+ end
24
+
25
+ def enable_echo
26
+ $stdin.echo = true
27
+ end
28
+ end
29
+ end
@@ -0,0 +1,40 @@
1
+ # frozen_string_literal: true
2
+
3
+ module RichEngine
4
+ class Timer
5
+ class Every
6
+ def initialize(interval)
7
+ @interval = interval
8
+ @ready = false
9
+ @timer = Timer.new
10
+ end
11
+
12
+ def update(elapsed_time)
13
+ @timer.update(elapsed_time)
14
+
15
+ if @timer.get >= @interval
16
+ @ready = true
17
+ end
18
+ end
19
+
20
+ def when_ready(&block)
21
+ if @ready
22
+ block.call
23
+ reset!
24
+ end
25
+ end
26
+
27
+ def interval=(interval)
28
+ @interval = interval
29
+ reset!
30
+ end
31
+
32
+ private
33
+
34
+ def reset!
35
+ @timer.reset!
36
+ @ready = false
37
+ end
38
+ end
39
+ end
40
+ end
@@ -0,0 +1,25 @@
1
+ # frozen_string_literal: true
2
+
3
+ module RichEngine
4
+ class Timer
5
+ def self.every(seconds: 1, &block)
6
+ Every.new(seconds)
7
+ end
8
+
9
+ def initialize
10
+ @timer = 0
11
+ end
12
+
13
+ def update(dt)
14
+ @timer += dt
15
+ end
16
+
17
+ def get
18
+ @timer
19
+ end
20
+
21
+ def reset!
22
+ @timer = 0
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,47 @@
1
+ module RichEngine
2
+ module UI
3
+ module Textures
4
+ extend self
5
+
6
+ def empty
7
+ " "
8
+ end
9
+
10
+ def solid
11
+ "█"
12
+ end
13
+
14
+ def light_shade
15
+ "▓"
16
+ end
17
+
18
+ def medium_shade
19
+ "▒"
20
+ end
21
+
22
+ def dark_shade
23
+ "░"
24
+ end
25
+
26
+ def top_half
27
+ "▀"
28
+ end
29
+
30
+ def bottom_half
31
+ "▄"
32
+ end
33
+
34
+ def left_half
35
+ "▌"
36
+ end
37
+
38
+ def right_half
39
+ "▐"
40
+ end
41
+
42
+ def plaid
43
+ "▞"
44
+ end
45
+ end
46
+ end
47
+ end
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ module RichEngine
4
+ VERSION = "0.0.0"
5
+ end
@@ -0,0 +1,17 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "rich_engine/canvas"
4
+ require_relative "rich_engine/chance"
5
+ require_relative "rich_engine/cooldown"
6
+ require_relative "rich_engine/enum"
7
+ require_relative "rich_engine/game"
8
+ require_relative "rich_engine/matrix"
9
+ require_relative "rich_engine/string_colors"
10
+ require_relative "rich_engine/terminal"
11
+ require_relative "rich_engine/timer"
12
+ require_relative "rich_engine/timer/every"
13
+ require_relative "rich_engine/ui/textures"
14
+ require_relative "rich_engine/version"
15
+
16
+ module RichEngine
17
+ end
data/mise.toml ADDED
@@ -0,0 +1,2 @@
1
+ [tools]
2
+ ruby = "3.4.6"
@@ -0,0 +1,28 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "lib/rich_engine/version"
4
+
5
+ Gem::Specification.new do |spec|
6
+ spec.name = "rich_engine"
7
+ spec.version = RichEngine::VERSION
8
+ spec.authors = ["Matheus Richard"]
9
+ spec.email = ["matheusrichardt@gmail.com"]
10
+
11
+ spec.summary = "A Ruby engine for terminal games."
12
+ spec.homepage = "https://github.com/MatheusRich/rich_engine"
13
+ spec.license = "MIT"
14
+ spec.required_ruby_version = Gem::Requirement.new(">= 2.3.0")
15
+
16
+ spec.metadata["homepage_uri"] = spec.homepage
17
+ # spec.metadata["source_code_uri"] = "TODO: Put your gem's public repo URL here."
18
+ # spec.metadata["changelog_uri"] = "TODO: Put your gem's CHANGELOG.md URL here."
19
+
20
+ # Specify which files should be added to the gem when it is released.
21
+ # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
22
+ spec.files = Dir.chdir(File.expand_path(__dir__)) do
23
+ `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
24
+ end
25
+ spec.bindir = "exe"
26
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
27
+ spec.require_paths = ["lib"]
28
+ end
metadata ADDED
@@ -0,0 +1,74 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: rich_engine
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.0
5
+ platform: ruby
6
+ authors:
7
+ - Matheus Richard
8
+ bindir: exe
9
+ cert_chain: []
10
+ date: 1980-01-02 00:00:00.000000000 Z
11
+ dependencies: []
12
+ email:
13
+ - matheusrichardt@gmail.com
14
+ executables: []
15
+ extensions: []
16
+ extra_rdoc_files: []
17
+ files:
18
+ - ".github/workflows/tests-and-linter.yml"
19
+ - ".gitignore"
20
+ - ".standard.yml"
21
+ - Gemfile
22
+ - Gemfile.lock
23
+ - Guardfile
24
+ - LICENSE.txt
25
+ - README.md
26
+ - Rakefile
27
+ - bin/console
28
+ - bin/setup
29
+ - examples/background.rb
30
+ - examples/grains_of_sand.rb
31
+ - examples/noise.rb
32
+ - examples/timer.rb
33
+ - lib/rich_engine.rb
34
+ - lib/rich_engine/canvas.rb
35
+ - lib/rich_engine/chance.rb
36
+ - lib/rich_engine/cooldown.rb
37
+ - lib/rich_engine/enum.rb
38
+ - lib/rich_engine/enum/mixin.rb
39
+ - lib/rich_engine/enum/value.rb
40
+ - lib/rich_engine/game.rb
41
+ - lib/rich_engine/io.rb
42
+ - lib/rich_engine/matrix.rb
43
+ - lib/rich_engine/string_colors.rb
44
+ - lib/rich_engine/terminal.rb
45
+ - lib/rich_engine/terminal/cursor.rb
46
+ - lib/rich_engine/timer.rb
47
+ - lib/rich_engine/timer/every.rb
48
+ - lib/rich_engine/ui/textures.rb
49
+ - lib/rich_engine/version.rb
50
+ - mise.toml
51
+ - rich_engine.gemspec
52
+ homepage: https://github.com/MatheusRich/rich_engine
53
+ licenses:
54
+ - MIT
55
+ metadata:
56
+ homepage_uri: https://github.com/MatheusRich/rich_engine
57
+ rdoc_options: []
58
+ require_paths:
59
+ - lib
60
+ required_ruby_version: !ruby/object:Gem::Requirement
61
+ requirements:
62
+ - - ">="
63
+ - !ruby/object:Gem::Version
64
+ version: 2.3.0
65
+ required_rubygems_version: !ruby/object:Gem::Requirement
66
+ requirements:
67
+ - - ">="
68
+ - !ruby/object:Gem::Version
69
+ version: '0'
70
+ requirements: []
71
+ rubygems_version: 3.6.9
72
+ specification_version: 4
73
+ summary: A Ruby engine for terminal games.
74
+ test_files: []