Skip to content

Commit

Permalink
feat(effect): you can now link an existing effect to a choice
Browse files Browse the repository at this point in the history
  • Loading branch information
AcevedoR committed Mar 30, 2024
1 parent 69d9287 commit f1dbe60
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 4 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,5 +23,5 @@ generated from https://github.com/cawa-93/vite-electron-builder
- link another event from event
- ~create an effect from event~
- ~create an effect from a choice~
- link an effect to event
- link an effect to choice
- ~link an effect to event~
- ~link an effect to choice~
2 changes: 1 addition & 1 deletion packages/renderer/src/App.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@
<EventEditionSidebar selectedContentToEdit={selectedContentToEdit} chainEffects={chain.chain.effects}
on:save={e => modifyChain(chain.chainFileAbsolutePath, chain.chain, e)} />
{:else}
<ChoiceEditionSidebar selectedContentToEdit={selectedContentToEdit}
<ChoiceEditionSidebar selectedContentToEdit={selectedContentToEdit} chainEffects={chain.chain.effects}
on:save={e => modifyChain(chain.chainFileAbsolutePath, chain.chain, e)} />
{/if}
{/if}
Expand Down
34 changes: 33 additions & 1 deletion packages/renderer/src/admin-view/ChoiceEditionSidebar.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,24 @@
import EffectCreationForm from '/@/admin-view/EffectCreationForm.svelte';
import type {CreateEffect} from '/@/file-synchronization/CreateEffect';
import Button from '/@/admin-view/Button.svelte';
import LinkEffectForm from '/@/admin-view/LinkEffectForm.svelte';
import type {LinkEffect} from '/@/file-synchronization/LinkEffect';
import type {Effect} from '/@/model/Effect';
export let selectedContentToEdit: ChoiceToDisplay;
export let chainEffects: Record<string, Effect>;
$: availableEffects = getAvailableEffects(chainEffects);
const getAvailableEffects = (chainEffects: Record<string, Effect>): Record<string, Effect> => {
let res: Record<string, Effect> = {};
Object.entries(chainEffects)
.filter(([name, effect]) => !selectedContentToEdit.effects.find(x => x.id === name))
.forEach(([name, effect]) => res[name] = effect);
return res;
};
enum CreationFormDisplayed {
none, createEvent, createEffect
none, createEvent, createEffect, linkEffect
}
let currentCreationFormDisplayed = CreationFormDisplayed.none;
Expand Down Expand Up @@ -52,7 +64,16 @@
currentCreationFormDisplayed = CreationFormDisplayed.none;
};
const onEffectLink = (linkEffect: LinkEffect) => {
console.log('linking effect: ' + linkEffect.effectName);
dispatch('save', {
type: 'linkEffect',
content: linkEffect,
});
currentCreationFormDisplayed = CreationFormDisplayed.none;
};
</script>

<div id="choice-edition-sidebar">

<h1>Admin sidebar</h1>
Expand All @@ -67,6 +88,12 @@
parentId={selectedContentToEdit.id}
on:createEffect={(msg) => onEffectCreation(msg.detail)}
></EffectCreationForm>
{:else if currentCreationFormDisplayed === CreationFormDisplayed.linkEffect}
<LinkEffectForm
parentId={selectedContentToEdit.id}
effects={availableEffects}
on:linkEffect={(msg) => onEffectLink(msg.detail)}
></LinkEffectForm>
{:else if currentCreationFormDisplayed === CreationFormDisplayed.none}
<div id="selected-content-display">
<h2>Modifying choice: </h2>
Expand All @@ -84,6 +111,11 @@
Create a new effect
</Button>
</div>
<div id="choice-effect-link-section">
<Button on:click={() => currentCreationFormDisplayed = CreationFormDisplayed.linkEffect}>
Link an existing effect
</Button>
</div>
{/if}
</div>

Expand Down

0 comments on commit f1dbe60

Please sign in to comment.