Skip to content

Commit

Permalink
TRUTHS
Browse files Browse the repository at this point in the history
  • Loading branch information
Nick Boughton committed Sep 6, 2021
1 parent 66f28bf commit 23d29fb
Show file tree
Hide file tree
Showing 8 changed files with 452 additions and 116 deletions.
2 changes: 1 addition & 1 deletion src/components/Oracles/OPlanet.vue
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
</template>

<script lang="ts">
import { defineComponent, PropType, ref } from 'vue';
import { defineComponent, ref } from 'vue';
import { IPlanet, ERegion, EPClass } from 'src/components/models';
import { tableRoll } from 'src/lib/roll';
import { Opportunity, Peril, Planets, RollPlanetType } from 'src/lib/oracles/planets';
Expand Down
2 changes: 1 addition & 1 deletion src/components/Oracles/OSettlement.vue
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
</template>

<script lang="ts">
import { defineComponent, PropType, ref } from 'vue';
import { defineComponent, ref } from 'vue';
import { ISettlement, ESLocation, ERegion } from 'src/components/models';
import { tableRoll } from 'src/lib/roll';
import { Settlement } from 'src/lib/oracles/settlement';
Expand Down
2 changes: 1 addition & 1 deletion src/components/Oracles/OStarship.vue
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
</template>

<script lang="ts">
import { defineComponent, PropType, ref } from 'vue';
import { defineComponent, ref } from 'vue';
import { ERegion, IStarship } from 'src/components/models';
import { tableRoll } from 'src/lib/roll';
import { Starship } from 'src/lib/oracles/starship';
Expand Down
89 changes: 57 additions & 32 deletions src/components/Truth.vue
Original file line number Diff line number Diff line change
@@ -1,17 +1,22 @@
<template>
<div class="q-pb-md">
<!-- content -->
<div class="row items-center q-pb-sm">
<div class="col-shrink text-h5 q-pr-sm">{{ label }}</div>
<q-select class="col-grow" v-model="select" :options="optsFn(id)" map-options emit-value dense label="Select one or write your own..." />
<div class="q-mb-md">
<div class="row text-h4 custom-header items-center">
<div class="col-shrink q-mr-sm">{{ label }}</div>
<q-select class="col-grow" label="Select one or write your own" v-model="optSelect" map-options emit-value :options="opts()" dense borderless />
<q-btn class="col-shrink" icon="mdi-dice-6" flat dense @click="campaign.data.truths[id] = RollTruth(id)" />
<q-select v-if="subOpts.length > 0" class="col-grow" label="Select" v-model="subOptSelect" :options="subOpts" dense borderless />
<q-btn class="col-shrink" v-if="subOpts.length > 0" icon="mdi-dice-6" flat dense @click="rollSub" />
</div>
<q-input v-model="data" autogrow dense standout="bg-blue-grey text-white" :input-style="{ color: '#ECEFF4' }" debounce="750" />

<q-input label="Text" v-model="campaign.data.truths[id]" dense outlined autogrow />
</div>
</template>

<script lang="ts">
import { ISelectOpt } from 'src/components/models';
import { Truths } from 'src/lib/truths';
import { SFTruths, RollTruth } from 'src/lib/truths';
import { tableRoll } from 'src/lib/roll';
import { useCampaign } from 'src/store/campaign';
import { defineComponent, ref, watch } from 'vue';
export default defineComponent({
name: 'Truths',
Expand All @@ -24,40 +29,60 @@ export default defineComponent({
type: String,
required: true,
},
modelValue: {
type: String,
required: true,
},
},
emits: ['update:modelValue'],
setup(props, ctx) {
const data = ref(props.modelValue);
watch(
() => props.modelValue,
() => (data.value = props.modelValue)
);
setup(props) {
const campaign = useCampaign();
const subOptSelect = ref('');
let subOpts = ref([] as string[]);
const optSelect = ref('');
const optID = ref(0);
const opts = (): ISelectOpt[] => {
const out: ISelectOpt[] = [];
SFTruths[props.id].forEach((t) => {
const opt = { label: t.summary, value: t.text };
out.push(opt);
});
return out;
};
watch(
() => data.value,
() => ctx.emit('update:modelValue', data.value)
() => optSelect.value,
() => {
subOpts.value = [];
SFTruths[props.id].forEach((t, i) => {
if (optSelect.value === t.text) campaign.data.truths[props.id] = `${t.summary} ${t.text}`;
if (optSelect.value === t.text && t.table) {
optID.value = i;
t.table.items.forEach((i) => {
subOpts.value.push(i.data);
});
}
});
}
);
const select = ref('');
watch(
() => select.value,
() => (data.value = select.value)
() => subOptSelect.value,
() => {
campaign.data.truths[props.id] += subOptSelect.value;
}
);
const optsFn = (label: string): ISelectOpt[] => {
const out: ISelectOpt[] = [];
Truths[label].forEach((t) => {
out.push({ label: `${t.substring(0, 70)}...`, value: t });
});
return out;
const rollSub = () => {
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
campaign.data.truths[props.id] += tableRoll(SFTruths[props.id][optID.value].table!);
};
return {
data,
select,
optsFn,
campaign,
optSelect,
opts,
optID,
subOptSelect,
subOpts,
RollTruth,
rollSub,
};
},
});
Expand Down
15 changes: 8 additions & 7 deletions src/components/models.ts
Original file line number Diff line number Diff line change
Expand Up @@ -299,12 +299,6 @@ export interface ITableItem {
text: string;
}

export interface IOracle {
name: string;
d: number;
table: ITableItem[];
}

// Starforged Oracles
export type TPlanetOracles = { [index: string]: IPlanetOracle };

Expand All @@ -314,10 +308,17 @@ export interface ISFTableItem {
}

export interface ISFTable {
name?: string;
match?: number[];
items: ISFTableItem[];
}

export interface ITruthsSection {
match: number[];
summary: string;
text: string;
table?: ISFTable;
}

export interface ISFOracle {
name: string;
table: ISFTable;
Expand Down
19 changes: 2 additions & 17 deletions src/lib/roll.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { IRollData, IOracle, ISFTable, ECoreCombo } from 'src/components/models';
import { IRollData, ISFTable, ECoreCombo } from 'src/components/models';
import { Core } from './oracles/core';

export const d = (size: number) => {
Expand Down Expand Up @@ -77,22 +77,6 @@ export const moveRoll = (attr: number, adds: number, momentum: number, progress?
return r;
};

export const oracleRoll = (oracle: IOracle): string => {
const n = d(oracle.d);
let out = 'No match';
oracle.table.forEach((item) => {
if (item.match.length === 1 && item.match[0] === n) {
out = item.text;
return;
}

if (n >= item.match[0] && n <= item.match[1]) {
out = item.text;
}
});
return out;
};

export const tableRoll = (oracle: ISFTable): string => {
const n = d(100);
let out = 'No match';
Expand All @@ -110,5 +94,6 @@ export const tableRoll = (oracle: ISFTable): string => {

if (out === ECoreCombo.ActTheme) out = `${tableRoll(Core.action)} ${tableRoll(Core.theme)}`;
if (out === ECoreCombo.DescFoc) out = `${tableRoll(Core.descriptor)} ${tableRoll(Core.focus)}`;
if (/roll twice/i.test(out)) out = `${tableRoll(oracle)} ${tableRoll(oracle)}`;
return out;
};
Loading

0 comments on commit 23d29fb

Please sign in to comment.