tpmkms 7.12.4-beta.0 → 7.12.4-beta.2

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.
@@ -391,25 +391,27 @@ const template = {
391
391
  },
392
392
  {
393
393
  operators: [
394
- "([change] (meal/*) (to/1))",
394
+ "([change] (meal/* || drink/*) (to/1))",
395
395
  ],
396
396
  hierarchy: [
397
397
  ['meal', 'toAble'],
398
+ ['drink', 'toAble'],
398
399
  ],
399
400
  bridges: [
400
401
  {
401
402
  id: "change",
402
403
  isA: ['verby'],
404
+ localHierarchy: [ ['thisitthat', 'meal'] ],
403
405
  generatorp: ({context, gp}) => `change ${gp(context.from)} to ${gp(context.to)}`,
404
406
  bridge: "{ ...next(operator), from: after[0], to: after[1].toObject }",
405
- semantic: ({context, api}) => {
407
+ semantic: ({context, api, e}) => {
406
408
  const state = api.state
409
+ const eFrom = e(context.from).evalue
410
+ const from = state.getIdCombo(eFrom.fromSTM ? eFrom : context.from)
411
+ const to = state.getIdCombo(context.to)
407
412
  for (const item of api.items()) {
408
- const from = state.getIdCombo(context.from)
409
- const to = state.getIdCombo(context.to)
410
413
  if (item.id == from.id) {
411
- debugger
412
- api.modify(item, { id: to.id })
414
+ api.modify(item, { id: to.id, food: context.to })
413
415
  }
414
416
  }
415
417
  }
@@ -430,6 +432,35 @@ const template = {
430
432
  { context: [['combo', 2], ['list', 0], ['combo', 1], ['withModification', 1]], ordered: true, choose: [3] },
431
433
  ],
432
434
  },
435
+ {
436
+ operators: [
437
+ "([remove|remove,delete,drop,ditch,forget,no] (food/*))",
438
+ "([reset|reset,restart,clear])",
439
+ ],
440
+ bridges: [
441
+ {
442
+ id: 'remove',
443
+ isA: ['verby'],
444
+ bridge: "{ ...next(operator), remove: after[0], postModifiers: ['remove'] }",
445
+ semantic: ({context, api}) => {
446
+ const state = api.state
447
+ for (const item of api.items()) {
448
+ if (state.match(context.remove, item)) {
449
+ api.remove(item)
450
+ }
451
+ }
452
+ }
453
+ },
454
+ {
455
+ id: 'reset',
456
+ isA: ['verby'],
457
+ bridge: "{ ...next(operator) }",
458
+ semantic: ({context, api}) => {
459
+ api.reset()
460
+ }
461
+ },
462
+ ],
463
+ },
433
464
  ],
434
465
  }
435
466
 
@@ -439,37 +470,63 @@ class API {
439
470
  this._objects.items = []
440
471
  this._objects.notAvailable = []
441
472
  this._objects.notAvailableModification = []
473
+ this._objects.item_id_counter = 0
442
474
  }
443
475
 
444
476
  show() {
445
477
  this._objects.show = this._objects.items
446
478
  }
447
479
 
480
+ toItem(item_id) {
481
+ if (Array.isArray(item_id)) {
482
+ return this._objects.items[item_id[0]].modifications[item_id[1]]
483
+ } else {
484
+ return this._objects.items[item_id]
485
+ }
486
+ }
487
+
488
+ new_item_id() {
489
+ const item_id = this._objects.item_id_counter
490
+ this._objects.item_id_counter += 1
491
+ return item_id
492
+ }
493
+
448
494
  // returns an item id so things can be updated if needed
449
495
  add(item) {
450
- item.item_id = this._objects.items.length
496
+ item.item_id = this.new_item_id()
451
497
  if (!item.modifications) {
452
498
  item.modifications = []
453
499
  }
500
+ item.modifications.forEach((modification, index) => {
501
+ modification.item_id = [item.item_id, index]
502
+ })
454
503
  this._objects.items.push(item)
455
- return item.item_id
504
+ }
505
+
506
+ reset() {
507
+ this._objects.items = []
456
508
  }
457
509
 
458
510
  get(item_id) {
459
- return this._objects.items[item_id]
511
+ return this.toItem(item_id)
460
512
  }
461
513
 
462
514
  modify(item, changes) {
463
- Object.assign(this._objects.items[item.item_id], changes)
515
+ Object.assign(this.toItem(item.item_id), changes)
516
+ }
517
+
518
+ remove(item) {
519
+ this._objects.items = this._objects.items.filter( (i) => i.item_id !== item.item_id )
464
520
  }
465
521
 
466
522
  items() {
467
- return this._objects.items
523
+ return [...this._objects.items]
468
524
  }
469
525
 
470
526
  addDrink(item_id, drink) {
471
- this._objects.items[item_id].modifications.push(drink)
472
- this._objects.items[item_id].needsDrink = false
527
+ const item = this.toItem(item_id)
528
+ item.modifications.push(drink)
529
+ item.needsDrink = false
473
530
  }
474
531
 
475
532
  say(response) {
@@ -663,7 +720,7 @@ class State {
663
720
  }
664
721
  combo = true
665
722
  } else if (food.marker == 'combo') {
666
- id = food.type.value
723
+ id = food.type?.value
667
724
  combo = true
668
725
  } else {
669
726
  id = food.value
@@ -677,6 +734,18 @@ class State {
677
734
  return { id, combo }
678
735
  }
679
736
 
737
+ match(pattern, item) {
738
+ Object.assign(pattern, this.getIdCombo(pattern))
739
+ if (pattern.id == item.id) {
740
+ return true
741
+ }
742
+ if (!pattern.id) {
743
+ if (pattern.combo == item.combo) {
744
+ return true
745
+ }
746
+ }
747
+ }
748
+
680
749
  add(food) {
681
750
  let quantity = 1
682
751
  if (food.quantity) {
@@ -748,7 +817,8 @@ class State {
748
817
  return
749
818
  }
750
819
 
751
- const item_id = this.api.add(item)
820
+ this.api.add(item)
821
+ this.api.args.mentioned(food)
752
822
 
753
823
  for (const addIt of addsInsteadOfModifications) {
754
824
  this.add(addIt)
@@ -788,7 +858,7 @@ const createConfig = (additionalConfig) => {
788
858
  },
789
859
  {
790
860
  where: where(),
791
- match: ({context, isAListable}) => isAListable(context, 'edible') && context.marker !== 'edible' && !context.same && !context.isResponse,
861
+ match: ({context, isAListable}) => isAListable(context, 'edible') && context.marker !== 'edible' && !context.same && !context.isResponse && !context.evaluate,
792
862
  apply: ({context, km, api, instance}) => {
793
863
  for (const element of propertyToArray(context)) {
794
864
  km('fastfood').api.state.add(element)
@@ -841,10 +911,23 @@ knowledgeModule( {
841
911
  checks: {
842
912
  objects: [
843
913
  'show',
844
- { property: 'items', filter: ['combo', 'pieces', 'size', 'item_id', 'id', 'modifications', 'needsDrink'] },
914
+ {
915
+ property: 'items',
916
+ filter: [
917
+ 'combo',
918
+ 'pieces',
919
+ 'size',
920
+ 'item_id',
921
+ 'id',
922
+ { property: 'food', filter: [ 'marker', 'value', 'text' ] },
923
+ { property: 'modifications', filter: [ 'id', 'item_id', 'food' ] },
924
+ 'needsDrink'
925
+ ],
926
+ },
845
927
  'changes',
846
928
  'response',
847
929
  { property: 'notAvailable', filter: [ 'marker', 'value', 'text' ] },
930
+ { property: 'notAvailableModification', filter: [ 'marker', 'value', 'text' ] },
848
931
  { property: 'quantity', filter: ['marker', 'value', 'text' ] },
849
932
  { property: 'pieces', filter: ['marker', 'value', 'text' ] },
850
933
  ],