tpmkms_4wp 9.1.1-beta.3 → 9.1.1-beta.30

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 (47) hide show
  1. package/common/animals.instance.json +13 -0
  2. package/common/articles.js +1 -0
  3. package/common/asking.test.json +193 -72
  4. package/common/colors.instance.json +14 -28
  5. package/common/comparable.instance.json +3 -0
  6. package/common/concept.js +1 -1
  7. package/common/crew.instance.json +26 -0
  8. package/common/dialogues.js +2 -1
  9. package/common/dimension.instance.json +1 -0
  10. package/common/edible.instance.json +36 -56
  11. package/common/emotions.instance.json +1 -0
  12. package/common/events.js +3 -3
  13. package/common/events.test.json +107 -36
  14. package/common/fastfood.instance.json +2215 -13572
  15. package/common/fastfood.js +2 -1
  16. package/common/formulas.instance.json +1 -0
  17. package/common/formulas.js +3 -1
  18. package/common/formulas.test.json +643 -711
  19. package/common/helpers/concept.js +6 -2
  20. package/common/helpers/dialogues.js +1 -1
  21. package/common/helpers/menus.js +154 -0
  22. package/common/helpers.js +16 -0
  23. package/common/kirk.instance.json +1 -0
  24. package/common/length.instance.json +15 -0
  25. package/common/math.instance.json +1 -0
  26. package/common/menus.instance.json +8922 -1
  27. package/common/menus.js +206 -8
  28. package/common/menus.test.json +21990 -1
  29. package/common/ordering.instance.json +2 -0
  30. package/common/people.instance.json +96 -8
  31. package/common/pipboy.instance.json +21 -57
  32. package/common/pokemon.instance.json +13 -8
  33. package/common/pressure.instance.json +4 -0
  34. package/common/properties.instance.json +1 -0
  35. package/common/reports.instance.json +18 -23
  36. package/common/reports.js +12 -3
  37. package/common/sdefaults.js +25 -0
  38. package/common/spock.instance.json +1 -0
  39. package/common/stm.js +2 -1
  40. package/common/temperature.instance.json +4 -112
  41. package/common/tester.js +24 -2
  42. package/common/ui.instance.json +446 -0
  43. package/common/ui.js +9 -4
  44. package/common/ui.test.json +6794 -0
  45. package/common/weight.instance.json +14 -0
  46. package/common/wp.instance.json +6118 -58
  47. package/package.json +3 -2
package/common/menus.js CHANGED
@@ -1,16 +1,55 @@
1
1
  const { knowledgeModule, where, Digraph } = require('./runtime').theprogrammablemind
2
2
  const { defaultContextCheck } = require('./helpers')
3
3
  const ui = require('./ui')
4
- const menus_tests = require('./menus.test.json')
5
- const menus_instance = require('./menus.instance.json')
4
+ const helpers = require('./helpers/menus')
5
+ const tests = require('./menus.test.json')
6
+ const instance = require('./menus.instance.json')
6
7
 
