inform-runtime 1.0.4

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.
Files changed (59) hide show
  1. checksums.yaml +7 -0
  2. data/LICENSE +623 -0
  3. data/README.md +185 -0
  4. data/Rakefile +65 -0
  5. data/config/database.yml +37 -0
  6. data/exe/inform.rb +6 -0
  7. data/game/config.yml +5 -0
  8. data/game/example.inf +76 -0
  9. data/game/example.rb +90 -0
  10. data/game/forms/example_form.rb +2 -0
  11. data/game/grammar/game_grammar.inf.rb +11 -0
  12. data/game/languages/english.rb +2 -0
  13. data/game/models/example_model.rb +2 -0
  14. data/game/modules/example_module.rb +9 -0
  15. data/game/rules/example_state.rb +2 -0
  16. data/game/scripts/example_script.rb +2 -0
  17. data/game/topics/example_topic.rb +2 -0
  18. data/game/verbs/game_verbs.rb +15 -0
  19. data/game/verbs/metaverbs.rb +2028 -0
  20. data/lib/runtime/articles.rb +138 -0
  21. data/lib/runtime/builtins.rb +359 -0
  22. data/lib/runtime/color.rb +145 -0
  23. data/lib/runtime/command.rb +470 -0
  24. data/lib/runtime/config.rb +48 -0
  25. data/lib/runtime/context.rb +78 -0
  26. data/lib/runtime/daemon.rb +266 -0
  27. data/lib/runtime/database.rb +500 -0
  28. data/lib/runtime/events.rb +771 -0
  29. data/lib/runtime/experimental/handler_dsl.rb +175 -0
  30. data/lib/runtime/game.rb +74 -0
  31. data/lib/runtime/game_loader.rb +132 -0
  32. data/lib/runtime/grammar_parser.rb +553 -0
  33. data/lib/runtime/helpers.rb +177 -0
  34. data/lib/runtime/history.rb +45 -0
  35. data/lib/runtime/inflector.rb +195 -0
  36. data/lib/runtime/io.rb +174 -0
  37. data/lib/runtime/kernel.rb +450 -0
  38. data/lib/runtime/library.rb +59 -0
  39. data/lib/runtime/library_loader.rb +135 -0
  40. data/lib/runtime/link.rb +158 -0
  41. data/lib/runtime/logging.rb +197 -0
  42. data/lib/runtime/mixins.rb +570 -0
  43. data/lib/runtime/module.rb +202 -0
  44. data/lib/runtime/object.rb +761 -0
  45. data/lib/runtime/options.rb +104 -0
  46. data/lib/runtime/persistence.rb +292 -0
  47. data/lib/runtime/plurals.rb +60 -0
  48. data/lib/runtime/prototype.rb +307 -0
  49. data/lib/runtime/publication.rb +92 -0
  50. data/lib/runtime/runtime.rb +321 -0
  51. data/lib/runtime/session.rb +202 -0
  52. data/lib/runtime/stdlib.rb +604 -0
  53. data/lib/runtime/subscription.rb +47 -0
  54. data/lib/runtime/tag.rb +287 -0
  55. data/lib/runtime/tree.rb +204 -0
  56. data/lib/runtime/version.rb +24 -0
  57. data/lib/runtime/world_tree.rb +69 -0
  58. data/lib/runtime.rb +35 -0
  59. metadata +199 -0
