gamefic 1.4.1 → 1.5.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (43) hide show
  1. checksums.yaml +4 -4
  2. data/lib/gamefic.rb +1 -2
  3. data/lib/gamefic/character.rb +31 -45
  4. data/lib/gamefic/director/delegate.rb +46 -24
  5. data/lib/gamefic/director/order.rb +7 -0
  6. data/lib/gamefic/director/parser.rb +11 -11
  7. data/lib/gamefic/engine/base.rb +2 -3
  8. data/lib/gamefic/entity.rb +8 -26
  9. data/lib/gamefic/plot.rb +38 -242
  10. data/lib/gamefic/plot/callbacks.rb +101 -0
  11. data/lib/gamefic/plot/command_mount.rb +70 -40
  12. data/lib/gamefic/plot/entities.rb +82 -0
  13. data/lib/gamefic/plot/host.rb +46 -0
  14. data/lib/gamefic/plot/playbook.rb +192 -0
  15. data/lib/gamefic/plot/players.rb +15 -0
  16. data/lib/gamefic/plot/scene_mount.rb +69 -31
  17. data/lib/gamefic/plot/snapshot.rb +20 -5
  18. data/lib/gamefic/scene/active.rb +8 -1
  19. data/lib/gamefic/scene/base.rb +4 -26
  20. data/lib/gamefic/scene/custom.rb +53 -3
  21. data/lib/gamefic/scene/multiple_choice.rb +1 -0
  22. data/lib/gamefic/scene/yes_or_no.rb +1 -1
  23. data/lib/gamefic/scene_data/multiple_scene.rb +0 -4
  24. data/lib/gamefic/shell.rb +0 -1
  25. data/lib/gamefic/source/file.rb +1 -1
  26. data/lib/gamefic/stage.rb +10 -2
  27. data/lib/gamefic/subplot.rb +70 -53
  28. data/lib/gamefic/syntax.rb +9 -2
  29. data/lib/gamefic/tester.rb +1 -1
  30. data/lib/gamefic/text.rb +8 -0
  31. data/lib/gamefic/{ansi.rb → text/ansi.rb} +12 -15
  32. data/lib/gamefic/text/html.rb +68 -0
  33. data/lib/gamefic/text/html/conversions.rb +250 -0
  34. data/lib/gamefic/text/html/entities.rb +9 -0
  35. data/lib/gamefic/tty.rb +2 -0
  36. data/lib/gamefic/user/tty.rb +2 -4
  37. data/lib/gamefic/version.rb +1 -1
  38. metadata +12 -8
  39. data/lib/gamefic/direction.rb +0 -46
  40. data/lib/gamefic/html.rb +0 -68
  41. data/lib/gamefic/html_to_ansi.rb +0 -185
  42. data/lib/gamefic/plot/entity_mount.rb +0 -45
  43. data/lib/gamefic/rule.rb +0 -18
