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.
 
 
 
 
 

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