Skip to content

Commit

Permalink
Add global task templates.
Browse files Browse the repository at this point in the history
  • Loading branch information
Damnae committed Feb 2, 2024
1 parent 5307dfa commit 919de0d
Show file tree
Hide file tree
Showing 7 changed files with 185 additions and 11 deletions.
11 changes: 11 additions & 0 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@ import RogueBuffModifier from './views/abilities/RogueBuffModifier.vue'
import AnyAbility from './views/abilities/AnyAbility.vue'
import AnyModifier from './views/abilities/AnyModifier.vue'

import AnyTaskTemplate from './views/abilities/AnyTaskTemplate.vue'

import TargetAlias from './views/pages/TargetAlias.vue'
import TargetAliases from './views/pages/TargetAliases.vue'

Expand Down Expand Up @@ -195,6 +197,13 @@ const routes:Readonly<RouteRecordRaw[]> =
meta: { mainNav: 'Modifier', mainNavTab:'Global', }
},

// Task Templates
{ path: '/tasktemplate-:taskTemplateId/@:commitId',
name: 'tasktemplate', components: { default: AnyTaskTemplate, },
props:{ default:toRouteProps({ }) },
meta: { mainNav: 'TaskTemplate', mainNavTab:'Global', }
},

// Misc Pages
{ path: '/targetalias-:aliasId/@:commitId',
name: 'targetAlias', components: { default: TargetAlias, },
Expand Down Expand Up @@ -241,6 +250,8 @@ const routes:Readonly<RouteRecordRaw[]> =
{ path: '/ability-:abilityId', meta: { redirectName:'ability' }, redirect: redirectToLatestCommit },
{ path: '/modifier-:modifierId', meta: { redirectName:'modifier' }, redirect: redirectToLatestCommit },

{ path: '/tasktemplate-:tasktemplateId', meta: { redirectName:'tasktemplate' }, redirect: redirectToLatestCommit },

{ path: '/targetalias-:aliasId', meta: { redirectName:'targetAlias' }, redirect: redirectToLatestCommit },
{ path: '/targetaliases', meta: { redirectName:'targetAliases' }, redirect: redirectToLatestCommit },

Expand Down
47 changes: 37 additions & 10 deletions src/sources/ability.ts
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,7 @@ export enum TaskContextType
BattleEvent = 'BattleEvent',
Level = 'Level',
Rogue = 'Rogue',
TaskTemplate = 'TaskTemplate',
}

const contextTypeToPaths =
Expand Down Expand Up @@ -305,6 +306,15 @@ const contextTypeToPaths =
'Config/ConfigGlobalTaskListTemplate/GlobalTaskListTemplate.json',
],
},
TaskTemplate:
{
Abilities: [],
Modifiers: [],
TaskListTemplates:
[
'Config/ConfigGlobalTaskListTemplate/GlobalTaskListTemplate.json',
],
},
Empty:
{
Abilities: [],
Expand Down Expand Up @@ -357,6 +367,12 @@ if (settings.includeWhiteBox)
'Config/ConfigAbility/WhiteBox/BattleEvent',
'Config/ConfigAbility/WhiteBox/Monster',
])
contextTypeToPaths.All.TaskListTemplates = contextTypeToPaths.All.TaskListTemplates.concat([
'Config/ConfigGlobalTaskListTemplate',
])
contextTypeToPaths.TaskTemplate.TaskListTemplates = contextTypeToPaths.TaskTemplate.TaskListTemplates.concat([
'Config/ConfigGlobalTaskListTemplate',
])
}

const taskContextCache:{[commitId: string]: {[type: string]: TaskContext}} = {}
Expand Down Expand Up @@ -407,7 +423,17 @@ export async function getTaskContext(commitId:string, type:TaskContextType) : Pr
}

for (const path of paths.TaskListTemplates)
if (path.endsWith('.json'))
mergeTaskListTemplateConfig(context, await getTaskListTemplates(commitId, path) as TaskListTemplateConfig)
else
{
const response = await retrieveJson(`git/trees/${commitId}:${path}`, commitId, true)
const tree = response.tree
if (tree !== undefined)
for (const treePath of tree.map((t:any) => t.path))
if (treePath.endsWith('.json'))
mergeTaskListTemplateConfig(context, await getTaskListTemplates(commitId, `${path}/${treePath}`) as TaskListTemplateConfig)
}