@@ -0,0 +1,9 @@
1
+ module Gamefic
2
+
3
+ module Text
4
+ module Html
5
+ ENTITIES = { "&quot;" => "\"", "&amp;" => "&", "&lt;" => "<", "&gt;" => ">", "&nbsp;" => " ", "&iexcl;" => "¡", "&cent;" => "¢", "&pound;" => "£", "&curren;" => "¤", "&yen;" => "¥", "&brvbar;" => "¦", "&sect;" => "§", "&uml;" => "¨", "&copy;" => "©", "&ordf;" => "ª", "&laquo;" => "«", "&not;" => "¬", "&shy;" => "­", "&reg;" => "®", "&macr;" => "¯", "&deg;" => "°", "&plusmn;" => "±", "&sup2;" => "²", "&sup3;" => "³", "&acute;" => "´", "&micro;" => "µ", "&para;" => "¶", "&middot;" => "·", "&cedil;" => "¸", "&sup1;" => "¹", "&ordm;" => "º", "&raquo;" => "»", "&frac14;" => "¼", "&frac12;" => "½", "&frac34;" => "¾", "&iquest;" => "¿", "&Agrave;" => "À", "&Aacute;" => "Á", "&Acirc;" => "Â", "&Atilde;" => "Ã", "&Auml;" => "Ä", "&Aring;" => "Å", "&AElig;" => "Æ", "&Ccedil;" => "Ç", "&Egrave;" => "È", "&Eacute;" => "É", "&Ecirc;" => "Ê", "&Euml;" => "Ë", "&Igrave;" => "Ì", "&Iacute;" => "Í", "&Icirc;" => "Î", "&Iuml;" => "Ï", "&ETH;" => "Ð", "&Ntilde;" => "Ñ", "&Ograve;" => "Ò", "&Oacute;" => "Ó", "&Ocirc;" => "Ô", "&Otilde;" => "Õ", "&Ouml;" => "Ö", "&times;" => "×", "&Oslash;" => "Ø", "&Ugrave;" => "Ù", "&Uacute;" => "Ú", "&Ucirc;" => "Û", "&Uuml;" => "Ü", "&Yacute;" => "Ý", "&THORN;" => "Þ", "&szlig;" => "ß", "&agrave;" => "à", "&aacute;" => "á", "&acirc;" => "â", "&atilde;" => "ã", "&auml;" => "ä", "&aring;" => "å", "&aelig;" => "æ", "&ccedil;" => "ç", "&egrave;" => "è", "&eacute;" => "é", "&ecirc;" => "ê", "&euml;" => "ë", "&igrave;" => "ì", "&iacute;" => "í", "&icirc;" => "î", "&iuml;" => "ï", "&eth;" => "ð", "&ntilde;" => "ñ", "&ograve;" => "ò", "&oacute;" => "ó", "&ocirc;" => "ô", "&otilde;" => "õ", "&ouml;" => "ö", "&divide;" => "÷", "&oslash;" => "ø", "&ugrave;" => "ù", "&uacute;" => "ú", "&ucirc;" => "û", "&uuml;" => "ü", "&yacute;" => "ý", "&thorn;" => "þ", "&yuml;" => "ÿ", "&OElig;" => "Œ", "&oelig;" => "œ", "&Scaron;" => "Š", "&scaron;" => "š", "&Yuml;" => "Ÿ", "&fnof;" => "ƒ", "&circ;" => "ˆ", "&tilde;" => "˜", "&Alpha;" => "Α", "&Beta;" => "Β", "&Gamma;" => "Γ", "&Delta;" => "Δ", "&Epsilon;" => "Ε", "&Zeta;" => "Ζ", "&Eta;" => "Η", "&Theta;" => "Θ", "&Iota;" => "Ι", "&Kappa;" => "Κ", "&Lambda;" => "Λ", "&Mu;" => "Μ", "&Nu;" => "Ν", "&Xi;" => "Ξ", "&Omicron;" => "Ο", "&Pi;" => "Π", "&Rho;" => "Ρ", "&Sigma;" => "Σ", "&Tau;" => "Τ", "&Upsilon;" => "Υ", "&Phi;" => "Φ", "&Chi;" => "Χ", "&Psi;" => "Ψ", "&Omega;" => "Ω", "&alpha;" => "α", "&beta;" => "β", "&gamma;" => "γ", "&delta;" => "δ", "&epsilon;" => "ε", "&zeta;" => "ζ", "&eta;" => "η", "&theta;" => "θ", "&iota;" => "ι", "&kappa;" => "κ", "&lambda;" => "λ", "&mu;" => "μ", "&nu;" => "ν", "&xi;" => "ξ", "&omicron;" => "ο", "&pi;" => "π", "&rho;" => "ρ", "&sigmaf;" => "ς", "&sigma;" => "σ", "&tau;" => "τ", "&upsilon;" => "υ", "&phi;" => "φ", "&chi;" => "χ", "&psi;" => "ψ", "&omega;" => "ω", "&thetasym;" => "ϑ", "&upsih;" => "ϒ", "&piv;" => "ϖ", "&ensp;" => " ", "&emsp;" => " ", "&thinsp;" => " ", "&zwnj;" => "‌", "&zwj;" => "‍", "&lrm;" => "‎", "&rlm;" => "‏", "&ndash;" => "–", "&mdash;" => "—", "&lsquo;" => "‘", "&rsquo;" => "’", "&sbquo;" => "‚", "&ldquo;" => "“", "&rdquo;" => "”", "&bdquo;" => "„", "&dagger;" => "†", "&Dagger;" => "‡", "&bull;" => "•", "&hellip;" => "…", "&permil;" => "‰", "&prime;" => "′", "&Prime;" => "″", "&lsaquo;" => "‹", "&rsaquo;" => "›", "&oline;" => "‾", "&frasl;" => "⁄", "&euro;" => "€", "&image;" => "ℑ", "&weierp;" => "℘", "&real;" => "ℜ", "&trade;" => "™", "&alefsym;" => "ℵ", "&larr;" => "←", "&uarr;" => "↑", "&rarr;" => "→", "&darr;" => "↓", "&harr;" => "↔", "&crarr;" => "↵", "&lArr;" => "⇐", "&uArr;" => "⇑", "&rArr;" => "⇒", "&dArr;" => "⇓", "&hArr;" => "⇔", "&forall;" => "∀", "&part;" => "∂", "&exist;" => "∃", "&empty;" => "∅", "&nabla;" => "∇", "&isin;" => "∈", "&notin;" => "∉", "&ni;" => "∋", "&prod;" => "∏", "&sum;" => "∑", "&minus;" => "−", "&lowast;" => "∗", "&radic;" => "√", "&prop;" => "∝", "&infin;" => "∞", "&ang;" => "∠", "&and;" => "∧", "&or;" => "∨", "&cap;" => "∩", "&cup;" => "∪", "&int;" => "∫", "&there4;" => "∴", "&sim;" => "∼", "&cong;" => "≅", "&asymp;" => "≈", "&ne;" => "≠", "&equiv;" => "≡", "&le;" => "≤", "&ge;" => "≥", "&sub;" => "⊂", "&sup;" => "⊃", "&nsub;" => "⊄", "&sube;" => "⊆", "&supe;" => "⊇", "&oplus;" => "⊕", "&otimes;" => "⊗", "&perp;" => "⊥", "&sdot;" => "⋅", "&lceil;" => "⌈", "&rceil;" => "⌉", "&lfloor;" => "⌊", "&rfloor;" => "⌋", "&lang;" => "〈", "&rang;" => "〉", "&loz;" => "◊", "&spades;" => "♠", "&clubs;" => "♣", "&hearts;" => "♥", "&diams;" => "♦" }
6
+ end
7
+ end
8
+
9
+ end
data/lib/gamefic/tty.rb CHANGED
@@ -1,3 +1,5 @@
1
+ require 'gamefic/text'
2
+
1
3
  module Gamefic
