-
-
Notifications
You must be signed in to change notification settings - Fork 41
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
253 additions
and
0 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
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 |
---|---|---|
@@ -0,0 +1,87 @@ | ||
<template> | ||
<div :class="$style.root"> | ||
<div> | ||
<MkInput v-model="diceCount" small type="text" :class="$style.input"> | ||
<template #label>{{ i18n.ts._dice.diceCount }}</template> | ||
</MkInput> | ||
</div> | ||
<div> | ||
<MkInput v-model="diceFaces" small type="text" :class="$style.input"> | ||
<template #label>{{ i18n.ts._dice.diceFaces }}</template> | ||
</MkInput> | ||
</div> | ||
<div> | ||
<MkButton large primary style="margin: 0 auto;" @click="rollDice"> | ||
<i class="ti ti-dice-2"></i> | ||
{{ i18n.ts._dice.rollDice }} | ||
</MkButton> | ||
</div> | ||
<div v-if="diceResult" :class="$style.result">{{ diceResult }}</div> | ||
<div v-if="showMinTotal" :class="$style.option">{{ diceMinTotal }}</div> | ||
<div v-if="showMaxTotal" :class="$style.option">{{ diceMaxTotal }}</div> | ||
<div v-if="showAverageTotal" :class="$style.option">{{ diceAverageTotal }}</div> | ||
</div> | ||
</template> | ||
|
||
<script lang="ts" setup> | ||
import { Ref, ref } from 'vue'; | ||
import { DiceRoll } from '@dice-roller/rpg-dice-roller'; | ||
import MkInput from '@/components/MkInput.vue'; | ||
import MkButton from '@/components/MkButton.vue'; | ||
import { i18n } from '@/i18n'; | ||
const props = withDefaults(defineProps<{ | ||
showMinTotal?: boolean; | ||
showMaxTotal?: boolean; | ||
showAverageTotal?: boolean; | ||
}>(), { | ||
showMinTotal: false, | ||
showMaxTotal: false, | ||
showAverageTotal: false, | ||
}); | ||
const diceCount = ref(1); | ||
const diceFaces = ref(6); | ||
const diceResult: Ref<number | null> = ref(null); | ||
const diceMinTotal: Ref<number | null> = ref(null); | ||
const diceMaxTotal: Ref<number | null> = ref(null); | ||
const diceAverageTotal: Ref<number | null> = ref(null); | ||
const rollDice = () => { | ||
let roll = new DiceRoll(`${diceCount.value}d${diceFaces.value}`); | ||
if (diceCount.value > 999) { | ||
return; | ||
} | ||
diceResult.value = roll.total; | ||
diceMinTotal.value = roll.minTotal; | ||
diceMaxTotal.value = roll.maxTotal; | ||
diceAverageTotal.value = roll.averageTotal; | ||
}; | ||
</script> | ||
|
||
<style lang="scss" module> | ||
.root { | ||
padding: 8px 16px; | ||
> div { | ||
margin: 8px 0; | ||
} | ||
} | ||
.input { | ||
flex: 1 1 auto; | ||
padding: 8px; | ||
} | ||
.result { | ||
text-align: center; | ||
margin: auto; | ||
} | ||
.option { | ||
padding: 8px 0; | ||
text-align: left; | ||
} | ||
</style> |
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,63 @@ | ||
<template> | ||
<MkContainer :naked="widgetProps.transparent" :showHeader="false"> | ||
<div class="_monospace" :class="[$style.root, {_panel: !widgetProps.transparent}]"> | ||
<MkDice | ||
:showMinTotal="widgetProps.showMinTotal" | ||
:showMaxTotal="widgetProps.showMaxTotal" | ||
:showAverageTotal="widgetProps.showAverageTotal" | ||
/> | ||
</div> | ||
</MkContainer> | ||
</template> | ||
|
||
<script lang="ts" setup> | ||
import { useWidgetPropsManager, WidgetComponentEmits, WidgetComponentExpose, WidgetComponentProps } from './widget.js'; | ||
import { GetFormResultType } from '@/scripts/form.js'; | ||
import MkDice from '@/components/MkDice.vue'; | ||
import MkContainer from '@/components/MkContainer.vue'; | ||
const name = 'dice'; | ||
const widgetPropsDef = { | ||
transparent: { | ||
type: 'boolean' as const, | ||
default: false, | ||
}, | ||
showMinTotal: { | ||
type: 'boolean' as const, | ||
default: false, | ||
}, | ||
showMaxTotal: { | ||
type: 'boolean' as const, | ||
default: false, | ||
}, | ||
showAverageTotal: { | ||
type: 'boolean' as const, | ||
default: false, | ||
}, | ||
}; | ||
type WidgetProps = GetFormResultType<typeof widgetPropsDef>; | ||
const props = defineProps<WidgetComponentProps<WidgetProps>>(); | ||
const emit = defineEmits<WidgetComponentEmits<WidgetProps>>(); | ||
const { widgetProps, configure } = useWidgetPropsManager(name, | ||
widgetPropsDef, | ||
props, | ||
emit, | ||
); | ||
defineExpose<WidgetComponentExpose>({ | ||
name, | ||
configure, | ||
id: props.widget ? props.widget.id : null, | ||
}); | ||
</script> | ||
|
||
<style lang="scss" module> | ||
.root { | ||
position: relative; | ||
padding: 16px 0; | ||
} | ||
</style> |
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
Oops, something went wrong.