world_in_your_terminal 0.0.2 → 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: a29a270cd0cdc73a534963690fc1390ff79d24f0b2e30f019eed885449cad325
4
- data.tar.gz: 9a5039556a06be0687aa9d8251f9255a98ba3c636588432da647932f8b5faf2c
3
+ metadata.gz: 87e23b706e5aae83d585b6f01bb4f9ad028e20c48d4538784034f6e82b6b0c14
4
+ data.tar.gz: abd22f064c39c0e52f15fab88da86890ab813df82e8f0958567e8ce98566fea1
5
5
  SHA512:
6
- metadata.gz: 287dcdd6c45866708b101d54b69d6e7ab51e94b90eef9f2223f884c1733d3dd83a12ece8d382b8240167ce92f1f488e2058668f38ab6c6bb08c7cece0f5e2a90
7
- data.tar.gz: 3d52f0e1cfd4057811b4852ffc356e6d201e3496b5dee000353f80b4e97a4e0e8e1bbd8ab2c637688c9f434487ef23081c4e1f4a35fc0726437f43957134da7e
6
+ metadata.gz: 12b8759a693a18cb62942a288bc7816b8410b34cf2be7bdce9c0e8284b64ef5da2ad4893c4428d84f96d9895d17193eec5044b5eb38da6b0ef7fdf22ad81944b
7
+ data.tar.gz: c9c4ffdc2191fe11091351b3589b083abdc4359a5491a8df3698493254e1644bdfec3e1d15316985183735a22a4527d798e546fab7cc957c989706cddb0eb52b
File without changes
@@ -0,0 +1,53 @@
1
+ class AlertSystem
2
+ def initialize
3
+ @pastel = Pastel.new
4
+ @alerts = []
5
+ end
6
+
7
+ def draw
8
+ puts render
9
+ clear
10
+ end
11
+
12
+ def add_message(message)
13
+ @alerts << Alert.new(message, pastel)
14
+ end
15
+
16
+ private
17
+
18
+ def render
19
+ lines_to_render = []
20
+ alerts.each { |alert|
21
+ lines_to_render << alert.render
22
+ }
23
+
24
+ lines_to_render.join("\n")
25
+ end
26
+
27
+ def alerts
28
+ @alerts
29
+ end
30
+
31
+ def clear
32
+ @alerts = []
33
+ end
34
+
35
+ def pastel
36
+ @pastel
37
+ end
38
+ end
39
+
40
+ class Alert
41
+ def initialize(message, pastel)
42
+ @message = message
43
+ @pastel = pastel
44
+ end
45
+
46
+ def render
47
+ @pastel.black.on_green(message)
48
+ end
49
+
50
+ def message
51
+ @message
52
+ end
53
+ end
@@ -1,6 +1,6 @@
1
1
  require_relative './constants/themes/default.rb'
2
2
  require_relative './constants/themes/black_white.rb'
3
- require_relative './World.rb'
3
+ require_relative './world.rb'
4
4
 
5
5
  class Display
6
6
  def initialize(screen_size)
@@ -1,6 +1,7 @@
1
1
  require 'tty-file'
2
2
  require 'date'
3
- require_relative './Action.rb'
3
+ require_relative './action.rb'
4
+ require_relative './alert_system.rb'
4
5
 
5
6
  class Engine
6
7
  def initialize(prompt, display)
@@ -13,6 +14,7 @@ class Engine
13
14
  initialize_key_prompt
14
15
  while is_running
15
16
  display.draw
17
+ alerts.draw
16
18
  show_key_prompts
17
19
  end
18
20
  end
@@ -54,6 +56,7 @@ class Engine
54
56
  'z' => Action.new(world.method(:zoom_in)),
55
57
  'x' => Action.new(world.method(:zoom_out)),
56
58
  'n' => Action.new(method(:name_world)),
59
+ 'c' => Action.new(world.method(:cycle_theme)),
57
60
  'e' => Action.new(method(:export_to_txt)),
58
61
  :up => Action.new(world.method(:scroll_up)), # scroll up
59
62
  :down => Action.new(world.method(:scroll_down)), # scroll down
@@ -81,6 +84,7 @@ class Engine
81
84
  "z to zoom in",
