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.
 
 
 
 
 

418 lines
10 KiB

  1. <template>
  2. <div @click="$emit('select', $el)" class="statblock">
  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> 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="$emit('selectPredator')" v-if="subject.containedIn !== null">Select predator</button>
  61. <button v-if="subject.perspective === POV.Third" @click.stop="subject.perspective = POV.Second">Second-person</button>
  62. <button v-if="subject.perspective === POV.First" @click.stop="subject.perspective = POV.Third">Third-person</button>
  63. <button v-if="subject.perspective === POV.Second" @click.stop="subject.perspective = POV.First">First-person</button>
  64. </div>
  65. </div>
  66. </template>
  67. <script lang="ts">
  68. import { Component, Prop, Vue, Watch, Emit } from 'vue-property-decorator'
  69. import { Creature } from '@/game/creature'
  70. import { POV } from '@/game/language'
  71. import { Stats, Stat, StatIcons, StatDescs, Vigor, VigorIcons, VigorDescs, VoreStatDescs, VoreStatIcons, VisibleStatus } from '@/game/combat'
  72. import ContainerView from './ContainerView.vue'
  73. import tippy, { delegate, createSingleton } from 'tippy.js'
  74. import 'tippy.js/dist/tippy.css'
  75. @Component({
  76. components: {
  77. ContainerView
  78. },
  79. data () {
  80. return {
  81. POV: POV
  82. }
  83. },
  84. methods: {
  85. vigorColor (value: number, max: number) {
  86. if (value * 5 <= max) {
  87. return 'red'
  88. } else if (value * 3 <= max) {
  89. return 'yellow'
  90. } else {
  91. return 'green'
  92. }
  93. },
  94. statClass (value: number, normal: number) {
  95. if (value < normal) {
  96. return 'stat-entry crit'
  97. } else if (value > normal) {
  98. return 'stat-entry buff'
  99. } else {
  100. return 'stat-entry'
  101. }
  102. }
  103. }
  104. })
  105. export default class Statblock extends Vue {
  106. @Prop({ type: Creature, required: true })
  107. subject!: Creature
  108. @Prop()
  109. initiative!: number
  110. firstperson: POV = POV.First
  111. thirdperson: POV = POV.Third
  112. private vigorIcons = VigorIcons
  113. private statIcons = StatIcons
  114. private voreStatIcons = VoreStatIcons
  115. private vigorDescs = VigorDescs
  116. private statDescs = StatDescs
  117. private voreStatDescs = VoreStatDescs
  118. private vigor = Vigor
  119. @Watch('subject.status')
  120. private statusChanged (a: Array<VisibleStatus>) {
  121. this.$nextTick(() => {
  122. const icons = Array.from(this.$el.querySelectorAll(".statblock-status-icons i")) as Array<HTMLElement>
  123. icons.map(elem => {
  124. const tooltip = elem.querySelector(".tooltip-template") as HTMLElement
  125. console.log(elem, tooltip)
  126. return tippy(elem, {
  127. content: tooltip
  128. })
  129. })
  130. })
  131. }
  132. mounted () {
  133. const statEntries = Array.from(this.$el.querySelectorAll(".stat-entry"))
  134. const name = Array.from(this.$el.querySelectorAll(".name"))
  135. const tippyInstances = statEntries.concat(name).map(elem => {
  136. const tooltip = elem.querySelector(".tooltip-template") as HTMLElement
  137. return tippy(elem, {
  138. content: tooltip
  139. })
  140. })
  141. createSingleton(tippyInstances, { delay: 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: 200%;
  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. }
  173. .stat-line {
  174. width: 100%;
  175. display: flex;
  176. justify-content: space-evenly;
  177. flex-wrap: wrap;
  178. }
  179. .stat-entry {
  180. position: relative;
  181. font-size: 10pt;
  182. padding-top: 2pt;
  183. padding-bottom: 2pt;
  184. display: flex;
  185. flex-direction: column;
  186. justify-content: space-evenly;
  187. align-items: center;
  188. user-select: none;
  189. text-align: center;
  190. }
  191. .stat-value {
  192. position: absolute;
  193. transform: translate(0, 8pt);
  194. padding-top: 4pt;
  195. padding-bottom: 4pt;
  196. }
  197. .healthbar {
  198. display: flex;
  199. align-items: center;
  200. justify-content: space-between;
  201. --color: green;
  202. --fullness: 100%;
  203. position: relative;
  204. width: 90%;
  205. margin: 0% 5% 0%;
  206. height: 14pt;
  207. border-radius: 2pt;
  208. border-width: 2pt;
  209. border-color: gray;
  210. border-style: outset;
  211. background: linear-gradient(90deg, var(--color) var(--fullness), black var(--fullness), black);
  212. }
  213. .stat-entry .healthbar i {
  214. flex: 0 1;
  215. flex-basis: 20pt;
  216. font-size: 14pt;
  217. }
  218. .healthbar .healthbar-value {
  219. flex: 1 0;
  220. font-size: 12pt;
  221. color: #bbb;
  222. }
  223. .stat-entry > i {
  224. font-size: 16pt;
  225. width: 16pt;
  226. margin-bottom: 18pt;
  227. }
  228. .stat-entry.low {
  229. color: yellow;
  230. }
  231. .stat-entry.crit {
  232. color: red;
  233. }
  234. .stat-entry.buff {
  235. color: green;
  236. }
  237. .statblock-content {
  238. position: relative;
  239. width: 100%;
  240. height: 100%;
  241. background: none;
  242. }
  243. .statblock-shader {
  244. position: absolute;
  245. width: 100%;
  246. height: 100%;
  247. opacity: 0%;
  248. pointer-events: none;
  249. z-index: 0;
  250. }
  251. .statblock[data-destroyed] .statblock-content,
  252. .statblock[data-destroyed] .stat-entry {
  253. animation: destroyed 1s;
  254. animation-fill-mode: both;
  255. overflow: hidden;
  256. }
  257. @keyframes destroyed {
  258. from {
  259. opacity: 1;
  260. }
  261. to {
  262. opacity: 0.25;
  263. }
  264. }
  265. .statblock[data-eaten] .statblock-shader-eaten {
  266. background: repeating-linear-gradient(45deg, transparent, transparent 20px, green 20px, green 40px, transparent 40px);
  267. opacity: 0.5;
  268. }
  269. /* yoinked from https://codepen.io/danichk/pen/PPRxrR?editors=0110 */
  270. .marching-ants {
  271. 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;
  272. animation: marching-ants 1s infinite linear;
  273. border: 4px solid transparent;
  274. }
  275. .statblock[data-active] .statblock-shader-selected {
  276. --ants-color: #f88;
  277. border-radius: 8px;
  278. width: calc(100% - 8px);
  279. height: calc(100% - 8px);
  280. opacity: 0.75;
  281. }
  282. .statblock[data-active-ally] .statblock-shader-selected-ally {
  283. --ants-color: #88f;
  284. border-radius: 8px;
  285. width: calc(100% - 8px);
  286. height: calc(100% - 8px);
  287. opacity: 0.75;
  288. }
  289. .statblock[data-current-turn] .statblock-shader-current-turn {
  290. --ants-color: #fff;
  291. border-radius: 8px;
  292. width: calc(100% - 8px);
  293. height: calc(100% - 8px);
  294. opacity: 0.75;
  295. }
  296. @keyframes marching-ants {
  297. from {
  298. background-position: 0px 0px;
  299. }
  300. to {
  301. background-position: 20px 20px;
  302. }
  303. }
  304. .statblock-shader-dead i {
  305. font-size: 100px;
  306. position: absolute;
  307. top: 50%;
  308. transform: translate(-50%, -50%);
  309. }
  310. .statblock[data-dead] .statblock-shader-dead {
  311. background: repeating-linear-gradient(45deg, red, red 20px, transparent 20px, transparent 40px, red 40px);
  312. opacity: 0.50;
  313. }
  314. .statblock:hover[data-active] .statblock-shader-hover {
  315. opacity: 0;
  316. }
  317. .statblock:hover .statblock-shader-hover {
  318. background: white;
  319. opacity: 0.20;
  320. }
  321. .statblock[data-active] .if-not-selected {
  322. display: none;
  323. }
  324. .statblock .if-ally {
  325. display: none;
  326. }
  327. .statblock[data-ally] .if-ally {
  328. display: block;
  329. }
  330. .statblock-status-icons {
  331. display: flex;
  332. justify-content: space-evenly;
  333. min-height: 16pt;
  334. }
  335. .statblock-status-icons > i {
  336. font-size: 16pt;
  337. position: relative;
  338. }
  339. .statblock-status-icon-topleft,
  340. .statblock-status-icon-bottomright {
  341. position: absolute;
  342. font-family: sans-serif;
  343. font-weight: 300;
  344. color: #999;
  345. }
  346. .statblock-status-icon-topleft {
  347. top: -12pt;
  348. }
  349. .statblock-status-icon-bottomright {
  350. top: 4pt;
  351. right: -12pt;
  352. }
  353. </style>
  354. <style>
  355. .left-stats .stat-entry::after {
  356. transform: translate(calc(0% + 16pt), -100%);
  357. }
  358. .left-stats .stat-entry::before {
  359. transform: translate(calc(0% + 16pt), calc(-100% + 18pt + 16pt));
  360. }
  361. .right-stats .stat-entry::after {
  362. transform: translate(calc(-100% + 16pt), -100%);
  363. }
  364. .right-stats .stat-entry::before {
  365. transform: translate(calc(-100% + 16pt), calc(-100% + 18pt + 16pt));
  366. }
  367. </style>