Skip to content

Commit

Permalink
Merge pull request #420 from ben/custom-conditions
Browse files Browse the repository at this point in the history
Custom conditions
  • Loading branch information
ben authored Aug 7, 2022
2 parents 17b1131 + a5474da commit 5f445d8
Show file tree
Hide file tree
Showing 9 changed files with 159 additions and 54 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

## In progress

- Custom conditions with custom names ([#420](https://github.com/ben/foundry-ironsworn/pull/420))

## 1.16.3

- Ironsworn sheet: completed area, and move notes to a tab ([#417](https://github.com/ben/foundry-ironsworn/pull/417))
Expand Down
4 changes: 4 additions & 0 deletions src/module/actor/actortypes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,10 @@ interface CharacterDataSourceData {
doomed: boolean
indebted: boolean
battered: boolean
custom1: boolean
custom1name: string
custom2: boolean
custom2name: string
}
legacies: {
quests: number
Expand Down
3 changes: 1 addition & 2 deletions src/module/vue/character-sheet.vue
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@

<!-- Conditions & Banes & Burdens -->
<section class="sheet-area nogrow">
<conditions :actor="actor" />
<conditions />
</section>
</div>

Expand Down Expand Up @@ -114,7 +114,6 @@ import { provide, computed, inject } from 'vue'
import { RollDialog } from '../helpers/rolldialog'
import CharacterHeader from './components/character-header.vue'
import Conditions from './components/conditions/conditions.vue'
import { throttle } from 'lodash'
import Tabs from './components/tabs/tabs.vue'
import Tab from './components/tabs/tab.vue'
import IronswornMain from './components/character-sheet-tabs/ironsworn-main.vue'
Expand Down
14 changes: 10 additions & 4 deletions src/module/vue/components/conditions/condition-checkbox.vue
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
</template>

<script lang="ts" setup>
import { inject, Ref } from 'vue'
import { inject, nextTick, Ref } from 'vue'
import { IronswornSettings } from '../../../helpers/settings'
import { $ActorKey } from '../../provisions'
Expand All @@ -24,18 +24,24 @@ const props = defineProps<{
async function input(ev) {
const value = ev.currentTarget.checked
let numDebilitiesMarked =
Object.values(actor.value.data.debility).filter((x) => x).length +
(value ? 1 : -1)
await $actor?.update({
data: {
debility: {
[props.name]: value,
},
},
})
await nextTick()
const numDebilitiesMarked = Object.values(actor.value.data.debility).filter(
(x) => x === true
).length
await $actor?.update({
data: {
momentumMax: 10 - numDebilitiesMarked,
momentumReset: Math.max(0, 2 - numDebilitiesMarked),
},
})
if (props.global) {
await IronswornSettings.maybeSetGlobalCondition(props.name, value)
}
Expand Down
54 changes: 30 additions & 24 deletions src/module/vue/components/conditions/conditions.vue
Original file line number Diff line number Diff line change
@@ -1,31 +1,37 @@
<template>
<div class="flexrow">
<div class="flexcol" style="flex: 2">
<h4>{{ $t('IRONSWORN.Conditions') }}</h4>
<div class="flexrow">
<div class="flexcol">
<condition-checkbox name="wounded" />
<condition-checkbox name="unprepared" />
</div>
<div class="flexcol">
<condition-checkbox name="shaken" />
<condition-checkbox name="encumbered" />
</div>
</div>
</div>
<div class="flexcol">
<h4>{{ $t('IRONSWORN.Banes') }}</h4>
<condition-checkbox name="maimed" />
<condition-checkbox name="corrupted" />
</div>
<div class="flexcol">
<h4>{{ $t('IRONSWORN.Burdens') }}</h4>
<condition-checkbox name="cursed" />
<condition-checkbox name="tormented" />
</div>
<div class="grid">
<h4 style="grid-column: 1 / 3">{{ $t('IRONSWORN.Conditions') }}</h4>
<h4 style="grid-column: 3">{{ $t('IRONSWORN.Banes') }}</h4>
<h4 style="grid-column: 4">{{ $t('IRONSWORN.Burdens') }}</h4>

<condition-checkbox name="wounded" />
<condition-checkbox name="shaken" />
<condition-checkbox name="maimed" />
<condition-checkbox name="cursed" />

<condition-checkbox name="unprepared" />
<condition-checkbox name="encumbered" />
<condition-checkbox name="corrupted" />
<condition-checkbox name="tormented" />

<custom-condition-checkbox
style="grid-column: 1 / 3"
debilitykey="custom1"
/>
<custom-condition-checkbox
style="grid-column: 3 / 5"
debilitykey="custom2"
/>
</div>
</template>

<style lang="less" scoped>
.grid {
grid-template-columns: repeat(4, 1fr);
}
</style>

<script setup lang="ts" >
import ConditionCheckbox from './condition-checkbox.vue'
import CustomConditionCheckbox from './custom-condition-checkbox.vue'
</script>
68 changes: 68 additions & 0 deletions src/module/vue/components/conditions/custom-condition-checkbox.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
<template>
<label class="checkbox flexrow">
<input
type="checkbox"
:checked="actor.data.debility[debilitykey]"
@input="toggled"
/>
<input
type="text"
v-model="actor.data.debility[nameKey]"
@input="nameUpdate"
/>
</label>
</template>

<style lang="less" scoped>
label {
margin-left: -2px;
margin-right: 5px;
}
input[type='text'] {
border: 0;
outline: 0;
border-bottom: 1px solid;
}
</style>

<script lang="ts" setup>
import { throttle } from 'lodash'
import { computed, inject, nextTick, Ref } from 'vue'
import { $ActorKey } from '../../provisions'
const props = defineProps<{ debilitykey: string }>()
const actor = inject('actor') as Ref
const $actor = inject($ActorKey)
const nameKey = computed(() => `${props.debilitykey}name`)
async function toggled(ev) {
const value = ev.target.checked
await $actor?.update({
data: {
debility: {
[props.debilitykey]: value,
},
},
})
await nextTick()
const numDebilitiesMarked = Object.values(actor.value.data.debility).filter(
(x) => x === true
).length
await $actor?.update({
data: {
momentumMax: 10 - numDebilitiesMarked,
momentumReset: Math.max(0, 2 - numDebilitiesMarked),
},
})
}
async function immediateNameUpdate() {
const nk = nameKey.value
await $actor?.update({
[`data.debility.${nk}`]: actor.value.data.debility[nk],
})
}
const nameUpdate = throttle(immediateNameUpdate, 1000)
</script>
58 changes: 35 additions & 23 deletions src/module/vue/components/sf-impacts.vue
Original file line number Diff line number Diff line change
@@ -1,31 +1,42 @@
<template>
<div class="flexrow">
<div class="flexcol">
<h5>{{ $t('IRONSWORN.Misfortunes') }}</h5>
<condition-checkbox class="nogrow" name="wounded" />
<condition-checkbox class="nogrow" name="shaken" />
<condition-checkbox class="nogrow" name="unprepared" />
</div>
<div class="flexcol">
<h5>{{ $t('IRONSWORN.LastingEffects') }}</h5>
<condition-checkbox class="nogrow" name="permanentlyharmed" />
<condition-checkbox class="nogrow" name="traumatized" />
</div>
<div class="flexcol">
<h5>{{ $t('IRONSWORN.Burdens') }}</h5>
<condition-checkbox class="nogrow" name="doomed" />
<condition-checkbox class="nogrow" name="tormented" />
<condition-checkbox class="nogrow" name="indebted" />
</div>
<div class="flexcol">
<h5>{{ $t('IRONSWORN.Vehicle') }}</h5>
<condition-checkbox class="nogrow" name="battered" :global="true" />
<condition-checkbox class="nogrow" name="cursed" :global="true" />
</div>
<div class="grid">
<h5>{{ $t('IRONSWORN.Misfortunes') }}</h5>
<h5>{{ $t('IRONSWORN.LastingEffects') }}</h5>
<h5>{{ $t('IRONSWORN.Burdens') }}</h5>
<h5>{{ $t('IRONSWORN.Vehicle') }}</h5>

<condition-checkbox class="nogrow" name="wounded" />
<condition-checkbox class="nogrow" name="permanentlyharmed" />
<condition-checkbox class="nogrow" name="doomed" />
<condition-checkbox class="nogrow" name="battered" :global="true" />

<condition-checkbox class="nogrow" name="shaken" />
<condition-checkbox class="nogrow" name="traumatized" />
<condition-checkbox class="nogrow" name="tormented" />
<condition-checkbox class="nogrow" name="cursed" :global="true" />

<condition-checkbox class="nogrow" name="unprepared" />
<condition-checkbox
class="nogrow"
name="indebted"
style="grid-column: 3/4"
/>

<custom-condition-checkbox
style="grid-column: 1 / 3"
debilitykey="custom1"
/>
<custom-condition-checkbox
style="grid-column: 3 / 5"
debilitykey="custom2"
/>
</div>
</template>

<style lang="less" scoped>
.grid {
grid-template-columns: repeat(4, 1fr);
}
h5 {
flex-grow: 0;
margin: 0.2rem 0;
Expand All @@ -34,4 +45,5 @@ h5 {

<script setup lang="ts">
import conditionCheckbox from './conditions/condition-checkbox.vue'
import CustomConditionCheckbox from './conditions/custom-condition-checkbox.vue'
</script>
4 changes: 4 additions & 0 deletions src/styles/styles.less
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@
scrollbar-color: #444 rgba(0, 0, 0, 0.1);
}

.grid {
display: grid;
}

.ironsworn {
font-family: var(--font-primary);
h1,
Expand Down
6 changes: 5 additions & 1 deletion system/template.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,11 @@
"traumatized": false,
"doomed": false,
"indebted": false,
"battered": false
"battered": false,
"custom1": false,
"custom1name": "",
"custom2": false,
"custom2name": ""
},
"xp": 0
},
Expand Down

0 comments on commit 5f445d8

Please sign in to comment.