Skip to content

Commit

Permalink
fix(items): fixed a bug where items would crash the tab
Browse files Browse the repository at this point in the history
  • Loading branch information
liana-p committed Jan 29, 2024
1 parent fa1028a commit 49a3089
Show file tree
Hide file tree
Showing 7 changed files with 40 additions and 5 deletions.
8 changes: 8 additions & 0 deletions docs/features/items.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,18 @@ There are also interaction groups which allow scripts to toggle on/off whether u
Config:

```yaml
categories:
- id: food
title: Food
- id: books
title: Books

items:
bread:
name: Bread
description: A bread in the game.
icon: img/items/bread.png
category: food
onUse:
action: jump
label: eat_bread
Expand All @@ -30,6 +37,7 @@ items:
name: Ominous Book
description: An ominous book
icon: img/items/book.png
category: books
onUse:
action: run_label
label: read_book
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,24 @@
---
categories:
- id: food
title: Food
- id: books
title: Books

items:
bread:
name: Bread
description: A bread in the game.
icon: img/items/bread.webp
category: food
onUse:
action: jump
label: eat_bread
book:
name: Ominous Book
description: An ominous book.
icon: img/items/book.webp
category: books
onUse:
action: run
label: read_book
Expand Down
Original file line number Diff line number Diff line change
@@ -1 +1,5 @@
categories:
- id: my_category
title: Some Category

items: {}
2 changes: 1 addition & 1 deletion packages/create-narrat/template/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
"dependencies": {
"electron-squirrel-startup": "^1.0.0",
"es6-promise": "^4.2.8",
"narrat": "3.9.2",
"narrat": "3.9.5",
"pinia": "^2.1.7",
"steamworks.js": "^0.2.0",
"vue": "^3.4.15"
Expand Down
6 changes: 4 additions & 2 deletions packages/narrat/src/components/inventory-ui.vue
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,10 @@ function closeItem() {
chosenId.value = false;
}
function useItem() {
store.useItem(chosenItem.value!);
close();
const result = store.useItem(chosenItem.value!);
if (result) {
close();
}
}
</script>

Expand Down
9 changes: 9 additions & 0 deletions packages/narrat/src/examples/demo/config/items.yaml
Original file line number Diff line number Diff line change
@@ -1,14 +1,23 @@
---
categories:
- id: food
title: Food
- id: books
title: Books

items:
bread:
name: Bread
description: A bread in the game.
category: food
icon: img/items/bread.webp
onUse:
action: jump
label: eat_bread
book:
name: Ominous Book
description: An ominous book.
category: books
icon: img/items/book.webp
onUse:
action: run
Expand Down
7 changes: 5 additions & 2 deletions packages/narrat/src/stores/inventory-store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -156,20 +156,23 @@ export const useInventory = defineStore('inventory', {
}
return false;
},
useItem(item: ItemState) {
useItem(item: ItemState): boolean {
let result = false;
const conf = getItemConfig(item.id);
if (item && this.canUseItem(item) && conf) {
const onUse = conf.onUse!;
close();
result = true;
audioEvent('onItemUsed');
if (onUse.action === 'jump') {
useVM().jumpToLabel(onUse.label);
} else if (onUse.action === 'run') {
useVM().runThenGoBackToPreviousDialog(onUse.label, true);
} else {
result = false;
error(`Unknown action ${onUse.action}`);
}
}
return result;
},
},
});
Expand Down

0 comments on commit 49a3089

Please sign in to comment.