From 73d10a7846e6641ab09495df3f453034128358b2 Mon Sep 17 00:00:00 2001 From: BinarySandia04 Date: Fri, 18 Oct 2024 15:11:08 +0200 Subject: [PATCH] More item types --- backend/models/Book.js | 1 - client/src/assets/main.css | 43 +++++- client/src/services/ContextMenu.js | 4 +- client/src/services/Utils.js | 31 +++++ client/src/views/partials/ConceptEntry.vue | 4 +- client/src/views/partials/Dropdown.vue | 22 ++- client/src/views/partials/FormElement.vue | 8 ++ .../partials/{NumberInput.vue => Input.vue} | 4 +- client/src/views/partials/Tags.vue | 1 + locales/en-US.json | 8 -- plugins/dnd-5e/backend/main.js | 21 +-- .../dnd-5e/client/views/CharacterSheet.vue | 2 +- .../dnd-5e/client/views/CreateItemPrompt.vue | 14 +- plugins/dnd-5e/client/views/Database.vue | 105 ++++++++++++-- plugins/dnd-5e/client/views/ItemSheet.vue | 130 +++++++++--------- plugins/dnd-5e/locales/en-US.json | 13 +- 16 files changed, 301 insertions(+), 110 deletions(-) create mode 100644 client/src/services/Utils.js create mode 100644 client/src/views/partials/FormElement.vue rename client/src/views/partials/{NumberInput.vue => Input.vue} (88%) diff --git a/backend/models/Book.js b/backend/models/Book.js index 3dcbc926..5e342a18 100644 --- a/backend/models/Book.js +++ b/backend/models/Book.js @@ -7,7 +7,6 @@ const BookSchema = new Schema({ description: { type: String }, system: {type: String, required: true}, image: { type: String }, - contents: [ {type: mongoose.Types.ObjectId, ref: "Concept"} ], }); module.exports = mongoose.model('Book', BookSchema); \ No newline at end of file diff --git a/client/src/assets/main.css b/client/src/assets/main.css index 262ac74c..a5db4059 100644 --- a/client/src/assets/main.css +++ b/client/src/assets/main.css @@ -307,9 +307,50 @@ span.artifact { } .form-element label { - flex-grow: 1; + flex-grow: 0; + margin-right: 6px; + margin-left: 6px; } .form-element.centered { justify-content: center; +} + +.grow { + flex-grow: 1; +} + + +.subsection.border:first-child { + border-left: none; +} + +.subsection.border { + border-left: 1px solid var(--color-border); +} + +.subsection { + margin-left: 5px; + margin-right: 5px; + height: 32px; + display: flex; + align-items: left; + justify-content: left; +} + +.subsection.left { + align-items: left; + justify-content: left; + +} + +.subsection.right { + align-items: right; + justify-content: right; + +} + +.subsection.center { + align-items: center; + justify-content: center; } \ No newline at end of file diff --git a/client/src/services/ContextMenu.js b/client/src/services/ContextMenu.js index f1805498..d8117c06 100644 --- a/client/src/services/ContextMenu.js +++ b/client/src/services/ContextMenu.js @@ -71,8 +71,8 @@ function PopulateContext(val){ animate(contextMenuElement, { opacity: [0, 1], - translateY: [20, -2] - }, {delay: (elementNum / 2) * 0.1, duration: 0.25}).finished.then(() => { + translateY: [-20, -2] + }, {duration: 0.15}).finished.then(() => { }); elementNum++; diff --git a/client/src/services/Utils.js b/client/src/services/Utils.js new file mode 100644 index 00000000..256184c9 --- /dev/null +++ b/client/src/services/Utils.js @@ -0,0 +1,31 @@ +function GetKey(from, key){ + let k = key.split('.'); + let obj = from; + for(let i = 0; i < k.length; i++){ + if(typeof obj !== 'object'){ + // We found a literal before ending! + return; + } + if(Object.keys(obj).includes(k[i])){ + obj = obj[k[i]]; + } else return; + } + return obj; +} + +function SetKey(from, key, value){ + let k = key.split('.'); + let obj = from; + for(let i = 0; i < k.length - 1; i++){ + if(!Object.keys(obj).includes(k[i])){ + obj[k[i]] = {}; + } + obj = obj[k[i]]; + } + obj[k[k.length - 1]] = value; +} + +export { + GetKey, + SetKey +} \ No newline at end of file diff --git a/client/src/views/partials/ConceptEntry.vue b/client/src/views/partials/ConceptEntry.vue index 9fbc3064..7124fd81 100644 --- a/client/src/views/partials/ConceptEntry.vue +++ b/client/src/views/partials/ConceptEntry.vue @@ -2,6 +2,7 @@ import { onMounted, ref, watch } from 'vue'; import { AddContextMenu } from '@/services/ContextMenu'; import { AddTooltip } from '@/services/Tooltip'; +import { GetKey } from '@/services/Utils'; import { marked } from "marked"; const props = defineProps(['element', 'context', 'tooltip', 'icon']); @@ -14,7 +15,8 @@ const icon = ref("icons/game-icons/ffffff/lorc/crossed-swords.svg") async function updateElement(){ element.value = props.element; // Do whatever - let desc = element.value.info.description; + let desc = undefined; + GetKey(element.value, "info.description", (val) => desc = val); desc = desc ? marked.parse(desc) : ''; if(props.icon) icon.value = await props.icon(element.value); diff --git a/client/src/views/partials/Dropdown.vue b/client/src/views/partials/Dropdown.vue index c9eb037c..d1f603d8 100644 --- a/client/src/views/partials/Dropdown.vue +++ b/client/src/views/partials/Dropdown.vue @@ -11,6 +11,7 @@ const selected = ref(initialSelect); onMounted(() => { let context = []; + if(props.selected == undefined) selected.value = "undefined"; watch(() => props.selected, () => { selected.value = props.selected; }); @@ -21,7 +22,7 @@ onMounted(() => { action: () => { HideContextMenu(); selected.value = name; - selectCallback(name); + if(selectCallback) selectCallback(name); } }); }); @@ -34,12 +35,27 @@ onMounted(() => { \ No newline at end of file diff --git a/client/src/views/partials/FormElement.vue b/client/src/views/partials/FormElement.vue new file mode 100644 index 00000000..4ce191a8 --- /dev/null +++ b/client/src/views/partials/FormElement.vue @@ -0,0 +1,8 @@ + + + \ No newline at end of file diff --git a/client/src/views/partials/NumberInput.vue b/client/src/views/partials/Input.vue similarity index 88% rename from client/src/views/partials/NumberInput.vue rename to client/src/views/partials/Input.vue index 44ff05ef..d7e5af1d 100644 --- a/client/src/views/partials/NumberInput.vue +++ b/client/src/views/partials/Input.vue @@ -23,7 +23,9 @@ defineExpose({ \ No newline at end of file diff --git a/client/src/views/partials/Tags.vue b/client/src/views/partials/Tags.vue index b274076f..8bc5b2c6 100644 --- a/client/src/views/partials/Tags.vue +++ b/client/src/views/partials/Tags.vue @@ -71,6 +71,7 @@ defineExpose({ diff --git a/plugins/dnd-5e/locales/en-US.json b/plugins/dnd-5e/locales/en-US.json index 699e36d1..52117e54 100644 --- a/plugins/dnd-5e/locales/en-US.json +++ b/plugins/dnd-5e/locales/en-US.json @@ -1,3 +1,14 @@ { - "test": "Test" + "database": { + "title": "Database", + "tabs": { + "weapons": "Weapons", + "equipment": "Equipment", + "consumables": "Consumables", + "containers": "Containers", + "tools": "Tools", + "spells": "Spells", + "features": "Features" + } + } } \ No newline at end of file