7
- class API {
8
- initialize({ objects }) {
8
+ class MenusAPI {
9
+ initialize({ objects, config }) {
10
+ this._config = config
9
11
  this._objects = objects
12
+ this._objects.show = []
13
+ this._objects.menuDefs = []
14
+ this._objects.directions = {}
15
+ }
16
+
17
+ setup() {
18
+ this._objects.directions = {
19
+ right: helpers.calculateRights(this._objects.menuDefs),
20
+ left: helpers.calculateLefts(this._objects.menuDefs),
21
+ up: helpers.calculateUps(this._objects.menuDefs),
22
+ down: helpers.calculateDowns(this._objects.menuDefs),
23
+ parents: helpers.calculateParents(this._objects.menuDefs),
24
+ paths: helpers.calculatePaths(this._objects.menuDefs),
25
+ }
26
+ }
27
+
28
+ close() {
29
+ this._objects.close = true
10
30
  }
11
31
 
12
32
  move(direction, steps = 1, units = undefined) {
13
33
  this._objects.move = { direction, steps, units }
34
+ let next = this.current()
35
+ if (direction === 'left' || direction === 'right' ){
36
+ next = this._objects.directions.parents[next]
37
+ }
38
+ for (let i = 0; i < steps; ++i) {
39
+ next = this._objects.directions[direction][next]
40
+ }
41
+ if (next) {
42
+ this.show(next)
43
+ }
44
+ }
45
+
46
+ show(item) {
47
+ this._objects.show.push(item)
48
+ this._objects.current = item
49
+ }
50
+
51
+ current() {
52
+ return this._objects.current
14
53
  }
15
54
 
16
55
  select(item) {
@@ -28,6 +67,44 @@ class API {
28
67
  stop(action) {
29
68
  this._objects.stop = action
30
69
  }
70
+
71
+ addMenu(name) {
72
+ const config = this._config
73
+ const id = name
74
+ const languageId = `${name}Menu_menus`
75
+ config.addOperator(`([${languageId}|])`)
76
+ config.addBridge({
77
+ id: `${languageId}`,
78
+ associations: [languageId, 'menus'],
79
+ isA: ['menu_menus'],
80
+ words: [{ word: name, value: id, instance: true }],
81
+ })
82
+ this._objects.menuDefs.push({
83
+ key: name,
84
+ text: name,
85
+ children: [],
86
+ })
87
+ this.setup()
88
+ return { languageId, id }
89
+ }
90
+
91
+ addMenuItem(menuId, id, name) {
92
+ const config = this._config
93
+ const languageId = `${id}MenuItem_menus`
94
+ config.addOperator(`([${languageId}|])`)
95
+ config.addBridge({
96
+ id: `${languageId}`,
97
+ associations: [menuId.languageId, 'menus'],
98
+ isA: ['menu_menus_item_menus'],
99
+ words: [{ word: name, value: id, path: [menuId.id, id], instance: true }],
100
+ })
101
+ const menu = this._objects.menuDefs.find((md) => md.key == menuId.id)
102
+ menu.children.push({
103
+ key: id,
104
+ text: name,
105
+ })
106
+ this.setup()
107
+ }
31
108
  }
32
109
 
33
110
  const config = {
@@ -35,27 +112,148 @@ const config = {
35
112
  };
36
113
 
37
114
  const template = {
115
+ configs: [
116
+ 'setidsuffix _menus',
117
+ "menu is a concept",
118
+ "item is a concept",
119
+ "menu modifies item",
120
+ "menus and menu items are showable",
121
+ {
122
+ operators: [
123
+ "([show_menus|show] (showable_menus))",
124
+ "([close_menus|close] (menu_menus/*))",
125
+ "((@<= menu_menus) [typeOfMenu_menus|show] (@== menu_menus))",
126
+ ],
127
+ bridges: [
128
+ {
129
+ id: 'close_menus',
130
+ isA: ['verb'],
131
+ associations: ['menus'],
132
+ bridge: "{ ...next(operator), closee: after[0], generate: ['this', 'closee'] }",
133
+ semantic: ({context, api}) => {
134
+ api.close()
135
+ }
136
+ },
137
+ {
138
+ id: 'show_menus',
139
+ isA: ['verb'],
140
+ bridge: "{ ...next(operator), show: after[0], generate: ['this', 'show'] }",
141
+ semantic: ({context, api}) => {
142
+ if (context.show.instance) {
143
+ api.show(context.show.value)
144
+ }
145
+ }
146
+ },
147
+ {
148
+ id: 'typeOfMenu_menus',
149
+ convolution: true,
150
+ isA: ['adjective'],
151
+ bridge: "{ ...after[0], modifiers: ['menus'], menus: before[0] }",
152
+ },
153
+ ],
154
+ semantics: [
155
+ {
156
+ where: where(),
157
+ match: ({context, isA}) => isA(context, 'showable_menus'),
158
+ apply: async ({context, insert, s, fragments}) => {
159
+ const value = context
160
+ const fragment = fragments("show showable")
161
+ const mappings = [{
162
+ where: where(),
163
+ match: ({context}) => context.value == 'showable_menus',
164
+ apply: ({context}) => Object.assign(context, value),
165
+ }]
166
+ const instantiation = await fragment.instantiate(mappings)
167
+ await s(instantiation)
168
+ }
169
+ },
170
+ ]
171
+ },
172
+ ],
38
173
  fragments: [
174
+ "show showable",
39
175
  ],
40
176
  }
41
177
 
178
+ class UIAPI {
179
+ constructor(menusAPI) {
180
+ this.menusAPI = menusAPI
181
+ }
182
+
183
+ initialize() {
184
+ }
185
+
186
+ move(direction, steps = 1, units = undefined) {
187
+ this.menusAPI.move(direction, steps, units)
188
+ }
189
+
190
+ select(item) {
191
+ this.menusAPI.select(item)
192
+ }
193
+
194
+ unselect(item) {
195
+ this.menusAPI.unselect(item)
196
+ }
197
+
198
+ cancel(direction) {
199
+ this.menusAPI.cancel(direction)
200
+ }
201
+
202
+ stop(action) {
203
+ this.menusAPI.stop(action)
204
+ }
205
+
206
+ }
207
+
208
+ /*
209
+ show the file menu
210
+ pick the file open item
211
+ show file
212
+
213
+ file (<- instance of menu) menu (<- concept of menu)
214
+ */
215
+ // called for the non-module load to setup fixtures
216
+ const fixtures = async ({api, fragment, s, config, objects, kms, isModule}) => {
217
+ const fileMenuId = api.addMenu('file')
218
+ const objectMenuId = api.addMenu('object')
219
+
220
+ api.addMenuItem(fileMenuId, 'fileOpen', 'open')
221
+ api.addMenuItem(fileMenuId, 'fileOpenRemote', 'open remote')
222
+ api.addMenuItem(fileMenuId, 'fileClose', 'close')
223
+
224
+ api.addMenuItem(objectMenuId, 'objectOpen', 'open')
225
+ api.addMenuItem(objectMenuId, 'objectClose', 'close')
226
+ }
227
+
42
228
  knowledgeModule({
43
229
  config,
44
230
  includes: [ui],
45
- api: () => new API(),
231
+ // api: () => new API(),
232
+ api: () => {
233
+ const menusAPI = new MenusAPI()
234
+ return {
235
+ 'menus': menusAPI,
236
+ 'ui': new UIAPI(menusAPI)
237
+ }
238
+ },
239
+ apiKMs: ['menus', 'ui'],
240
+ initializer: ({apis}) => {
241
+ apis('sdefaults').addAssociation('menus')
242
+ },
46
243
 
47
244
  module,
48
245
  description: 'Control menues with speech',
49
246
  test: {
50
247
  name: './menus.test.json',
51
- contents: menus_tests,
248
+ contents: tests,
249
+ fixtures,
52
250
  checks: {
53
- objects: ['move', 'select', 'unselect', 'cancel', 'stop'],
251
+ objects: ['move', 'select', 'unselect', 'cancel', 'stop', 'show', 'menuDefs', 'close'],
54
252
  context: defaultContextCheck(['operator', 'direction', 'moveable']),
55
253
  },
56
254
  },
57
255
  template: {
58
256
  template,
59
- instance: menus_instance
257
+ instance,
60
258
  }
61
259
  })