-
Notifications
You must be signed in to change notification settings - Fork 43
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #420 from ben/custom-conditions
Custom conditions
- Loading branch information
Showing
9 changed files
with
159 additions
and
54 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
68
src/module/vue/components/conditions/custom-condition-checkbox.vue
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters