Feast 2.0!
Ви не можете вибрати більше 25 тем Теми мають розпочинатися з літери або цифри, можуть містити дефіси (-) і не повинні перевищувати 35 символів.
 
 
 
 
 

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