story-teller 1.1.3

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