CharStatus.svelte 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  1. <script>
  2. import { decode } from '$lib/util';
  3. import Select from '../Select.svelte';
  4. import BodyPartIcon from './BodyPartIcon.svelte';
  5. import { enumAvaliableMeleeStyles, getStamina, setSelectedMeleeStyle } from './attack';
  6. import { renderBlocks } from './blocks';
  7. import { getBloodLevel } from './blood';
  8. import { Cash } from './cash';
  9. import { Profession } from './profession';
  10. let { world, char, tick } = $props();
  11. const health = {
  12. head: 0.75,
  13. body: 0.95,
  14. larm: 0.90,
  15. rarm: 1.00,
  16. lleg: 0.54,
  17. rleg: 0.31,
  18. };
  19. const styles = {
  20. hunger: '#aa0',
  21. thirst: '#aa0',
  22. };
  23. const descriptions = {
  24. head: 'You selected head',
  25. body: 'Body',
  26. larm: 'Your left arm is fine',
  27. rarm: 'Your right arm is in perfect shape',
  28. lleg: 'Your left leg bleeds!',
  29. rleg: 'Your right leg is heavily damaged!',
  30. };
  31. let selected = $state(null);
  32. let description = $derived(descriptions[selected] ?? '');
  33. let dynamicStyle = $derived(Object.entries(styles).map(([k, v]) => `--${k}: ${v}`).join(';'));
  34. let profession = $derived(decode(Profession.profession[char]));
  35. let staminaLine = $derived((tick, renderBlocks(getStamina(world, char))));
  36. let bloodLine = $derived((tick, renderBlocks(getBloodLevel(world, char))));
  37. let meleeStyles = $derived((tick, enumAvaliableMeleeStyles(world, char).map(([name, style]) => { return {name, style} })));
  38. let meleeStyleIndex = $state(0);
  39. $effect(() => {
  40. setSelectedMeleeStyle(world, char, meleeStyles[meleeStyleIndex].name);
  41. });
  42. const select = (part) => () => {
  43. if (selected === part) {
  44. selected = null;
  45. } else {
  46. selected = part;
  47. }
  48. };
  49. </script>
  50. <!--
  51. │┤╡╢╖╕╣║╗╝╜╛┐
  52. └┴┬├─┼╞╟╚╔╩╦╠═╬╧
  53. ╨╤╥╙╘╒╓╫╪┘┌
  54. ≡±≥≤
  55. ('-')
  56. ──╥──
  57. ║║║
  58. ╜ ╙
  59. {'-'}
  60. ≥─╥─≤
  61. ┌╨┐
  62. ╜ ╙
  63. -->
  64. <!-- ░▒▓█ -->
  65. <section class="stat" style="{dynamicStyle}">
  66. ${Cash.amount[char]} L1+23%
  67. {profession}
  68. <pre><span class="test">
  69. {'{'}'-x}
  70. ≥─╥─≤
  71. ┌╨┐
  72. ╜ ╙
  73. </span></pre>
  74. <!-- <BodyPartIcon {health} {selected} {select} part="head">(^_^)</BodyPartIcon>
  75. <BodyPartIcon {health} {selected} {select} part="larm">╓</BodyPartIcon><BodyPartIcon {health} {selected} {select} part="body">─╥─</BodyPartIcon><BodyPartIcon {health} {selected} {select} part="rarm">╖</BodyPartIcon>
  76. <BodyPartIcon {health} {selected} {select} part="body">║║║</BodyPartIcon>
  77. <BodyPartIcon {health} {selected} {select} part="lleg">╜</BodyPartIcon> <BodyPartIcon {health} {selected} {select} part="rleg">╙</BodyPartIcon> -->
  78. <!-- </pre> -->
  79. <div>{description}</div>
  80. <div>[<span class="stamina">{staminaLine}</span>]</div>
  81. <div>[<span class="blood">{bloodLine}</span>]</div>
  82. <div>
  83. <h3>Style</h3>
  84. <Select options={meleeStyles} bind:index={meleeStyleIndex} />
  85. </div>
  86. <button>More</button>
  87. </section>
  88. <style>
  89. .test {
  90. animation: wounded linear 1000ms infinite;
  91. animation-direction: alternate;
  92. /* text-shadow: 1px 1px 0 #d1d; */
  93. }
  94. @keyframes wounded {
  95. 0% {
  96. text-shadow: 1px 1px 6px #d11;
  97. }
  98. 100% {
  99. text-shadow: 1px 1px 1px #d11;
  100. }
  101. }
  102. .stamina {
  103. font-family: 'Square';
  104. color: #384;
  105. }
  106. .blood {
  107. font-family: 'Square';
  108. color: #834;
  109. }
  110. </style>