Skip to content

Commit

Permalink
feat: adds new IfElse block, new Collapse block
Browse files Browse the repository at this point in the history
  • Loading branch information
valentine195 committed Mar 4, 2023
1 parent 161d113 commit 66fad70
Show file tree
Hide file tree
Showing 7 changed files with 14 additions and 28 deletions.
6 changes: 3 additions & 3 deletions src/layouts/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,12 +37,12 @@ export type StatblockItemType = typeof StatblockItemTypes[number];

type RequiredProps = {
type: StatblockItemType;
conditioned?: boolean;
id: string;
};

export type CommonProps = RequiredProps & {
properties: Array<keyof Monster>;
conditioned?: boolean;
fallback?: string;
hasRule?: boolean;
dice?: boolean;
Expand Down Expand Up @@ -114,15 +114,15 @@ type TextProps = {
};
export type IfElseCondition = {
condition: string;
blocks: [GroupItem];
nested: [GroupItem];
};
type IfElseProps = {
type: "ifelse";
conditions: IfElseCondition[];
};
type CollapseProps = {
type: "collapse";
blocks: [GroupItem];
nested: [GroupItem];
heading?: string;
hasRule?: boolean;
};
Expand Down
1 change: 0 additions & 1 deletion src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -473,7 +473,6 @@ export default class StatBlockPlugin extends Plugin {

/** Get Parameters */
let params: StatblockParameters = parseYaml(source);
console.log("🚀 ~ file: main.ts:476 ~ params:", params);

el.addClass("statblock-plugin-container");
el.parentElement?.addClass("statblock-plugin-parent");
Expand Down
3 changes: 2 additions & 1 deletion src/settings/add.ts
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,8 @@ export function blockGenerator(type: string): StatblockItem {
id: nanoid(),
heading: null,
hasRule: false,
blocks: [blockGenerator("group")]
conditioned: false,
nested: [blockGenerator("group")]
};
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/settings/ui/Block.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@
<div class="statblock-creator-container">
{#key block}
<div class="statblock-creator-block">
{#if block.type != "ifelse"}
{#if block.type != "ifelse" && block.type != "collapse"}
<PropertyBlock {block} />
{/if}
</div>
Expand Down
7 changes: 2 additions & 5 deletions src/settings/ui/Creator.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@
<span>Collapse</span>
{/if}
<svelte:self
bind:blocks={block.blocks}
bind:blocks={block.nested}
bind:plugin
draggable={false}
/>
Expand All @@ -239,7 +239,7 @@
<div class="statblock-creator-container">
<div class="statblock-creator-block">
<div class="if-else-block-container">
{#each block.conditions as { condition, blocks: ifElseBlocks } (condition)}
{#each block.conditions as { condition, nested: ifElseBlocks } (condition)}
<div
class="condition-container"
>
Expand Down Expand Up @@ -312,9 +312,6 @@
padding: 2px;
margin: 2px;
}
:global(body:not(.is-mobile)) .ifelse:not(:hover) > .icons {
visibility: hidden;
}
.group {
display: grid;
grid-template-columns: 1fr;
Expand Down
2 changes: 1 addition & 1 deletion src/settings/ui/IfElseProperties.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@
...items,
{
prop: {
blocks: [blockGenerator("group")],
nested: [blockGenerator("group")],
condition: null
},
id
Expand Down
21 changes: 5 additions & 16 deletions src/view/ui/Content.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,11 @@
const monster = getContext<Monster>("monster");
const checkConditioned = (item: StatblockItem): boolean => {
if (item.type == "ifelse" || item.type == "collapse") return true;
if (item.conditioned == null || !item.conditioned) return true;
if ("nested" in item) {
return item.nested.some((prop) => checkConditioned(prop));
}
if (item.type == "ifelse") return true;
if (!item.properties.length) return true;
return item.properties.some((prop) => {
if (prop in monster) {
Expand Down Expand Up @@ -85,7 +85,7 @@
}
case "collapse": {
const elements = [];
for (const nested of item.blocks) {
for (const nested of item.nested) {
const element = getElementForStatblockItem(nested);
elements.push(...element);
}
Expand All @@ -96,18 +96,7 @@
elements
}
});
/* const details = target.createEl("details");
const summary = details.createEl("summary", {
text: item.heading ?? null
});
summary.createDiv("collapser").createDiv("handle");
for (const nested of item.blocks) {
const element = getElementForStatblockItem(nested, details);
for (const el of element) {
details.appendChild(el);
}
}
targets.push(details); */
break;
}
case "heading": {
Expand All @@ -125,7 +114,7 @@
}
case "ifelse": {
for (let i = 0; i < item.conditions.length; i++) {
const { condition, blocks } = item.conditions[i];
const { condition, nested } = item.conditions[i];
const frame = document.body.createEl("iframe");
const funct = (frame.contentWindow as any).Function;
let parsed: boolean = false;
Expand All @@ -141,7 +130,7 @@
parsed == true ||
(i == item.conditions.length - 1 && !condition?.length)
) {
for (const block of blocks) {
for (const block of nested) {
const element = getElementForStatblockItem(
block,
target
Expand Down

0 comments on commit 66fad70

Please sign in to comment.