tpmkms_4wp 9.1.1-beta.2 → 9.1.1-beta.20

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 (44) 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 +1139 -12736
  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 +132 -0
  22. package/common/kirk.instance.json +1 -0
  23. package/common/length.instance.json +15 -0
  24. package/common/math.instance.json +1 -0
  25. package/common/menus.instance.json +6264 -1
  26. package/common/menus.js +204 -8
  27. package/common/menus.test.json +15797 -1
  28. package/common/ordering.instance.json +2 -0
  29. package/common/people.instance.json +132 -8
  30. package/common/pipboy.instance.json +21 -57
  31. package/common/pokemon.instance.json +13 -8
  32. package/common/pressure.instance.json +4 -0
  33. package/common/properties.instance.json +1 -0
  34. package/common/reports.instance.json +18 -23
  35. package/common/reports.js +12 -3
  36. package/common/sdefaults.js +25 -0
  37. package/common/spock.instance.json +1 -0
  38. package/common/temperature.instance.json +4 -112
  39. package/common/tester.js +24 -2
  40. package/common/ui.instance.json +1 -0
  41. package/common/ui.js +3 -1
  42. package/common/weight.instance.json +14 -0
  43. package/common/wp.instance.json +28 -58
  44. package/package.json +3 -2
package/common/menus.js CHANGED
@@ -1,16 +1,54 @@
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
+ }
25
+ }
26
+
27
+ close() {
28
+ this._objects.close = true
10
29
  }
11
30
 
12
31
  move(direction, steps = 1, units = undefined) {
13
32
  this._objects.move = { direction, steps, units }
33
+ let next = this.current()
34
+ if (direction === 'left' || direction === 'right' ){
35
+ next = this._objects.directions.parents[next]
36
+ }
37
+ for (let i = 0; i < steps; ++i) {
38
+ next = this._objects.directions[direction][next]
39
+ }
40
+ if (next) {
41
+ this.show(next)
42
+ }
43
+ }
44
+
45
+ show(item) {
46
+ this._objects.show.push(item)
47
+ this._objects.current = item
48
+ }
49
+
50
+ current() {
51
+ return this._objects.current
14
52
  }
15
53
 
16
54
  select(item) {
@@ -28,6 +66,44 @@ class API {
28
66
  stop(action) {
29
67
  this._objects.stop = action
30
68
  }
69
+
70
+ addMenu(name) {
71
+ const config = this._config
72
+ const id = name
73
+ const languageId = `${name}Menu_menus`
74
+ config.addOperator(`([${languageId}|])`)
75
+ config.addBridge({
76
+ id: `${languageId}`,
77
+ associations: [languageId, 'menus'],
78
+ isA: ['menu_menus'],
79
+ words: [{ word: name, value: id, instance: true }],
80
+ })
81
+ this._objects.menuDefs.push({
82
+ key: name,
83
+ text: name,
84
+ children: [],
85
+ })
86
+ this.setup()
87
+ return { languageId, id }
88
+ }
89
+
90
+ addMenuItem(menuId, id, name) {
91
+ const config = this._config
92
+ const languageId = `${id}MenuItem_menus`
93
+ config.addOperator(`([${languageId}|])`)
94
+ config.addBridge({
95
+ id: `${languageId}`,
96
+ associations: [menuId.languageId, 'menus'],
97
+ isA: ['menu_menus_item_menus'],
98
+ words: [{ word: name, value: id, path: [menuId.id, id], instance: true }],
99
+ })
100
+ const menu = this._objects.menuDefs.find((md) => md.key == menuId.id)
101
+ menu.children.push({
102
+ key: id,
103
+ text: name,
104
+ })
105
+ this.setup()
106
+ }
31
107
  }
32
108
 
33
109
  const config = {
@@ -35,27 +111,147 @@ const config = {
35
111
  };
36
112
 
37
113
  const template = {
114
+ configs: [
115
+ 'setidsuffix _menus',
116
+ "menu is a concept",
117
+ "item is a concept",
118
+ "menu modifies item",
119
+ "menus and menu items are showable",
120
+ {
121
+ operators: [
122
+ "([show_menus|show] (showable_menus))",
123
+ "([close_menus|close] (menu_menus/*))",
124
+ "((@<= menu_menus) [typeOfMenu_menus|show] (@== menu_menus))",
125
+ ],
126
+ bridges: [
127
+ {
128
+ id: 'close_menus',
129
+ isA: ['verb'],
130
+ associations: ['menus'],
131
+ bridge: "{ ...next(operator), closee: after[0], generate: ['this', 'closee'] }",
132
+ semantic: ({context, api}) => {
133
+ debugger
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, 'fileClose', 'close')
222
+ api.addMenuItem(objectMenuId, 'objectOpen', 'open')
223
+ api.addMenuItem(objectMenuId, 'objectClose', 'close')
224
+ }
225
+
42
226
  knowledgeModule({
43
227
  config,
44
228
  includes: [ui],
45
- api: () => new API(),
229
+ // api: () => new API(),
230
+ api: () => {
231
+ const menusAPI = new MenusAPI()
232
+ return {
233
+ 'menus': menusAPI,
234
+ 'ui': new UIAPI(menusAPI)
235
+ }
236
+ },
237
+ apiKMs: ['menus', 'ui'],
238
+ initializer: ({apis}) => {
239
+ apis('sdefaults').addAssociation('menus')
240
+ },
46
241
 
47
242
  module,
48
243
  description: 'Control menues with speech',
49
244
  test: {
50
245
  name: './menus.test.json',
51
- contents: menus_tests,
246
+ contents: tests,
247
+ fixtures,
52
248
  checks: {
53
- objects: ['move', 'select', 'unselect', 'cancel', 'stop'],
249
+ objects: ['move', 'select', 'unselect', 'cancel', 'stop', 'show', 'menuDefs', 'close'],
54
250
  context: defaultContextCheck(['operator', 'direction', 'moveable']),
55
251
  },
56
252
  },
57
253
  template: {
58
254
  template,
59
- instance: menus_instance
255
+ instance,
60
256
  }
61
257
  })