2
4
  module Engine
3
5
  autoload :Tty, 'gamefic/engine/tty'
@@ -1,14 +1,12 @@
1
1
  require 'gamefic/engine'
2
2
  require 'json'
3
- require 'gamefic/html_to_ansi'
3
+ require 'gamefic/text'
4
4
 
5
5
  module Gamefic
6
6
 
7
7
  # Extend User::Base to convert HTML into ANSI text.
8
8
  #
9
9
  class User::Tty < User::Base
10
- include HtmlToAnsi
11
-
12
10
  def save filename, snapshot
13
11
  data = snapshot.merge(:metadata => @character.plot.metadata)
14
12
  json = JSON.generate data
@@ -48,7 +46,7 @@ module Gamefic
48
46
  end
49
47
 
50
48
  def flush
51
- html_to_ansi(super)
49
+ Gamefic::Text::Html::Conversions.html_to_ansi(super)
52
50
  end
53
51
  end
54
52
 
@@ -1,3 +1,3 @@
1
1
  module Gamefic
2
- VERSION = '1.4.1'
2
+ VERSION = '1.5.0'
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: gamefic
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.4.1
4
+ version: 1.5.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Fred Snyder
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-02-02 00:00:00.000000000 Z
11
+ date: 2017-03-14 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: thor
@@ -134,13 +134,11 @@ files:
134
134
  - bin/gamefic
135
135
  - lib/gamefic.rb
136
136
  - lib/gamefic/action.rb
137
- - lib/gamefic/ansi.rb
138
137
  - lib/gamefic/character.rb
139
138
  - lib/gamefic/command.rb
140
139
  - lib/gamefic/core_ext/array.rb
141
140
  - lib/gamefic/core_ext/string.rb
142
141
  - lib/gamefic/describable.rb
143
- - lib/gamefic/direction.rb
144
142
  - lib/gamefic/director.rb
145
143
  - lib/gamefic/director/delegate.rb
146
144
  - lib/gamefic/director/order.rb
@@ -159,14 +157,16 @@ files:
159
157
  - lib/gamefic/grammar/verb_set.rb
160
158
  - lib/gamefic/grammar/verbs.rb
161
159
  - lib/gamefic/grammar/word_adapter.rb
162
- - lib/gamefic/html.rb
163
- - lib/gamefic/html_to_ansi.rb
164
160
  - lib/gamefic/keywords.rb