82
85
  "x to zoom out",
83
86
  "n to rename this world",
87
+ "c to switch theme",
84
88
  "e to save this world in text",
85
89
  "q to quit",
86
90
  ""
@@ -99,8 +103,10 @@ class Engine
99
103
  directory = "exported_worlds"
100
104
  extension = 'txt'
101
105
  file_name = "#{DateTime.now.strftime('%Y_%m_%d__%H%M%S')}__#{world.name}.txt".gsub!(" ","_")
106
+ location = "#{directory}/#{file_name}"
107
+ TTY::File.create_file(location, content)
102
108
 
103
- TTY::File.create_file("#{directory}/#{file_name}", content)
109
+ alerts.add_message("Succesfully saved to #{location}")
104
110
  end
105
111
 
106
112
  def default_action
@@ -115,6 +121,10 @@ class Engine
115
121
  @display
116
122
  end
117
123
 
124
+ def alerts
125
+ @alerts ||= AlertSystem.new
126
+ end
127
+
118
128
  def world
119
129
  @display.world
120
130
  end
@@ -2,8 +2,8 @@ require 'tty-table'
2
2
  require 'tty-box'
3
3
  require_relative './constants/tile_types.rb'
4
4
  require_relative './constants/themes/black_white.rb'
5
- require_relative './GenerateName.rb'
6
- require_relative './GenerateMatrix.rb'
5
+ require_relative './generate_name.rb'
6
+ require_relative './generate_matrix.rb'
7
7
 
8
8
 
9
9
  class Point
@@ -71,6 +71,19 @@ class World
71
71
  @name = name
72
72
  end
73
73
 
74
+ def cycle_theme
75
+ available_themes = Constants::THEME.constants.map {|theme| Constants::THEME.const_get(theme)}
76
+
77
+ current_theme_index = available_themes.index(@theme)
78
+ next_theme_index = (current_theme_index + 1) % available_themes.length
79
+
80
+ set_theme(available_themes[next_theme_index])
81
+ end
82
+
83
+ def set_theme(theme)
84
+ @theme = theme
85
+ end
86
+
74
87
  def draw(tile_size)
75
88
  # puts render_framed_map(tile_size)
76
89
  # puts render_framed_table_map(tile_size)
@@ -1,6 +1,6 @@
1
1
  require 'tty-prompt'
2
- require_relative './world_in_your_terminal/Display.rb'
3
- require_relative './world_in_your_terminal/Engine.rb'
2
+ require_relative './world_in_your_terminal/display.rb'
3
+ require_relative './world_in_your_terminal/engine.rb'
4
4
 
5
5
  class WorldInYourTerminal
6
6
  def explore
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: world_in_your_terminal
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - David Vanderhaar
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-12-11 00:00:00.000000000 Z
11
+ date: 2021-12-16 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: pastel
@@ -131,15 +131,16 @@ extra_rdoc_files: []
131
131
  files:
132
132
  - bin/world_in_your_terminal
133
133
  - lib/world_in_your_terminal.rb
134
- - lib/world_in_your_terminal/Action.rb
135
- - lib/world_in_your_terminal/Display.rb
136
- - lib/world_in_your_terminal/Engine.rb
137
- - lib/world_in_your_terminal/GenerateMatrix.rb
138
- - lib/world_in_your_terminal/GenerateName.rb
139
- - lib/world_in_your_terminal/World.rb
134
+ - lib/world_in_your_terminal/action.rb
135
+ - lib/world_in_your_terminal/alert_system.rb
140
136
  - lib/world_in_your_terminal/constants/themes/black_white.rb
141
137
  - lib/world_in_your_terminal/constants/themes/default.rb
142
138
  - lib/world_in_your_terminal/constants/tile_types.rb
139
+ - lib/world_in_your_terminal/display.rb
140
+ - lib/world_in_your_terminal/engine.rb
141
+ - lib/world_in_your_terminal/generate_matrix.rb
142
+ - lib/world_in_your_terminal/generate_name.rb
143
+ - lib/world_in_your_terminal/world.rb
143
144
  homepage: https://rubygems.org/gems/world_in_your_terminal
144
145
  licenses:
145
146
  - MIT