tpmkms 7.12.4-beta.1 → 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.
@@ -411,7 +411,7 @@ const template = {
411
411
  const to = state.getIdCombo(context.to)
412
412
  for (const item of api.items()) {
413
413
  if (item.id == from.id) {
414
- api.modify(item, { id: to.id })
414
+ api.modify(item, { id: to.id, food: context.to })
415
415
  }
416
416
  }
417
417
  }
@@ -432,6 +432,35 @@ const template = {
432
432
  { context: [['combo', 2], ['list', 0], ['combo', 1], ['withModification', 1]], ordered: true, choose: [3] },
433
433
  ],
434
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
+ },
435
464
  ],
436
465
  }
437
466
 
@@ -441,28 +470,53 @@ class API {
441
470
  this._objects.items = []
442
471
  this._objects.notAvailable = []
443
472
  this._objects.notAvailableModification = []
473
+ this._objects.item_id_counter = 0
444
474
  }
445
475
 
446
476
  show() {
447
477
  this._objects.show = this._objects.items
448
478
  }
449
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
+
450
494
  // returns an item id so things can be updated if needed
451
495
  add(item) {
452
- item.item_id = this._objects.items.length
496
+ item.item_id = this.new_item_id()
453
497
  if (!item.modifications) {
454
498
  item.modifications = []
455
499
  }
500
+ item.modifications.forEach((modification, index) => {
501
+ modification.item_id = [item.item_id, index]
502
+ })
456
503
  this._objects.items.push(item)
457
- return item.item_id
504
+ }
505
+
506
+ reset() {
507
+ this._objects.items = []
458
508
  }
459
509
 
460
510
  get(item_id) {
461
- return this._objects.items[item_id]
511
+ return this.toItem(item_id)
462
512
  }
463
513
 
464
514
  modify(item, changes) {
465
- 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 )
466
520
  }
467
521
 
468
522
  items() {
@@ -470,8 +524,9 @@ class API {
470
524
  }
471
525
 
472
526
  addDrink(item_id, drink) {
473
- this._objects.items[item_id].modifications.push(drink)
474
- this._objects.items[item_id].needsDrink = false
527
+ const item = this.toItem(item_id)
528
+ item.modifications.push(drink)
529
+ item.needsDrink = false
475
530
  }
476
531
 
477
532
  say(response) {
@@ -665,7 +720,7 @@ class State {
665
720
  }
666
721
  combo = true
667
722
  } else if (food.marker == 'combo') {
668
- id = food.type.value
723
+ id = food.type?.value
669
724
  combo = true
670
725
  } else {
671
726
  id = food.value
@@ -679,6 +734,18 @@ class State {
679
734
  return { id, combo }
680
735
  }
681
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
+
682
749
  add(food) {
683
750
  let quantity = 1
684
751
  if (food.quantity) {
@@ -844,7 +911,19 @@ knowledgeModule( {
844
911
  checks: {
845
912
  objects: [
846
913
  'show',
847
- { 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
+ },
848
927
  'changes',
849
928
  'response',
850
929
  { property: 'notAvailable', filter: [ 'marker', 'value', 'text' ] },