165
161
  - lib/gamefic/node.rb
166
162
  - lib/gamefic/plot.rb
167
163
  - lib/gamefic/plot/article_mount.rb
164
+ - lib/gamefic/plot/callbacks.rb
168
165
  - lib/gamefic/plot/command_mount.rb
169
- - lib/gamefic/plot/entity_mount.rb
166
+ - lib/gamefic/plot/entities.rb
167
+ - lib/gamefic/plot/host.rb
168
+ - lib/gamefic/plot/playbook.rb
169
+ - lib/gamefic/plot/players.rb
170
170
  - lib/gamefic/plot/query_mount.rb
171
171
  - lib/gamefic/plot/scene_mount.rb
172
172
  - lib/gamefic/plot/snapshot.rb
@@ -184,7 +184,6 @@ files:
184
184
  - lib/gamefic/query/self.rb
185
185
  - lib/gamefic/query/siblings.rb
186
186
  - lib/gamefic/query/text.rb
187
- - lib/gamefic/rule.rb
188
187
  - lib/gamefic/scene.rb
189
188
  - lib/gamefic/scene/active.rb
190
189
  - lib/gamefic/scene/base.rb
@@ -213,6 +212,11 @@ files:
213
212
  - lib/gamefic/subplot.rb
214
213
  - lib/gamefic/syntax.rb
215
214
  - lib/gamefic/tester.rb
215
+ - lib/gamefic/text.rb
216
+ - lib/gamefic/text/ansi.rb
217
+ - lib/gamefic/text/html.rb
218
+ - lib/gamefic/text/html/conversions.rb
219
+ - lib/gamefic/text/html/entities.rb
216
220
  - lib/gamefic/tty.rb
217
221
  - lib/gamefic/user.rb
218
222
  - lib/gamefic/user/base.rb
