You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

84 lines
2.0 KiB

  1. <script lang="ts">
  2. import type { GoalCompositionMode } from "../models/goal";
  3. import type { LogResult } from "../models/log";
  4. interface CompositionItem {
  5. link: string
  6. amount: number
  7. name: string
  8. }
  9. export let logs: LogResult[] = [];
  10. export let mode: GoalCompositionMode = "item";
  11. let list: CompositionItem[] = [];
  12. $: {
  13. const map: {[k: string]: CompositionItem} = {}
  14. if (mode === "item") {
  15. for (const log of logs) {
  16. if (log.itemCounted !== false) {
  17. const item = log.item;
  18. if (!map[item.id]) {
  19. map[item.id] = {name: item.name, amount: log.itemAmount, link: `/items#${item.id}`};
  20. } else {
  21. map[item.id].amount += log.itemAmount;
  22. }
  23. }
  24. if (log.secondaryItem && log.secondaryItemCounted !== false) {
  25. const item = log.secondaryItem;
  26. if (!map[item.id]) {
  27. map[item.id] = {name: item.name, amount: log.secondaryItemAmount, link: `/items#${item.id}`};
  28. } else {
  29. map[item.id].amount += log.secondaryItemAmount;
  30. }
  31. }
  32. }
  33. } else {
  34. for (const log of logs) {
  35. const task = log.task;
  36. const amount = log.secondaryItem ? log.secondaryItemAmount + log.itemAmount : log.itemAmount;
  37. if (!map[task.id]) {
  38. map[task.id] = {name: task.name, amount, link: `/questlog#${task.projectId}`};
  39. } else {
  40. map[task.id].amount += amount;
  41. }
  42. }
  43. }
  44. list = Object.keys(map).sort((a, b) => map[b].amount - map[a].amount).map(k => map[k]).filter(e => e.amount > 0);
  45. }
  46. </script>
  47. <div class="composition">
  48. {#each list as item (item.name)}
  49. <div class="item">
  50. <span class="amount">{item.amount}x&nbsp;</span>
  51. <a href={item.link}>{item.name}</a>
  52. </div>
  53. {/each}
  54. </div>
  55. <style>
  56. div.composition {
  57. padding: 0.25em 0ch;
  58. color: #555;
  59. font-size: 0.75em;
  60. }
  61. div.item {
  62. padding: 0.125em 0.5ch;
  63. display: inline-block;
  64. }
  65. span.amount {
  66. color: #777;
  67. }
  68. a {
  69. color: inherit;
  70. }
  71. </style>