tpmkms 9.1.1-beta.0 → 9.1.1-beta.10

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 (43) 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 +1938 -13407
  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 +148 -5
  27. package/common/menus.test.json +12297 -1
  28. package/common/ordering.instance.json +2 -0
  29. package/common/people.instance.json +96 -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/ui.instance.json +1 -0
  40. package/common/ui.js +3 -1
  41. package/common/weight.instance.json +14 -0
  42. package/common/wp.instance.json +28 -58
  43. package/package.json +3 -2
package/common/menus.js CHANGED
@@ -1,16 +1,49 @@
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
8
  class API {
8
9
  initialize({ objects }) {
9
10
  this._objects = objects
11
+ this._objects.show = []
12
+ this._objects.menuDefs = []
13
+ this._objects.directions = {}
14
+ }
15
+
16
+ setup() {
17
+ this._objects.directions = {
18
+ right: helpers.calculateRights(this._objects.menuDefs),
19
+ left: helpers.calculateLefts(this._objects.menuDefs),
20
+ up: helpers.calculateUps(this._objects.menuDefs),
21
+ down: helpers.calculateDowns(this._objects.menuDefs),
22
+ parents: helpers.calculateParents(this._objects.menuDefs),
23
+ }
10
24
  }
11
25
 
12
26
  move(direction, steps = 1, units = undefined) {
13
27
  this._objects.move = { direction, steps, units }
28
+ let next = this.current()
29
+ if (direction === 'left' || direction === 'right' ){
30
+ next = this._objects.directions.parents[next]
31
+ }
32
+ for (let i = 0; i < steps; ++i) {
33
+ next = this._objects.directions[direction][next]
34
+ }
35
+ if (next) {
36
+ this.show(next)
37
+ }
38
+ }
39
+
40
+ show(item) {
41
+ this._objects.show.push(item)
42
+ this._objects.current = item
43
+ }
44
+
45
+ current() {
46
+ return this._objects.current
14
47
  }
15
48
 
16
49
  select(item) {
@@ -28,6 +61,44 @@ class API {
28
61
  stop(action) {
29
62
  this._objects.stop = action
30
63
  }
64
+
65
+ addMenu(name) {
66
+ const config = this.args.config
67
+ const id = name
68
+ const languageId = `${name}Menu_menus`
69
+ config.addOperator(`([${languageId}|])`)
70
+ config.addBridge({
71
+ id: `${languageId}`,
72
+ associations: [languageId, 'menus'],
73
+ isA: ['menu_menus'],
74
+ words: [{ word: name, value: id, instance: true }],
75
+ })
76
+ this._objects.menuDefs.push({
77
+ key: name,
78
+ text: name,
79
+ children: [],
80
+ })
81
+ this.setup()
82
+ return { languageId, id }
83
+ }
84
+
85
+ addMenuItem(menuId, id, name) {
86
+ const config = this.args.config
87
+ const languageId = `${id}MenuItem_menus`
88
+ config.addOperator(`([${languageId}|])`)
89
+ config.addBridge({
90
+ id: `${languageId}`,
91
+ associations: [menuId.languageId, 'menus'],
92
+ isA: ['menu_menus_item_menus'],
93
+ words: [{ word: name, value: id, path: [menuId.id, id], instance: true }],
94
+ })
95
+ const menu = this._objects.menuDefs.find((md) => md.key == menuId.id)
96
+ menu.children.push({
97
+ key: id,
98
+ text: name,
99
+ })
100
+ this.setup()
101
+ }
31
102
  }
32
103
 
33
104
  const config = {
@@ -35,27 +106,99 @@ const config = {
35
106
  };
36
107
 
37
108
  const template = {
109
+ configs: [
110
+ 'setidsuffix _menus',
111
+ "menu is a concept",
112
+ "item is a concept",
113
+ "menu modifies item",
114
+ "menus and menu items are showable",
115
+ {
116
+ operators: [
117
+ "([show_menus|show] (showable_menus))",
118
+ "((@<= menu_menus) [typeOfMenu_menus|show] (@== menu_menus))",
119
+ ],
120
+ bridges: [
121
+ {
122
+ id: 'show_menus',
123
+ isA: ['verb'],
124
+ bridge: "{ ...next(operator), show: after[0], generate: ['this', 'show'] }",
125
+ semantic: ({context, api}) => {
126
+ if (context.show.instance) {
127
+ api.show(context.show.value)
128
+ }
129
+ }
130
+ },
131
+ {
132
+ id: 'typeOfMenu_menus',
133
+ convolution: true,
134
+ isA: ['adjective'],
135
+ bridge: "{ ...after[0], modifiers: ['menus'], menus: before[0] }",
136
+ },
137
+ ],
138
+ semantics: [
139
+ {
140
+ where: where(),
141
+ match: ({context, isA}) => isA(context, 'showable_menus'),
142
+ apply: async ({context, insert, s, fragments}) => {
143
+ const value = context
144
+ const fragment = fragments("show showable")
145
+ const mappings = [{
146
+ where: where(),
147
+ match: ({context}) => context.value == 'showable_menus',
148
+ apply: ({context}) => Object.assign(context, value),
149
+ }]
150
+ const instantiation = await fragment.instantiate(mappings)
151
+ await s(instantiation)
152
+ }
153
+ },
154
+ ]
155
+ },
156
+ ],
38
157
  fragments: [
158
+ "show showable",
39
159
  ],
40
160
  }
41
161
 
162
+ /*
163
+ show the file menu
164
+ pick the file open item
165
+ show file
166
+
167
+ file (<- instance of menu) menu (<- concept of menu)
168
+ */
169
+ // called for the non-module load to setup fixtures
170
+ const fixtures = async ({api, fragment, s, config, objects, kms, isModule}) => {
171
+ const fileMenuId = api.addMenu('file')
172
+ const objectMenuId = api.addMenu('object')
173
+
174
+ api.addMenuItem(fileMenuId, 'fileOpen', 'open')
175
+ api.addMenuItem(fileMenuId, 'fileClose', 'close')
176
+ api.addMenuItem(objectMenuId, 'objectOpen', 'open')
177
+ api.addMenuItem(objectMenuId, 'objectClose', 'close')
178
+ }
179
+
42
180
  knowledgeModule({
43
181
  config,
44
182
  includes: [ui],
45
183
  api: () => new API(),
184
+ apiKMs: ['menus', 'ui'],
185
+ initializer: ({apis}) => {
186
+ apis('sdefaults').addAssociation('menus')
187
+ },
46
188
 
47
189
  module,
48
190
  description: 'Control menues with speech',
49
191
  test: {
50
192
  name: './menus.test.json',
51
- contents: menus_tests,
193
+ contents: tests,
194
+ fixtures,
52
195
  checks: {
53
- objects: ['move', 'select', 'unselect', 'cancel', 'stop'],
196
+ objects: ['move', 'select', 'unselect', 'cancel', 'stop', 'show', 'menuDefs'],
54
197
  context: defaultContextCheck(['operator', 'direction', 'moveable']),
55
198
  },
56
199
  },
57
200
  template: {
58
201
  template,
59
- instance: menus_instance
202
+ instance,
60
203
  }
61
204
  })