Skip to content

Commit

Permalink
further improvements, add claws attack
Browse files Browse the repository at this point in the history
  • Loading branch information
MrVauxs committed Aug 1, 2024
1 parent 9f98203 commit 036750b
Show file tree
Hide file tree
Showing 11 changed files with 191 additions and 101 deletions.
10 changes: 9 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,15 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [Unreleased]
## [0.1.2]

### Added

- Added a toggle to see the predicate data in the Token Image Manager.

#### Animations

- Jaws

## [0.1.1] - 2024-08-01

Expand Down
40 changes: 37 additions & 3 deletions animations/weapons.json
Original file line number Diff line number Diff line change
@@ -1,10 +1,24 @@
{
"item:slug:claw": "item:slug:claws",
"item:slug:claws": [
{
"trigger": "attack-roll",
"preset": "onToken",
"file": "jb2a.claws.400px.red",
"options": {
"preset": "target",
"scaleToObject": {
"value": 2
}
}
}
],
"item:slug:jaw": "item:slug:jaws",
"item:slug:jaws": [
{
"trigger": "attack-roll",
"preset": "onToken",
"file": "jb2a.claws.400px.red",
"file": "jb2a.bite.400px.red",
"options": {
"preset": "target",
"scaleToObject": {
Expand Down Expand Up @@ -144,5 +158,25 @@
}
}
],
"item:base:longbow": "item:base:shortbow"
}
"item:base:longbow": "item:base:shortbow",
"item:base:crossbow": [
{
"trigger": "attack-roll",
"preset": "ranged",
"file": "jb2a.arrow.physical.white.01",
"options": {
"sound": {
"file": "pf2e-graphics.crossbow"
},
"stretchTo": {
"randomOffset": 0.5
}
}
}
],
"item:base:heavy-crossbow": "item:base:crossbow",
"item:base:hand-crossbow": "item:base:crossbow",
"item:base:repeating-crossbow": "item:base:crossbow",
"item:base:repeating-heavy-crossbow": "item:base:crossbow",
"item:base:repeating-hand-crossbow": "item:base:crossbow"
}

Check failure on line 182 in animations/weapons.json

View workflow job for this annotation

GitHub Actions / build

Newline required at end of file but not found
2 changes: 0 additions & 2 deletions assets/library/sounds/TODO.md

This file was deleted.

Binary file removed assets/library/sounds/ovani-sounds/Bow A.wav
Binary file not shown.
Binary file removed assets/library/sounds/ovani-sounds/Bow B.wav
Binary file not shown.
6 changes: 4 additions & 2 deletions lang/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,11 @@
"all-animations": "All Animations",
"actor-animations": "Actor Animations",
"tokenimage-manager": "Token Image Manager"
}
},
"toggle": "Toggle Predicates on and off, allowing you to preview the token change.",
"switch": "See the Effect the rule is predicated onto, or the predicate data itself."
},
"easingTooltip": "Learn more about various easing functions here.",
"featText": "This feat contains PF2e Graphics-managed Rule Elements, primarily of the TokenImage variety. Opening the Rules tab on this feat may lag your game if the actor contains a lot of forms (ex. Druid)."
}
}
}

Check failure on line 57 in lang/en.json

View workflow job for this annotation

GitHub Actions / build

Newline required at end of file but not found
35 changes: 22 additions & 13 deletions src/app.postcss
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,27 @@
@tailwind components;
@tailwind utilities;

