Feast 2.0!
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.
 
 
 
 
 

420 lines
10 KiB

  1. <template>
  2. <div @click="$emit('select', $el)" @keyup.enter="$emit('select', $el)" class="statblock" tabindex="0">
  3. <div class="statblock-shader statblock-shader-hover"></div>
  4. <div class="statblock-shader statblock-shader-selected marching-ants"></div>
  5. <div class="statblock-shader statblock-shader-selected-ally marching-ants"></div>
  6. <div class="statblock-shader statblock-shader-current-turn marching-ants"></div>
  7. <div class="statblock-shader statblock-shader-dead">
  8. <i class="fas fa-skull-crossbones" />
  9. </div>
  10. <div class="statblock-shader statblock-shader-eaten"></div>
  11. <div class="statblock-content">
  12. <h2 class="name">
  13. {{subject.name.all.capital.objective}}
  14. <div class="tooltip-template">
  15. <div class="tooltip-title">{{ subject.title }}</div>
  16. <div class="tooltip-body">{{ subject.desc }}</div>
  17. </div>
  18. </h2>
  19. <div v-if="initiative !== undefined"> Initiative: {{ (initiative).toFixed(0) }}%</div>
  20. <div class="statblock-status-icons">
  21. <i :class="status.icon" v-for="(status, index) in subject.status" :key="'status' + index">
  22. <div class="statblock-status-icon-topleft">{{ status.topLeft }}</div>
  23. <div class="statblock-status-icon-bottomright">{{ status.bottomRight }}</div>
  24. <div class="tooltip-template">
  25. <div class="tooltip-title">{{ status.name }}</div>
  26. <div class="tooltip-body">{{ status.desc }}</div>
  27. </div>
  28. </i>
  29. </div>
  30. <div class="stat-entry" v-for="vigor in Object.keys(subject.vigors)" v-bind:key="vigor">
  31. <div class="healthbar" v-bind:style="{'--fullness': (subject.vigors[vigor]/subject.maxVigors[vigor]*100) + '%', '--color': vigorColor(subject.vigors[vigor], subject.maxVigors[vigor]) }">
  32. <i :class="vigorIcons[vigor]" />
  33. <div class="healthbar-value"> {{ subject.vigors[vigor].toFixed(0) + '/' + subject.maxVigors[vigor].toFixed(0) }}</div>
  34. </div>
  35. <div class="tooltip-template">
  36. <div class="tooltip-title">{{ vigor }}</div>
  37. <div class="tooltip-body">{{ vigorDescs[vigor] }}</div>
  38. </div>
  39. </div>
  40. <div class="stat-line stats">
  41. <div :class="statClass(subject.stats[stat], subject.baseStats[stat])" v-for="stat in Object.keys(subject.stats)" v-bind:key="stat">
  42. <i :class="statIcons[stat]" />
  43. <div class="stat-value">{{subject.stats[stat].toFixed(0)}}</div>
  44. <div class="tooltip-template">
  45. <div class="tooltip-title">{{ stat }}</div>
  46. <div class="tooltip-body">{{ statDescs[stat] }}</div>
  47. </div>
  48. </div>
  49. </div>
  50. <div class="stat-line vore-stats">
  51. <div class="stat-entry" v-for="stat in Object.keys(subject.voreStats)" v-bind:key="stat">
  52. <i :class="voreStatIcons[stat]" />
  53. <div class="stat-value">{{subject.voreStats[stat].toFixed(0)}}</div>
  54. <div class="tooltip-template">
  55. <div class="tooltip-title">{{ stat }}</div>
  56. <div class="tooltip-body">{{ voreStatDescs[stat] }}</div>
  57. </div>
  58. </div>
  59. </div>
  60. <button @click.stop="subject.perspective = POV.First">1st</button>
  61. <button @click.stop="subject.perspective = POV.Second">2nd</button>
  62. <button @click.stop="subject.perspective = POV.Third">3rd</button>
  63. </div>
  64. </div>
  65. </template>
  66. <script lang="ts">
  67. import { Component, Prop, Vue, Watch, Emit } from 'vue-property-decorator'
  68. import { Creature } from '@/game/creature'
  69. import { POV } from '@/game/language'
  70. import { Stats, Stat, StatIcons, StatDescs, Vigor, VigorIcons, VigorDescs, VoreStatDescs, VoreStatIcons, VisibleStatus } from '@/game/combat'
  71. import ContainerView from './ContainerView.vue'
  72. import tippy, { delegate, createSingleton } from 'tippy.js'
  73. import 'tippy.js/dist/tippy.css'
  74. @Component({
  75. components: {
  76. ContainerView
  77. },
  78. data () {
  79. return {
  80. POV: POV
  81. }
  82. },
  83. methods: {
  84. vigorColor (value: number, max: number) {
  85. if (value * 5 <= max) {
  86. return 'red'
  87. } else if (value * 3 <= max) {
  88. return 'yellow'
  89. } else {
  90. return 'green'
  91. }
  92. },
  93. statClass (value: number, normal: number) {
  94. if (value < normal) {
  95. return 'stat-entry crit'
  96. } else if (value > normal) {
  97. return 'stat-entry buff'
  98. } else {
  99. return 'stat-entry'
  100. }
  101. }
  102. }
  103. })
  104. export default class Statblock extends Vue {
  105. @Prop({ type: Creature, required: true })
  106. subject!: Creature
  107. @Prop()
  108. initiative!: number
  109. firstperson: POV = POV.First
  110. thirdperson: POV = POV.Third
  111. private vigorIcons = VigorIcons
  112. private statIcons = StatIcons
  113. private voreStatIcons = VoreStatIcons
  114. private vigorDescs = VigorDescs
  115. private statDescs = StatDescs
  116. private voreStatDescs = VoreStatDescs
  117. private vigor = Vigor
  118. @Watch('subject.status')
  119. private statusChanged (a: Array<VisibleStatus>) {
  120. this.$nextTick(() => {
  121. const icons = Array.from(this.$el.querySelectorAll(".statblock-status-icons i")) as Array<HTMLElement>
  122. icons.map(elem => {
  123. const tooltip = elem.querySelector(".tooltip-template") as HTMLElement
  124. return tippy(elem, {
  125. content: tooltip,
  126. touch: ["hold", 500]
  127. })
  128. })
  129. })
  130. }
  131. mounted () {
  132. const statEntries = Array.from(this.$el.querySelectorAll(".stat-entry"))
  133. const name = Array.from(this.$el.querySelectorAll(".name"))
  134. const tippyInstances = statEntries.concat(name).map(elem => {
  135. const tooltip = elem.querySelector(".tooltip-template") as HTMLElement
  136. return tippy(elem, {
  137. content: tooltip,
  138. touch: ["hold", 500]
  139. })
  140. })
  141. createSingleton(tippyInstances, { delay: 500, touch: ["hold", 500] })
  142. this.statusChanged([])
  143. }
  144. }
  145. </script>
  146. <!-- Add "scoped" attribute to limit CSS to this component only -->
  147. <style scoped>
  148. h2 {
  149. margin-bottom: 8pt;
  150. font-size: 2rem;
  151. }
  152. ul {
  153. list-style-type: none;
  154. padding: 0;
  155. }
  156. li {
  157. display: inline-block;
  158. margin: 0 10px;
  159. }
  160. a {
  161. color: #42b983;
  162. }
  163. .statblock {
  164. flex: 1 0;
  165. flex-basis: 100pt;
  166. margin: 0pt 4pt 0pt;
  167. user-select: none;
  168. position: relative;
  169. overflow: hidden;
  170. background: none;
  171. border-radius: 10px;
  172. outline: none;
  173. }
  174. .stat-line {
  175. width: 100%;
  176. display: flex;
  177. justify-content: space-evenly;
  178. flex-wrap: wrap;
  179. }
  180. .stat-entry {
  181. position: relative;
  182. font-size: 0.75rem;
  183. padding-top: 2pt;
  184. padding-bottom: 2pt;
  185. display: flex;
  186. flex-direction: column;
  187. justify-content: space-evenly;
  188. align-items: center;
  189. user-select: none;
  190. text-align: center;
  191. }
  192. .stat-value {
  193. position: absolute;
  194. transform: translate(0, 8pt);
  195. padding-top: 4pt;
  196. padding-bottom: 4pt;
  197. }
  198. .healthbar {
  199. display: flex;
  200. align-items: center;
  201. justify-content: space-between;
  202. --color: green;
  203. --fullness: 100%;
  204. position: relative;
  205. width: 90%;
  206. margin: 0% 5% 0%;
  207. height: 14pt;
  208. border-radius: 2pt;
  209. border-width: 2pt;
  210. border-color: gray;
  211. border-style: outset;
  212. background: linear-gradient(90deg, var(--color) var(--fullness), black var(--fullness), black);
  213. }
  214. .stat-entry .healthbar i {
  215. flex: 0 1;
  216. flex-basis: 20pt;
  217. font-size: 1rem;
  218. }
  219. .healthbar .healthbar-value {
  220. flex: 1 0;
  221. font-size: 0.75rem;
  222. color: #bbb;
  223. }
  224. .stat-entry > i {
  225. font-size: 1.25rem;
  226. width: 1.5rem;
  227. margin-bottom: 1.25rem;
  228. }
  229. .stat-entry.low {
  230. color: yellow;
  231. }
  232. .stat-entry.crit {
  233. color: red;
  234. }
  235. .stat-entry.buff {
  236. color: green;
  237. }
  238. .statblock-content {
  239. position: relative;
  240. width: 100%;
  241. height: 100%;
  242. background: none;
  243. }
  244. .statblock-shader {
  245. position: absolute;
  246. width: 100%;
  247. height: 100%;
  248. opacity: 0%;
  249. pointer-events: none;
  250. z-index: 0;
  251. }
  252. .statblock[data-destroyed] .statblock-content,
  253. .statblock[data-destroyed] .stat-entry {
  254. animation: destroyed 1s;
  255. animation-fill-mode: both;
  256. overflow: hidden;
  257. }
  258. @keyframes destroyed {
  259. from {
  260. opacity: 1;
  261. }
  262. to {
  263. opacity: 0.25;
  264. }
  265. }
  266. .statblock[data-eaten] .statblock-shader-eaten {
  267. background: repeating-linear-gradient(45deg, transparent, transparent 20px, green 20px, green 40px, transparent 40px);
  268. opacity: 0.5;
  269. }
  270. /* yoinked from https://codepen.io/danichk/pen/PPRxrR?editors=0110 */
  271. .marching-ants {
  272. background: linear-gradient(#111, #111) padding-box, repeating-linear-gradient(-45deg, var(--ants-color) 0, var(--ants-color) 25%, transparent 0, transparent 50%) 0 / 20px 20px;
  273. animation: marching-ants 1s infinite linear;
  274. border: 4px solid transparent;
  275. }
  276. .statblock[data-active] .statblock-shader-selected {
  277. --ants-color: #f88;
  278. border-radius: 8px;
  279. width: calc(100% - 8px);
  280. height: calc(100% - 8px);
  281. opacity: 0.75;
  282. }
  283. .statblock[data-active-ally] .statblock-shader-selected-ally {
  284. --ants-color: #88f;
  285. border-radius: 8px;
  286. width: calc(100% - 8px);
  287. height: calc(100% - 8px);
  288. opacity: 0.75;
  289. }
  290. .statblock[data-current-turn] .statblock-shader-current-turn {
  291. --ants-color: #fff;
  292. border-radius: 8px;
  293. width: calc(100% - 8px);
  294. height: calc(100% - 8px);
  295. opacity: 0.75;
  296. }
  297. @keyframes marching-ants {
  298. from {
  299. background-position: 0px 0px;
  300. }
  301. to {
  302. background-position: 20px 20px;
  303. }
  304. }
  305. .statblock-shader-dead i {
  306. font-size: 5rem;
  307. position: absolute;
  308. top: 50%;
  309. transform: translate(-50%, -50%);
  310. }
  311. .statblock[data-dead] .statblock-shader-dead {
  312. background: repeating-linear-gradient(45deg, red, red 20px, transparent 20px, transparent 40px, red 40px);
  313. opacity: 0.50;
  314. }
  315. .statblock:hover[data-active] .statblock-shader-hover {
  316. opacity: 0;
  317. }
  318. .statblock:hover .statblock-shader-hover,
  319. .statblock:focus .statblock-shader-hover {
  320. background: white;
  321. opacity: 0.20;
  322. }
  323. .statblock[data-active] .if-not-selected {
  324. display: none;
  325. }
  326. .statblock .if-ally {
  327. display: none;
  328. }
  329. .statblock[data-ally] .if-ally {
  330. display: block;
  331. }
  332. .statblock-status-icons {
  333. display: flex;
  334. justify-content: space-evenly;
  335. min-height: 1.25rem;
  336. }
  337. .statblock-status-icons > i {
  338. font-size: 1.25rem;
  339. position: relative;
  340. }
  341. .statblock-status-icon-topleft,
  342. .statblock-status-icon-bottomright {
  343. position: absolute;
  344. font-family: sans-serif;
  345. font-weight: 300;
  346. color: #999;
  347. }
  348. .statblock-status-icon-topleft {
  349. top: -12pt;
  350. }
  351. .statblock-status-icon-bottomright {
  352. top: 4pt;
  353. right: -12pt;
  354. }
  355. </style>
  356. <style>
  357. .left-stats .stat-entry::after {
  358. transform: translate(calc(0% + 16pt), -100%);
  359. }
  360. .left-stats .stat-entry::before {
  361. transform: translate(calc(0% + 16pt), calc(-100% + 18pt + 16pt));
  362. }
  363. .right-stats .stat-entry::after {
  364. transform: translate(calc(-100% + 16pt), -100%);
  365. }
  366. .right-stats .stat-entry::before {
  367. transform: translate(calc(-100% + 16pt), calc(-100% + 18pt + 16pt));
  368. }
  369. </style>