Skip to content

Commit 2dcfeae

Browse files
committed
layout builder (almost) done. just need to add in dice callback
1 parent 813bb37 commit 2dcfeae

11 files changed

+245
-182
lines changed

src/data/constants.ts

+14-20
Original file line numberDiff line numberDiff line change
@@ -33,11 +33,8 @@ interface CommonProps {
3333
fallback?: string;
3434
hasRule?: boolean;
3535
dice?: {
36-
default?: keyof Monster;
37-
text?: keyof Monster;
38-
conditioned?: boolean;
36+
property?: keyof Monster;
3937
parse?: boolean;
40-
regex?: RegExp;
4138
};
4239
}
4340

@@ -154,10 +151,8 @@ export const Statblock5e: StatblockItem[] = [
154151
properties: ["hp"],
155152
display: "Hit Points",
156153
dice: {
157-
default: "hp",
158-
text: "hit_dice",
159-
conditioned: true,
160-
parse: false
154+
property: "hit_dice",
155+
parse: true
161156
},
162157
conditioned: true
163158
},
@@ -270,25 +265,24 @@ export const Statblock5e: StatblockItem[] = [
270265
id: nanoid(),
271266
display: "Challenge",
272267
properties: ["cr"],
273-
callback: `
274-
if ("cr" in monster && monster.cr in plugin.CR) {
275-
return \`\${monster.cr} (\${plugin.CR[
276-
monster.cr
277-
].xp.toLocaleString()} XP)\`;
278-
}
279-
return "";`
268+
callback: `if ("cr" in monster && monster.cr in plugin.CR) {
269+
return \`\${monster.cr} (\${plugin.CR[
270+
monster.cr
271+
].xp.toLocaleString()} XP)\`;
272+
}
273+
return "";`
280274
},
281275
{
282276
type: "property",
283277
id: nanoid(),
284278
display: "Proficiency Bonus",
285279
properties: ["cr"],
286280
callback: `if ("cr" in monster) {
287-
return \`+\${Math.floor(
288-
2 + (plugin.CR[monster.cr].value - 1) / 4
289-
)}\`;
290-
}
291-
return "";`
281+
return \`+\${Math.floor(
282+
2 + (plugin.CR[monster.cr].value - 1) / 4
283+
)}\`;
284+
}
285+
return "";`
292286
}
293287
]
294288
}

src/settings/StatblockCreator.svelte

+2-7
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@
77
88
import type { Layout, StatblockItem } from "src/data/constants";
99
import type StatBlockPlugin from "src/main";
10-
import { createEventDispatcher, setContext } from "svelte";
11-
import { writable } from "svelte/store";
10+
import { createEventDispatcher } from "svelte";
11+
1212
import { generate } from "./add";
1313
import AddButton from "./ui/AddButton.svelte";
1414
import Creator from "./ui/Creator.svelte";
@@ -111,11 +111,6 @@
111111
</div>
112112