/* https://github.com/FortAwesome/Font-Awesome/issues/12607#issuecomment-506886318 */
.ko-fi::after {
content: '\f004';
font-weight: 900;
font-size: 0.4rem;
color: #ff5e5e;
position: absolute;
margin: 0.42rem 0 0 -0.74rem;
}
.pf2e-g {
/* https://github.com/FortAwesome/Font-Awesome/issues/12607#issuecomment-506886318 */
& .ko-fi::after {
content: '\f004';
font-weight: 900;
font-size: 0.4rem;
color: #ff5e5e;
position: absolute;
margin: 0.42rem 0 0 -0.74rem;
}

& .bg-button {
background: rgba(0, 0, 0, 0.1);
border: 2px groove var(--color-border-light-highlight);
border-radius: 3px;
}

.bg-button {
background: rgba(0, 0, 0, 0.1);
border: 2px groove var(--color-border-light-highlight);
border-radius: 3px;
& button {
&.disabled,
&:disabled {
@apply cursor-not-allowed;
}
}
}
20 changes: 10 additions & 10 deletions src/storage/index.ts
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
import './presets.ts'
import { AnimCore } from './AnimCore.ts'

window.pf2eGraphics ??= {
modules: {},
Object.assign(window, {
pf2eGraphics: { modules: {}, AnimCore },
AnimCore,
}

window.AnimCore = AnimCore
})

Hooks.on('ready', async () => {
for (const mod of game.modules) {
if (!mod.active)
continue
if (!mod.active) continue
const animations: string | undefined = mod.flags?.['pf2e-graphics'] as unknown as string
if (!animations)
continue
window.pf2eGraphics.modules[mod.id] = await (await fetch(animations)).json()
if (!animations) continue
const path = animations.startsWith('modules/') ? animations : `modules/${mod.id}/${animations}`

fetch(path)
.then(resp => resp.json()
.then((json) => { window.pf2eGraphics.modules[mod.id] = json }))
}
})

Expand Down
7 changes: 6 additions & 1 deletion src/view/ActorAnimations/ActorAnimationsShell.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,12 @@
<!-- svelte-ignore a11y-no-noninteractive-element-interactions -->
<div class='flex gap-2 h-20'>
<!-- svelte-ignore a11y-click-events-have-key-events -->
<img src={$doc.img} alt={$doc.name} class='h-full aspect-square hover:cursor-pointer' on:click={() => $doc.sheet.render(true)} />
<img
src={$doc.img}
alt={$doc.name}
class='h-full hover:cursor-pointer'
on:click={() => $doc.sheet.render(true)}
/>
<div class='flex flex-col w-full'>
<h1 class='w-full mt-1 font-serif font-bold text-4xl'>
{$doc.name}
Expand Down
85 changes: 85 additions & 0 deletions src/view/ActorAnimations/submenus/elements/PredicateSection.svelte
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
<script lang='ts'>
import { ErrorMsg } from 'src/utils'
import type { CustomTokenImage } from '../tokenimage-manager.svelte'
export let rule: CustomTokenImage
export let updateRules: (rule1?: CustomTokenImage, rule2?: Partial<CustomTokenImage>) => void
async function dropPredicate(event: DragEvent, rule: CustomTokenImage): Promise<void> {
const data = event?.dataTransfer?.getData('text/plain')
if (!data) return
const effect = await fromUuid(JSON.parse(data).uuid) as EffectPF2e
if (effect?.type !== 'effect') throw new ErrorMsg('The dragged entity is not an effect!')
// TODO: I swear this feels so wrong using an index for this.
return updateRules(rule, {
predicate: [`self:${effect.getRollOptions()[1]}`],
uuidPredicate: effect.uuid,
})
}
function removeDropPredicate(rule: CustomTokenImage) {
rule.predicate = []
rule.uuidPredicate = ''
updateRules()
}
function isEffect(doc?: ClientDocument | null): doc is EffectPF2e {
return doc?.type === 'effect'
}
let showPredicate = (rule.predicate || [])?.length > 1 || !rule.uuidPredicate
</script>

<section
class='border border-solid p-1 rounded-sm bg-opacity-50 bg-slate-100 flex h-9 gap-1'
on:drop|preventDefault|stopPropagation={event => dropPredicate(event, rule)}
aria-dropeffect='none'
aria-label='Drag and Drop Effect Target'
>
{#await fromUuid(rule.uuidPredicate) then effect}
{#if showPredicate}
<input class='' type='text'
value={JSON.stringify(rule.predicate)}
on:change={(e) => {
rule.predicate = JSON.parse(e.target?.value || [])
updateRules()
}}
/>
{:else}
<!-- svelte-ignore a11y-no-noninteractive-element-interactions -->
<div
class='flex items-center mx-auto cursor-pointer text-nowrap'
>
{#if isEffect(effect)}
<div
class='flex items-center gap-1'
on:click={() => effect.sheet.render(true)}
on:keyup={() => effect.sheet.render(true)}
role='document'
>
<img
src={effect.img}
alt='Effect Icon'
class='size-6 cursor-pointer aspect-square'
/>
<span>
{effect.name}
</span>
<i class='fa fa-close ml-auto mr-6 p-1 py-0 leading-normal hover:underline'
role='button'
tabindex='-1'
on:click|stopPropagation={() => removeDropPredicate(rule)}
on:keyup|stopPropagation={() => removeDropPredicate(rule)}
/>
</div>
{:else}
<span class='px-1'>Drag and drop an effect to predicate onto!</span>
{/if}
</div>
{/if}

<button data-tooltip='pf2e-graphics.actorAnimation.switch' class='fa fa-refresh w-min' on:click={() => showPredicate = !showPredicate} />
{/await}
</section>
87 changes: 18 additions & 69 deletions src/view/ActorAnimations/submenus/tokenimage-manager.svelte
Original file line number Diff line number Diff line change
@@ -1,9 +1,22 @@
<script lang='ts' context='module'>
const ruleTemplate = (feat: ItemPF2e) => ({
id: foundry.utils.randomID(),
key: 'TokenImage',
value: feat?.actor?.prototypeToken.texture.src as string,
uuidPredicate: '',
animation: {},
predicate: [] as (string | object)[],
})
export type CustomTokenImage = ReturnType<typeof ruleTemplate> & TokenImageRuleSource
</script>
<script lang='ts'>
import { TJSDocument } from '@typhonjs-fvtt/runtime/svelte/store/fvtt/document'
import { ErrorMsg, devMessage, i18n } from 'src/utils'
import { devMessage, i18n } from 'src/utils'
import { derived } from 'svelte/store'
import featData from './tokenimage-feat.json'
import TokenThumbnail from './elements/TokenThumbnail.svelte'
import PredicateSection from './elements/PredicateSection.svelte'
export let actor: TJSDocument<ActorPF2e>
Expand Down Expand Up @@ -36,17 +49,8 @@
$actor.setFlag('pf2e-graphics', 'displayFeat', display)
}
const ruleTemplate = () => ({
id: foundry.utils.randomID(),
key: 'TokenImage',
value: $feat?.actor.prototypeToken.texture.src as string,
uuidPredicate: '',
animation: {},
})
type CustomTokenImage = ReturnType<typeof ruleTemplate> & TokenImageRuleSource
async function createRule() {
await $feat?.update({ 'system.rules': $feat.system.rules.concat(ruleTemplate()) })
await $feat?.update({ 'system.rules': $feat.system.rules.concat(ruleTemplate($feat)) })
}
async function removeRule(rule: RuleElementSource) {
Expand All @@ -68,33 +72,10 @@
return new Promise(resolve => new FilePicker({ current, callback: result => resolve(result) }).browse())
}
async function dropPredicate(event: DragEvent, rule: CustomTokenImage): Promise<void> {
const data = event?.dataTransfer?.getData('text/plain')
if (!data) return
const effect = await fromUuid(JSON.parse(data).uuid) as EffectPF2e
if (effect?.type !== 'effect') throw new ErrorMsg('The dragged entity is not an effect!')
// TODO: I swear this feels so wrong using an index for this.
return updateRules(rule, {
predicate: [`self:${effect.getRollOptions()[1]}`],
uuidPredicate: effect.uuid,
})
}
function removeDropPredicate(rule: CustomTokenImage) {
rule.predicate = []
rule.uuidPredicate = ''
updateRules()
}
function isCustomTokenImage(rule: RuleElementSource): rule is CustomTokenImage {
return rule.key === 'TokenImage'
}
function isEffect(doc?: ClientDocument | null): doc is EffectPF2e {
return doc?.type === 'effect'
}
</script>

<div class='p-2 pb-0 flex flex-col h-full'>
Expand Down Expand Up @@ -128,42 +109,10 @@
'>
<!-- #region Predicate -->
<span>
Activate on:
Predicate:
</span>
<section
class='border border-solid p-1 rounded-sm bg-opacity-50 bg-slate-100 flex-grow'
on:drop|preventDefault|stopPropagation={event => dropPredicate(event, rule)}
aria-dropeffect='none'
aria-label='Drag and Drop Effect Target'
>
{#await fromUuid(rule.uuidPredicate) then effect}
{#if isEffect(effect)}
<!-- svelte-ignore a11y-no-noninteractive-element-interactions -->
<div
class='flex items-center gap-1 mx-auto cursor-pointer'
on:click={() => effect.sheet.render(true)}
on:keyup={() => effect.sheet.render(true)}
role='document'
>
<img
src={effect.img}
alt='Effect Icon'
class='size-6 cursor-pointer'
/>
<span>
{effect.name}
</span>
<i class='fa fa-close ml-auto p-1 py-0 leading-normal hover:underline'
role='button'
tabindex='-1'
on:click|stopPropagation={() => removeDropPredicate(rule)}
on:keyup|stopPropagation={() => removeDropPredicate(rule)} />
</div>
{:else}
Drag and drop an effect to predicate onto!
{/if}
{/await}
</section>
<PredicateSection {rule} {updateRules} />

<!-- #endregion -->
<!-- #region Token Image -->
<span>
Expand Down

0 comments on commit 036750b

Please sign in to comment.