@@ -1,46 +0,0 @@
1
- module Gamefic
2
-
3
- class Direction
4
- attr_accessor :name, :adjective, :adverb, :reverse
5
- def initialize args = {}
6
- args.each { |key, value|
7
- send "#{key}=", value
8
- }
9
- if !reverse.nil?
10
- reverse.reverse = self
11
- end
12
- proper_named = true
13
- end
14
- def adjective
15
- @adjective || @name
16
- end
17
- def adverb
18
- @adverb || @name
19
- end
20
- def reverse=(dir)
21
- @reverse = dir
22
- end
23
- def synonyms
24
- "#{adjective} #{adverb}"
25
- end
26
- def to_s
27
- @name
28
- end
29
- def self.find(str)
30
- x = { "north" => NORTH, "south" => SOUTH, "west" => WEST, "east" => EAST, "up" => UP, "down" => DOWN, "northwest" => NORTHWEST, "northeast" => NORTHEAST, "southwest" => SOUTHWEST, "southeast" => SOUTHEAST }
31
- x[str]
32
- end
33
- end
34
-
35
- NORTH = Direction.new(:name => 'north', :adjective => 'northern')
36
- SOUTH = Direction.new(:name => 'south', :adjective => 'southern', :reverse => NORTH)
37
- WEST = Direction.new(:name => 'west', :adjective => 'western')
38
- EAST = Direction.new(:name => 'east', :adjective => 'eastern', :reverse => WEST)
39
- NORTHWEST = Direction.new(:name => 'northwest', :adjective => 'northwestern')
40
- SOUTHEAST = Direction.new(:name => 'southeast', :adjective => 'southeastern', :reverse => NORTHWEST)
41
- NORTHEAST = Direction.new(:name => 'northeast', :adjective => 'northeastern')
42
- SOUTHWEST = Direction.new(:name => 'southwest', :adjective => 'southwestern', :reverse => NORTHEAST)
43
- UP = Direction.new(:name => 'up', :adjective => 'upwards')
44
- DOWN = Direction.new(:name => 'down', :adjective => 'downwards', :reverse => UP)
45
-
46
- end
data/lib/gamefic/html.rb DELETED
@@ -1,68 +0,0 @@
1
- require 'rexml/document'
2
-
3
- module Gamefic
4
-
5
- module Html
6
- # Convert ampersands to &amp;
7
- #
8
- # @param text [String]
9
- # @return [String]
10
- def self.fix_ampersands(text)
11
- codes = []
12
- ENTITIES.keys.each { |e|
13
- codes.push e[1..-1]
14
- }
15
- piped = codes.join('|')
16
- re = Regexp.new("&(?!(#{piped}))")
17
- text.gsub(re, '&amp;\1')
18
- end
19
-
20
- # Encode a String with HTML entities
21
- #
22
- # @param text [String]
23
- # @return [String]
24
- def self.encode(text)
25
- encoded = text
26
- Gamefic::Html::ENTITIES.each { |k, v|
27
- encoded = encoded.gsub(v, k)
28
- }
29
- encoded
30
- end
31
-
32
- # Decode a String's HTML entities
33
- #
34
- # @param text [String]
35
- # @return [String]
36
- def self.decode(text)
37
- Gamefic::Html::ENTITIES.each { |k, v|
38
- text = text.gsub(k, v)
39
- }
40
- text
41
- end
42
-
43
- # Parse a String into an XML document
44
- #
45
- # @param code [String]
46
- # @return [REXML::Document]
47
- def self.parse(code)
48
- code = fix_ampersands(code).strip
49
- last = nil
50
- begin
51
- doc = REXML::Document.new code
52
- rescue REXML::ParseException => e
53
- # Convert invalid < characters to &lt;
54
- if e.source.buffer != last and e.source.buffer[0,1] == '<'
55
- code = code[0,(code.length - e.source.buffer.length)] + '&lt;' + e.source.buffer[1..-1]
56
- last = e.source.buffer
57
- retry
58
- end
59
- raise e
60
- end
61
- end
62
- end
63
-
64
- module Html
65
- ENTITIES = { "&quot;" => "\"", "&amp;" => "&", "&lt;" => "<", "&gt;" => ">", "&nbsp;" => " ", "&iexcl;" => "¡", "&cent;" => "¢", "&pound;" => "£", "&curren;" => "¤", "&yen;" => "¥", "&brvbar;" => "¦", "&sect;" => "§", "&uml;" => "¨", "&copy;" => "©", "&ordf;" => "ª", "&laquo;" => "«", "&not;" => "¬", "&shy;" => "­", "&reg;" => "®", "&macr;" => "¯", "&deg;" => "°", "&plusmn;" => "±", "&sup2;" => "²", "&sup3;" => "³", "&acute;" => "´", "&micro;" => "µ", "&para;" => "¶", "&middot;" => "·", "&cedil;" => "¸", "&sup1;" => "¹", "&ordm;" => "º", "&raquo;" => "»", "&frac14;" => "¼", "&frac12;" => "½", "&frac34;" => "¾", "&iquest;" => "¿", "&Agrave;" => "À", "&Aacute;" => "Á", "&Acirc;" => "Â", "&Atilde;" => "Ã", "&Auml;" => "Ä", "&Aring;" => "Å", "&AElig;" => "Æ", "&Ccedil;" => "Ç", "&Egrave;" => "È", "&Eacute;" => "É", "&Ecirc;" => "Ê", "&Euml;" => "Ë", "&Igrave;" => "Ì", "&Iacute;" => "Í", "&Icirc;" => "Î", "&Iuml;" => "Ï", "&ETH;" => "Ð", "&Ntilde;" => "Ñ", "&Ograve;" => "Ò", "&Oacute;" => "Ó", "&Ocirc;" => "Ô", "&Otilde;" => "Õ", "&Ouml;" => "Ö", "&times;" => "×", "&Oslash;" => "Ø", "&Ugrave;" => "Ù", "&Uacute;" => "Ú", "&Ucirc;" => "Û", "&Uuml;" => "Ü", "&Yacute;" => "Ý", "&THORN;" => "Þ", "&szlig;" => "ß", "&agrave;" => "à", "&aacute;" => "á", "&acirc;" => "â", "&atilde;" => "ã", "&auml;" => "ä", "&aring;" => "å", "&aelig;" => "æ", "&ccedil;" => "ç", "&egrave;" => "è", "&eacute;" => "é", "&ecirc;" => "ê", "&euml;" => "ë", "&igrave;" => "ì", "&iacute;" => "í", "&icirc;" => "î", "&iuml;" => "ï", "&eth;" => "ð", "&ntilde;" => "ñ", "&ograve;" => "ò", "&oacute;" => "ó", "&ocirc;" => "ô", "&otilde;" => "õ", "&ouml;" => "ö", "&divide;" => "÷", "&oslash;" => "ø", "&ugrave;" => "ù", "&uacute;" => "ú", "&ucirc;" => "û", "&uuml;" => "ü", "&yacute;" => "ý", "&thorn;" => "þ", "&yuml;" => "ÿ", "&OElig;" => "Œ", "&oelig;" => "œ", "&Scaron;" => "Š", "&scaron;" => "š", "&Yuml;" => "Ÿ", "&fnof;" => "ƒ", "&circ;" => "ˆ", "&tilde;" => "˜", "&Alpha;" => "Α", "&Beta;" => "Β", "&Gamma;" => "Γ", "&Delta;" => "Δ", "&Epsilon;" => "Ε", "&Zeta;" => "Ζ", "&Eta;" => "Η", "&Theta;" => "Θ", "&Iota;" => "Ι", "&Kappa;" => "Κ", "&Lambda;" => "Λ", "&Mu;" => "Μ", "&Nu;" => "Ν", "&Xi;" => "Ξ", "&Omicron;" => "Ο", "&Pi;" => "Π", "&Rho;" => "Ρ", "&Sigma;" => "Σ", "&Tau;" => "Τ", "&Upsilon;" => "Υ", "&Phi;" => "Φ", "&Chi;" => "Χ", "&Psi;" => "Ψ", "&Omega;" => "Ω", "&alpha;" => "α", "&beta;" => "β", "&gamma;" => "γ", "&delta;" => "δ", "&epsilon;" => "ε", "&zeta;" => "ζ", "&eta;" => "η", "&theta;" => "θ", "&iota;" => "ι", "&kappa;" => "κ", "&lambda;" => "λ", "&mu;" => "μ", "&nu;" => "ν", "&xi;" => "ξ", "&omicron;" => "ο", "&pi;" => "π", "&rho;" => "ρ", "&sigmaf;" => "ς", "&sigma;" => "σ", "&tau;" => "τ", "&upsilon;" => "υ", "&phi;" => "φ", "&chi;" => "χ", "&psi;" => "ψ", "&omega;" => "ω", "&thetasym;" => "ϑ", "&upsih;" => "ϒ", "&piv;" => "ϖ", "&ensp;" => " ", "&emsp;" => " ", "&thinsp;" => " ", "&zwnj;" => "‌", "&zwj;" => "‍", "&lrm;" => "‎", "&rlm;" => "‏", "&ndash;" => "–", "&mdash;" => "—", "&lsquo;" => "‘", "&rsquo;" => "’", "&sbquo;" => "‚", "&ldquo;" => "“", "&rdquo;" => "”", "&bdquo;" => "„", "&dagger;" => "†", "&Dagger;" => "‡", "&bull;" => "•", "&hellip;" => "…", "&permil;" => "‰", "&prime;" => "′", "&Prime;" => "″", "&lsaquo;" => "‹", "&rsaquo;" => "›", "&oline;" => "‾", "&frasl;" => "⁄", "&euro;" => "€", "&image;" => "ℑ", "&weierp;" => "℘", "&real;" => "ℜ", "&trade;" => "™", "&alefsym;" => "ℵ", "&larr;" => "←", "&uarr;" => "↑", "&rarr;" => "→", "&darr;" => "↓", "&harr;" => "↔", "&crarr;" => "↵", "&lArr;" => "⇐", "&uArr;" => "⇑", "&rArr;" => "⇒", "&dArr;" => "⇓", "&hArr;" => "⇔", "&forall;" => "∀", "&part;" => "∂", "&exist;" => "∃", "&empty;" => "∅", "&nabla;" => "∇", "&isin;" => "∈", "&notin;" => "∉", "&ni;" => "∋", "&prod;" => "∏", "&sum;" => "∑", "&minus;" => "−", "&lowast;" => "∗", "&radic;" => "√", "&prop;" => "∝", "&infin;" => "∞", "&ang;" => "∠", "&and;" => "∧", "&or;" => "∨", "&cap;" => "∩", "&cup;" => "∪", "&int;" => "∫", "&there4;" => "∴", "&sim;" => "∼", "&cong;" => "≅", "&asymp;" => "≈", "&ne;" => "≠", "&equiv;" => "≡", "&le;" => "≤", "&ge;" => "≥", "&sub;" => "⊂", "&sup;" => "⊃", "&nsub;" => "⊄", "&sube;" => "⊆", "&supe;" => "⊇", "&oplus;" => "⊕", "&otimes;" => "⊗", "&perp;" => "⊥", "&sdot;" => "⋅", "&lceil;" => "⌈", "&rceil;" => "⌉", "&lfloor;" => "⌊", "&rfloor;" => "⌋", "&lang;" => "〈", "&rang;" => "〉", "&loz;" => "◊", "&spades;" => "♠", "&clubs;" => "♣", "&hearts;" => "♥", "&diams;" => "♦" }
66
- end
67
-
68
- end
@@ -1,185 +0,0 @@
1
- require 'gamefic/ansi'
2
- require 'gamefic/html'
3
- require 'io/console'
4
-
5
- module Gamefic
6
-
7
- module HtmlToAnsi
8
- include Ansi
9
- include Ansi::Code
10
-
11
- def html_to_ansi text, wrap: true, width: nil
12
- return '' if text.strip == ''
13
- output = ''
14
- begin
15
- doc = Html.parse("<body>#{text.strip}</body>")
16
- format_recursively doc
17
- texts = REXML::XPath.match(doc, './/text()')
18
- output = texts.join('').gsub(/&apos;/, "'").gsub(/&quot;/, '"').gsub(/&lt;/, '<').gsub(/&gt;/, '>')
19
- output += Ansi.graphics_mode(Attribute::NORMAL)
20
- output = Html.decode(output)
21
- rescue REXML::ParseException => e
22
- output = Html.encode(text) + "\n\n"
23
- #output = data
24
- end
25
- output.gsub!(/(\n\n)+/, "\n\n")
26
- calc_width = size[0] || width
27
- if calc_width.nil? or !wrap
28
- output
29
- else
30
- terminalize(output, calc_width - 1)
31
- end
32
- output
33
- end
34
-
35
- private
36
-
37
- def format_recursively(top, stack = nil)
38
- ol_index = 1
39
- stack ||= [Attribute::NORMAL]
40
- top.elements.each { |element|
41
- formats = [Attribute::NORMAL]
42
- classes = element.attribute('class').to_s.split(' ')
43
- if classes.include?('hint')
44
- formats.push Foreground::YELLOW
45
- end
46
- case element.name
47
- when 'strong', 'b'
48
- formats.push Attribute::BOLD
49
- when 'em', 'i', 'u'
50
- formats.push Attribute::UNDERSCORE
51
- when 'a'
52
- if element.attributes['rel'].to_s == 'gamefic'
53
- element.attributes['href'] = element.attributes['href'][5..-1]
54
- formats.push [Attribute::UNDERSCORE, Extra::COMMAND]
55
- else
56
- formats.push [Attribute::UNDERSCORE, Extra::HREF]
57
- end
58
- when 'li'
59
- if top.name == 'ol'
60
- element.text = "#{ol_index}. #{element.text}"
61
- ol_index += 1
62
- else
63
- element.text = "* #{element.text}"
64
- end
65
- formats.push [Extra::LINE]
66
- when 'img'
67
- formats.push [Extra::IGNORED]
68
- when 'body', 'p', 'ol', 'ul'
69
- formats.push Extra::BLOCK
70
- when 'pre'
71
- formats.push [Extra::BLOCK, Extra::PRE]
72
- when 'nav'
73
- formats.push Extra::BLOCK
74
- when 'h1', 'h2', 'h3', 'h4', 'h5'
75
- formats.push [Attribute::BOLD, Extra::BLOCK, Extra::UPPERCASE]
76
- when 'kbd'
77
- formats.push [Foreground::GREEN]
78
- end
79
- if has_code?(stack, Extra::IGNORED)
80
- element.parent.delete_element(element)
81
- end
82
- stack.push formats
83
- if has_code?(stack, Extra::UPPERCASE)
84
- element.texts.each { |text|
85
- text.value.upcase!
86
- }
87
- end
88
- element.texts.each { |text|
89
- text.value = "#{Ansi.graphics_mode(*stack)}#{text.value}"
90
- }
91
- if has_code?(stack.last, Extra::IMAGE)
92
- element.text = "#{element.attribute('alt') ? element.attribute('alt') : '[Image]'}"
93
- end
94
- format_recursively element, stack
95
- if has_code?(stack.last, Extra::COMMAND)
96
- if element.attribute('data-command').to_s != ''
97
- tmp = stack.pop
98
- element.add_text "#{Ansi.graphics_mode(*stack)}"
99
- element.add_text " [#{element.attribute('data-command')}]"
100
- stack.push tmp
101
- element.add_text "#{Ansi.graphics_mode(*stack)}"
102
- end
103
- end
104
- if has_code?(stack.last, Extra::BLOCK) and !has_code?(stack.last, Extra::PRE)
105
- element.texts.first.value.lstrip! unless element.texts.first.nil?
106
- element.texts.last.value.rstrip! unless element.texts.last.nil?
107
- element.texts.each { |t|
108
- t.value = t.value.gsub(/ +/, ' ').strip
109
- }
110
- end
111
- if has_code?(stack.last, Extra::BLOCK)
112
- element.add_text("\n\n")
113
- elsif has_code?(stack.last, Extra::LINE)
114
- if !has_code?(stack[-2], Extra::BLOCK) || element != top.elements.to_a.last
115
- element.add_text("\n")
116
- end
117
- end
118
- if has_code?(stack.last, Extra::HREF)
119
- if element.attribute('href').to_s != "#"
120
- tmp = stack.pop
121
- element.add_text "#{Ansi.graphics_mode(*stack)}"
122
- element.add_text(" [#{element.attribute('href')}]")
123
- stack.push tmp
124
- element.add_text "#{Ansi.graphics_mode(*stack)}"
125
- end
126
- end
127
- if has_code?(stack.last, Extra::IMAGE)
128
- element.add_text(" [#{element.attribute('src')}]")
129
- if !has_code?(stack, Extra::BLOCK)
130
- element.add_text("\n\n")
131
- end
132
- end
133
- stack.pop
134
- }
135
- end
136
-
137
- def terminalize string, max_length
138
- i = 0
139
- output = ''
140
- line_length = 0
141
- while i < string.length
142
- line_length += 1
143
- char = string[i,1]
144
- if char == "\e"
145
- # Right now, graphics modes are the only supported ANSI sequences.
146
- end_of_seq = string.index("m", i)
147
- output += string[i..end_of_seq]
148
- i = end_of_seq + 1
149
- elsif char == " "
150
- next_space = string.index(/[\s]/, i + 1)
151
- if !next_space.nil? and line_length + (next_space - i) > max_length
152
- output += "\n"
153
- line_length = 0
154
- else
155
- output += char
156
- end
157
- i += 1
158
- else
159
- if char == "\n"
160
- line_length = 0
161
- end
162
- output += char
163
- i += 1
164
- end
165
- end
166
- output #output.strip
167
- end
168
-
169
- def has_code?(fmt, code)
170
- if fmt.kind_of?(Array)
171
- return fmt.flatten.include?(code)
172
- end
173
- return fmt == code
174
- end
175
-
176
- def size
177
- begin
178
- return STDOUT.winsize.reverse
179
- rescue
180
- return [nil,nil]
181
- end
182
- end
183
- end
184
-
185
- end
@@ -1,45 +0,0 @@
1
- module Gamefic
2
-
3
- module Plot::EntityMount
4
- # Make a new Entity with the provided properties.
5
- #
6
- # @example Create an Entity
7
- # chair = make Entity, :name => 'red chair'
8
- # chair.name #=> 'red chair'
9
- #
10
- # @param cls [Class] The Class of the Entity to be created.
11
- # @param args [Hash] The entity's properties.
12
- # @return The Entity instance.
13
- def make(cls, args = {}, &block)
14
- ent = cls.new(self, args, &block)
15
- if ent.kind_of?(Entity) == false
16
- raise "Invalid entity class"
17
- end
18
- ent
19
- end
20
- # Pick an entity based on its description.
21
- # The description provided must match exactly one entity; otherwise
22
- # an error is raised.
23
- #
24
- # @example Select the Entity that matches the description
25
- # red_chair = make Entity, :name => 'red chair'
26
- # blue_chair make Entity, :name => 'blue chair'
27
- # pick "red chair" #=> red_chair
28
- # pick "blue chair" #=> blue_chair
29
- # pick "chair" #=> IndexError: description is ambiguous
30
- #
31
- # @param @description [String] The description of the entity
32
- # @return [Entity] The entity that matches the description
33
- def pick(description)
34
- query = Gamefic::Query::Base.new
35
- result = query.match(description, entities)
36
- if result.objects.length == 0
37
- raise IndexError.new("Unable to find entity from '#{description}'")
38
- elsif result.objects.length > 1
39
- raise IndexError.new("Ambiguous entities found from '#{description}'")
40
- end
41
- result.objects[0]
42
- end
43
- end
44
-
45
- end