113113
<style>
114-
:global(body:not(.is-mobile)) .creator-container {
115-
max-width: 75vw;
116-
max-height: 65vh;
117-
overflow: auto;
118-
}
119114
.top {
120115
display: flex;
121116
align-items: center;

src/settings/settings.css

+10
Original file line numberDiff line numberDiff line change
@@ -16,3 +16,13 @@
1616
.statblock-edit-block .statblock-additional-container > :not(.additional) {
1717
padding-bottom: 0;
1818
}
19+
20+
.statblock-edit-block .setting-item {
21+
border: 0;
22+
}
23+
24+
.statblock-edit-block textarea {
25+
width: 100%;
26+
resize: vertical;
27+
overflow: hidden;
28+
}

src/settings/ui/Block.svelte

+9-70
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,24 @@
11
<script lang="ts">
22
import type { StatblockItem } from "src/data/constants";
33
4-
import Group from "./Blocks/GroupBlock.svelte";
54
import PropertyBlock from "./Blocks/PropertyBlock.svelte";
65
import type StatBlockPlugin from "src/main";
7-
import { ExtraButtonComponent, Menu } from "obsidian";
6+
import { ExtraButtonComponent } from "obsidian";
87
import { createEventDispatcher } from "svelte";
9-
import { generate } from "../add";
108
import { BlockModal } from "./block";
119
import Rule from "src/view/ui/Rule.svelte";
12-
import copy from "fast-copy";
1310
1411
export let block: StatblockItem;
1512
export let plugin: StatBlockPlugin;
1613
1714
const dispatch = createEventDispatcher();
1815
19-
const group = block.type == "group";
20-
const inline = block.type == "inline";
21-
2216
const editBlock = () => {
2317
const modal = new BlockModal(plugin, block);
2418
2519
modal.onClose = () => {
2620
if (!modal.saved) return;
2721
dispatch("edited", modal.block);
28-
/* block = copy(modal.block); */
2922
};
3023
modal.open();
3124
};
@@ -45,85 +38,31 @@
4538
.setTooltip("Delete Block")
4639
.onClick(() => dispatch("trash", block));
4740
};
48-
49-
const dropdown = (node: HTMLDivElement) => {
50-
new ExtraButtonComponent(node).setIcon("vertical-three-dots");
51-
node.onclick = (evt) => {
52-
new Menu(plugin.app)
53-
.addItem((item) => {
54-
item.setTitle("Add")
55-
.setIcon("plus-with-circle")
56-
.onClick(async () => {
57-
if (
58-
block.type == "group" ||
59-
block.type == "inline"
60-
) {
61-
const gen = await generate(plugin, evt);
62-
if (gen) {
63-
block.nested = [...block.nested, gen];
64-
block = block;
65-
}
66-
dispatch("added");
67-
}
68-
});
69-
})
70-
.addItem((item) =>
71-
item
72-
.setTitle("Edit")
73-
.setIcon("pencil")
74-
.onClick(() => {
75-
editBlock();
76-
})
77-
)
78-
.addItem((item) =>
79-
item
80-
.setTitle("Delete")
81-
.setIcon("trash")
82-
.onClick(() => dispatch("trash", block))
83-
)
84-
.showAtMouseEvent(evt);
85-
};
86-
};
8741
</script>
8842

89-
<div class="statblock-creator-container" class:group class:inline>
43+
<div class="statblock-creator-container">
9044
{#key block}
9145
<div class="statblock-creator-block">
92-
{#if block.type == "group" || block.type == "inline"}
93-
<Group inline={block.type == "inline"} {block} {plugin} />
94-
{:else}
95-
<PropertyBlock {block} />
96-
{/if}
46+
<PropertyBlock {block} />
9747
</div>
9848
{/key}
99-
{#if group || inline}
100-
<div class="icons" use:dropdown />
101-
{:else}
102-
<div class="icons">
103-
<div class="icon" use:edit />
104-
<div class="icon" use:trash />
105-
</div>
106-
{/if}
107-
</div>
108-
{#if block.hasRule}
109-
<div aria-label="Block Has Rule">
110-
<Rule />
49+
<div class="icons">
50+
<div class="icon" use:edit />
51+
<div class="icon" use:trash />
11152
</div>
112-
{/if}
53+
</div>
11354

11455
<style>
11556
.statblock-creator-container {
11657
display: flex;
11758
justify-content: space-between;
11859
/* align-items: center; */
119-
padding: 2px;
120-
margin: 2px;
12160
width: 100%;
12261
height: 100%;
12362
}
12463
12564
:global(body:not(.is-mobile))
126-
.statblock-creator-container:not(:hover):not(.group):not(.inline)
65+
.statblock-creator-container:not(:hover)
12766
> .icons {
12867
visibility: hidden;
12968
}
@@ -134,7 +73,7 @@
13473
display: flex;
13574
justify-content: flex-end;
13675
}
137-
.statblock-creator-container:not(.group):not(.inline) .icons {
76+
.statblock-creator-container .icons {
13877
align-items: center;
13978
}
14079
.icon:not(:first-child) :global(.clickable-icon) {

src/settings/ui/Blocks/GroupBlock.svelte

-32
This file was deleted.

0 commit comments

Comments
 (0)