tpmkms_4wp 9.1.1-beta.3 → 9.1.1-beta.31

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 -0
  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 -0
  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 +2322 -13547
  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 +10096 -1
  27. package/common/menus.js +207 -8
  28. package/common/menus.test.json +26162 -1
  29. package/common/ordering.instance.json +2 -0
  30. package/common/people.instance.json +156 -8
  31. package/common/pipboy.instance.json +49 -1
  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 +28 -3
  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 -2
  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,149 @@ 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
+ "resetidsuffix",
173
+ ],
38
174
  fragments: [
175
+ "show showable",
39
176
  ],
40
177
  }
41
178
 
179
+ class UIAPI {
180
+ constructor(menusAPI) {
181
+ this.menusAPI = menusAPI
182
+ }
183
+
184
+ initialize() {
185
+ }
186
+
187
+ move(direction, steps = 1, units = undefined) {
188
+ this.menusAPI.move(direction, steps, units)
189
+ }
190
+
191
+ select(item) {
192
+ this.menusAPI.select(item)
193
+ }
194
+
195
+ unselect(item) {
196
+ this.menusAPI.unselect(item)
197
+ }
198
+
199
+ cancel(direction) {
200
+ this.menusAPI.cancel(direction)
201
+ }
202
+
203
+ stop(action) {
204
+ this.menusAPI.stop(action)
205
+ }
206
+
207
+ }
208
+
209
+ /*
210
+ show the file menu
211
+ pick the file open item
212
+ show file
213
+
214
+ file (<- instance of menu) menu (<- concept of menu)
215
+ */
216
+ // called for the non-module load to setup fixtures
217
+ const fixtures = async ({api, fragment, s, config, objects, kms, isModule}) => {
218
+ const fileMenuId = api.addMenu('file')
219
+ const objectMenuId = api.addMenu('object')
220
+
221
+ api.addMenuItem(fileMenuId, 'fileOpen', 'open')
222
+ api.addMenuItem(fileMenuId, 'fileOpenRemote', 'open remote')
223
+ api.addMenuItem(fileMenuId, 'fileClose', 'close')
224
+
225
+ api.addMenuItem(objectMenuId, 'objectOpen', 'open')
226
+ api.addMenuItem(objectMenuId, 'objectClose', 'close')
227
+ }
228
+
42
229
  knowledgeModule({
43
230
  config,
44
231
  includes: [ui],
45
- api: () => new API(),
232
+ // api: () => new API(),
233
+ api: () => {
234
+ const menusAPI = new MenusAPI()
235
+ return {
236
+ 'menus': menusAPI,
237
+ 'ui': new UIAPI(menusAPI)
238
+ }
239
+ },
240
+ apiKMs: ['menus', 'ui'],
241
+ initializer: ({apis}) => {
242
+ apis('sdefaults').addAssociation('menus')
243
+ },
46
244
 
47
245
  module,
48
246
  description: 'Control menues with speech',
49
247
  test: {
50
248
  name: './menus.test.json',
51
- contents: menus_tests,
249
+ contents: tests,
250
+ fixtures,
52
251
  checks: {
53
- objects: ['move', 'select', 'unselect', 'cancel', 'stop'],
252
+ objects: ['move', 'select', 'unselect', 'cancel', 'stop', 'show', 'menuDefs', 'close'],
54
253
  context: defaultContextCheck(['operator', 'direction', 'moveable']),
55
254
  },
56
255
  },
57
256
  template: {
58
257
  template,
59
- instance: menus_instance
258
+ instance,
60
259
  }
61
260
  })