@@ -0,0 +1,202 @@
1
+ # encoding: utf-8
2
+ # frozen_string_literal: false
3
+
4
+ # Copyright Nels Nelson 2008-2023 but freely usable (see license)
5
+ #
6
+ # This file is part of the Inform Runtime.
7
+ #
8
+ # The Inform Runtime is free software: you can redistribute it and/or
9
+ # modify it under the terms of the GNU General Public License as published
10
+ # by the Free Software Foundation, either version 3 of the License, or
11
+ # (at your option) any later version.
12
+ #
13
+ # The Inform Runtime is distributed in the hope that it will be useful,
14
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
15
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16
+ # GNU General Public License for more details.
17
+ #
18
+ # You should have received a copy of the GNU General Public License
19
+ # along with the Inform Runtime. If not, see <http://www.gnu.org/licenses/>.
20
+
21
+ # Module
22
+
23
+ if defined?(Sequel::Migration)
24
+ # The ModuleSetup class
25
+ class ModuleSetup < Sequel::Migration
26
+ def up
27
+ log.debug "#up"
28
+ create_table? :module do
29
+ primary_key :id
30
+ index :name
31
+ index :created_at
32
+
33
+ String :name, unique: true, null: false
34
+ DateTime :created_at
35
+ DateTime :modified_at
36
+ end
37
+ end
38
+
39
+ def down
40
+ drop_table(:module, cascade: true) if table_exists? :module
41
+ end
42
+ end
43
+ # class ModuleSetup
44
+ end
45
+ # defined?(Sequel::Migration)
46
+
47
+ # The Inform module
48
+ module Inform
49
+ # Deine the Inform::Module class
50
+ class Module < Sequel::Model
51
+ set_primary_key :id
52
+ def_column_accessor :created_at, :modified_at
53
+ def_column_accessor :name
54
+
55
+ def to_s
56
+ name
57
+ end
58
+
59
+ def <=>(other)
60
+ self.name <=> other.name
61
+ end
62
+
63
+ def self.tidy
64
+ db << %{delete from module where id in
65
+ (select a.id from module a group by a.id, a.name
66
+ having ((select count(b.id) from modularized b
67
+ where b.module_id = a.id) = 0))}
68
+ return nil
69
+ end
70
+
71
+ # rubocop: disable Style/FormatString
72
+ # rubocop: disable Style/FormatStringToken
73
+ def self.dirty
74
+ results = db.fetch %{select a.id, a.name from module a group by a.id, a.name having
75
+ ((select count(b.id) from modularized b where b.module_id = a.id) = 0)}
76
+ return nil if results.empty?
77
+ s = ["%5s %20s" % results.first.keys]
78
+ s.concat(results.collect { |row| "%5d %20s" % row.values })
79
+ s.join("\n")
80
+ end
81
+ # rubocop: enable Style/FormatString
82
+ # rubocop: enable Style/FormatStringToken
83
+
84
+ # rubocop: disable Style/FormatString
85
+ # rubocop: disable Style/FormatStringToken
86
+ def self.stats
87
+ results = db.fetch %{select a.*, count(a.id) as "number modularized"
88
+ from module a, modularized b where b.module_id = a.id group by a.id, a.name}
89
+ return nil if results.empty?
90
+ s = ["%5s %20s %15s" % results.first.keys]
91
+ s.concat(results.collect { |row| "%5d %20s %15s" % row.values })
92
+ s.join("\n")
93
+ end
94
+ # rubocop: enable Style/FormatString
95
+ # rubocop: enable Style/FormatStringToken
96
+ end
97
+ end
98
+ # module Inform
99
+
100
+ # Modularized
101
+
102
+ if defined?(Sequel::Migration)
103
+ # The ModularizedSetup class
104
+ class ModularizedSetup < Sequel::Migration
105
+ def up
106
+ create_table? :modularized do
107
+ primary_key :id
108
+ foreign_key :object_id, :object, on_delete: :cascade
109
+ foreign_key :module_id, :module, on_delete: :cascade
110
+ end
111
+ end
112
+
113
+ def down
114
+ drop_table(:modularized, cascade: true) if table_exists? :modularized
115
+ end
116
+ end
117
+ # class ModularizedSetup
118
+ end
119
+ # defined?(Sequel::Migration)
120
+
121
+ # The Inform module
122
+ module Inform
123
+ # The Inform::Modularized class
124
+ class Modularized < Sequel::Model
125
+ set_primary_key :id
126
+ end
127
+ end
128
+ # module Inform
129
+
130
+ # Modular
131
+
132
+ # The Inform module
133
+ module Inform
134
+ # The Inform::Modular module
135
+ module Modular
136
+ def after_initialize
137
+ self.apply_modules
138
+ super
139
+ end
140
+
141
+ def modules
142
+ super
143
+ rescue StandardError => _e
144
+ Array::Empty
145
+ end
146
+
147
+ def mod(*args)
148
+ a = args.flatten.collect(&:to_s)
149
+ (a - (nil_safe_modules & a)).each do |mod|
150
+ add_module(Inform::Module.find_or_create(name: mod))
151
+ end
152
+ save
153
+ apply_modules
154
+ self
155
+ end
156
+
157
+ def unmod(*args)
158
+ (nil_safe_modules & args.flatten.collect(&:to_s)).each do |mod|
159
+ remove_module(Inform::Module.find(name: mod))
160
+ end
161
+ save
162
+ i = parent(self)
163
+ self.remove
164
+ i << self
165
+ self
166
+ end
167
+
168
+ def modules_semaphore
169
+ @modules_semaphore ||= Mutex.new
170
+ end
171
+
172
+ def nil_safe_modules
173
+ modules.compact.map(&:to_s)
174
+ end
175
+
176
+ def apply_modules(exceptions = [])
177
+ nil_safe_modules.each do |module_name|
178
+ next if exceptions.include?(module_name.to_sym)
179
+ mod = find_module(module_name)
180
+ next if mod.nil?
181
+ mod.ancestors.reverse.each do |ancestor|
182
+ self.extend(ancestor)
183
+ end
184
+ end
185
+ self
186
+ end
187
+
188
+ # TODO: This is broken somehow FIXME
189
+ def reset_modules
190
+ nil_safe_modules.each do |module_name|
191
+ remove_module(module_name)
192
+ mod = find_module(module_name)
193
+ next if mod.nil?
194
+ mod.instance_methods.each { |method_name| undef_method(method_name) }
195
+ end
196
+ save
197
+ self
198
+ end
199
+ end
200
+ # module Inform::Modular
201
+ end
202
+ # module Inform