result = container[type] = context
console.log(`cached ${type} ability context for ${commitId}`)
Expand Down Expand Up @@ -480,15 +506,16 @@ function mergeAbilityConfig(into:TaskContext, from:AbilityConfig)
if (!from)
return;

for (const ability of from.AbilityList)
{
let nameIndex = 2
const originalName = ability.Name
while (ability.Name in into.Abilities)
ability.Name = `${originalName}#${nameIndex++}`
if (from.AbilityList !== undefined)
for (const ability of from.AbilityList)
{
let nameIndex = 2
const originalName = ability.Name
while (ability.Name in into.Abilities)
ability.Name = `${originalName}#${nameIndex++}`

into.Abilities[ability.Name] = ability
}
into.Abilities[ability.Name] = ability
}

if (from.GlobalModifiers !== undefined)
for (const modifier of Object.values(from.GlobalModifiers))
Expand All @@ -515,7 +542,7 @@ function mergeAbilityConfig(into:TaskContext, from:AbilityConfig)

function mergeModifierConfig(into:TaskContext, from:ModifierConfig)
{
if (!from)
if (!from?.ModifierMap)
return;

for (const modifier of Object.values(from.ModifierMap))
Expand All @@ -531,7 +558,7 @@ function mergeModifierConfig(into:TaskContext, from:ModifierConfig)

function mergeTaskListTemplateConfig(into:TaskContext, from:TaskListTemplateConfig)
{
if (!from)
if (!from?.TaskListTemplate)
return;

for (const template of from.TaskListTemplate)
Expand Down
17 changes: 17 additions & 0 deletions src/views/abilities/AnyTaskTemplate.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<script setup lang="ts">
import ProvideTaskTemplateContext from './components/ProvideTaskTemplateContext.vue';
import TaskTemplate from './TaskTemplate.vue';
defineProps<{commitId:string, taskTemplateId:string}>()
</script>

<template>
<main class="panel">
<ProvideTaskTemplateContext :commitId="commitId">
<TaskTemplate :taskTemplateId="taskTemplateId" />
</ProvideTaskTemplateContext>
</main>
</template>

<style scoped>
</style>
42 changes: 42 additions & 0 deletions src/views/abilities/TaskTemplate.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
<script setup lang="ts">
import { inject, Ref, computed, } from 'vue'
import { TaskContext, TaskListTemplate, } from '@/sources/ability';
import AnyTask from '@/gamecore/AnyTask.vue';
import ShowContext from './components/ShowContext.vue';
import BlockLayout from '@/components/BlockLayout.vue';
const props = defineProps<{taskTemplateId:string}>()
const taskContext = inject('taskContext') as Ref<TaskContext>
const taskTemplate = computed<TaskListTemplate>(() => taskContext.value.TaskListTemplates?.[props.taskTemplateId])
</script>

<template>
<header>
<h1><span class="pretitle">Task Template:</span> {{ taskTemplateId }}</h1>
</header>
<section :key="taskTemplateId">

<template v-if="taskTemplate">

<template v-if="taskTemplate.TaskList">
<h2>Tasks</h2>
<template v-for="task in taskTemplate.TaskList">
<AnyTask :node="task" />
</template>
</template>

<h2>Context</h2>
<BlockLayout :source="taskTemplate">
<span class="flow">Task Template Data</span>
</BlockLayout>
<ShowContext />

</template>
<span v-else class="minor">(Task Template {{ taskTemplateId }} not found)</span>

</section>
</template>

<style scoped>
</style>
39 changes: 39 additions & 0 deletions src/views/abilities/components/ProvideTaskTemplateContext.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
<script setup lang="ts">
import { ref, watch, provide, } from 'vue';
import { ExpressionContext } from '@/sources/gamecore';
import { getTaskContext, TaskContext, TaskContextType, } from '@/sources/ability';
const props = defineProps<{commitId:string, abilityRouteName?:string, modifierRouteName?:string}>()
const expressionContext = ref<ExpressionContext>(await getExpressionContext())
const taskContext = ref<TaskContext>(await getTaskContext(props.commitId, TaskContextType.TaskTemplate))
watch(props, async () =>
{
expressionContext.value = await getExpressionContext()
taskContext.value = await getTaskContext(props.commitId, TaskContextType.TaskTemplate)
})
async function getExpressionContext()
{
const context:ExpressionContext =
{
Params: {},
AbilityHashValues: {},
AbilityDynamicValues: {},
}
return context
}
provide('expressionContext', expressionContext)
provide('taskContext', taskContext)
provide('createAbilityRoute', (abilityId:string) : object => { return { name: props.abilityRouteName ?? 'ability', params:{ commitId: props.commitId, abilityId: abilityId, } }})
provide('createModifierRoute', (modifierId:string) : object => { return { name: props.modifierRouteName ?? 'modifier', params:{ commitId: props.commitId, modifierId: modifierId, } }})
</script>

<template>
<slot></slot>
</template>

<style scoped>
</style>
10 changes: 9 additions & 1 deletion src/views/navigation-main/CommitNav.vue
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import StatusNav from './StatusNav.vue'
import AbilityNav from './AbilityNav.vue'
import ModifierNav from './ModifierNav.vue'
import TaskTemplateNav from './TaskTemplateNav.vue'
import RogueBuffNav from './RogueBuffNav.vue'
import NavTabs from '@/components/NavTabs.vue'
Expand All @@ -29,7 +30,7 @@
All: ['Avatar', 'Monster', 'BattleEvent', 'Equipment', 'RelicSet', 'Status', 'Ability', 'Modifier', 'RogueBuff', 'RogueMiracle', 'Misc'],
Players: ['Avatar', 'Equipment', 'RelicSet'],
NPC: ['Monster', 'BattleEvent'],
Global: ['Status', 'Ability', 'Modifier'],
Global: ['Status', 'Ability', 'Modifier', 'TaskTemplate'],
'Simulated Universe': ['RogueBuff', 'RogueMiracle'],
}
Expand Down Expand Up @@ -106,6 +107,13 @@
</NavTree>
</NavItem>

<NavItem v-if="isVisible('TaskTemplate')">
<NavTree :startsOpen="mainNav == 'TaskTemplate'">
<template #header>Task Templates</template>
<TaskTemplateNav />
</NavTree>
</NavItem>

<NavItem v-if="isVisible('RogueBuff')">
<NavTree :startsOpen="mainNav == 'RogueBuff'">
<template #header>Blessings</template>
Expand Down
30 changes: 30 additions & 0 deletions src/views/navigation-main/TaskTemplateNav.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<script setup lang="ts">
import { ref, computed, inject, Ref, } from 'vue'
import { RouterLink } from 'vue-router';
import { TaskContext, TaskContextType, getTaskContext, TaskListTemplate } from '@/sources/ability';
import NavItem from '@/components/NavItem.vue'
const commitId = inject<string>('commitId') as string
const search = inject<Ref<string>>('search') as Ref<string>
const taskContext = ref<TaskContext>(await getTaskContext(commitId, TaskContextType.TaskTemplate))
const taskTemplatesSearchResults = computed(() => allTaskTemplates())
function allTaskTemplates() : TaskListTemplate[]
{
return Object.values(taskContext.value.TaskListTemplates)
.filter(v => v.Name.toLowerCase().includes(search.value.toLowerCase()))
.sort((a, b) => a.Name > b.Name ? 1 : -1)
}
</script>

<template>
<NavItem v-for="taskTemplate in taskTemplatesSearchResults" :key="taskTemplate.Name">
<RouterLink :to="{ name:'tasktemplate', params:{ commitId: commitId, taskTemplateId: taskTemplate.Name }}">
<span :title="taskTemplate.Name">{{ taskTemplate.Name }}</span>
</RouterLink>
</NavItem>
</template>

<style scoped>
</style>

0 comments on commit 919de0d

Please sign in to comment.