Compare commits
10 Commits
963295e76b
...
master
| Author | SHA1 | Date | |
|---|---|---|---|
| 94e2b8bd47 | |||
| 030060286f | |||
| b7ad2dc406 | |||
| 2023542229 | |||
| eaac266ebb | |||
| ed782f2fc6 | |||
| f2fd36664c | |||
| 456a0490a7 | |||
| 306dd8cabc | |||
| 50b3e421df |
@@ -13,9 +13,10 @@ jobs:
|
||||
- name: Checkout
|
||||
uses: actions/checkout@v4
|
||||
|
||||
- name: Install SSH client
|
||||
- name: Install dependencies
|
||||
run: |
|
||||
apt-get update -y && apt-get install -y openssh-client
|
||||
apt-get install -y git
|
||||
|
||||
- name: Setup SSH inside container
|
||||
run: |
|
||||
@@ -33,7 +34,11 @@ jobs:
|
||||
|
||||
- name: Build frontend
|
||||
run: |
|
||||
docker build -t git.aranroig.com/${{ secrets.REGISTRY_USER }}/dragonroll-frontend:latest ./frontend
|
||||
docker build -t git.aranroig.com/${{ secrets.REGISTRY_USER }}/dragonroll-frontend:latest \
|
||||
--build-arg NUXT_PUBLIC_GIT_COMMIT=$(git rev-parse --short HEAD) \
|
||||
--build-arg NUXT_PUBLIC_GIT_TAG=$(git describe --tags --abbrev=0) \
|
||||
--build-arg NUXT_PUBLIC_GIT_BRANCH=$(git rev-parse --abbrev-ref HEAD) \
|
||||
./frontend
|
||||
docker push git.aranroig.com/${{ secrets.REGISTRY_USER }}/dragonroll-frontend:latest
|
||||
|
||||
- name: Build backend
|
||||
|
||||
@@ -1 +1 @@
|
||||
API_BASE_URL=https://dragonroll.aranroig.com/api
|
||||
NUXT_PUBLIC_API_BASE_URL=https://dragonroll.aranroig.com/api
|
||||
@@ -1,6 +1,14 @@
|
||||
# ---------- Build Stage ----------
|
||||
FROM node:20-alpine AS builder
|
||||
|
||||
ARG NUXT_PUBLIC_GIT_COMMIT
|
||||
ARG NUXT_PUBLIC_GIT_TAG
|
||||
ARG NUXT_PUBLIC_GIT_BRANCH
|
||||
|
||||
ENV NUXT_PUBLIC_GIT_COMMIT=$NUXT_PUBLIC_GIT_COMMIT
|
||||
ENV NUXT_PUBLIC_GIT_TAG=$NUXT_PUBLIC_GIT_TAG
|
||||
ENV NUXT_PUBLIC_GIT_BRANCH=$NUXT_PUBLIC_GIT_BRANCH
|
||||
|
||||
WORKDIR /app
|
||||
|
||||
# Copy package files
|
||||
|
||||
@@ -31,6 +31,7 @@ $themes: (
|
||||
|
||||
red: #e06c75,
|
||||
green: #98c379,
|
||||
gray: #cccccc,
|
||||
|
||||
icon-invert: 100%
|
||||
),
|
||||
@@ -63,6 +64,7 @@ $themes: (
|
||||
|
||||
red: #e06c75,
|
||||
green: #98c379,
|
||||
gray: #cccccc,
|
||||
|
||||
icon-invert: 0%
|
||||
)
|
||||
|
||||
@@ -4,7 +4,6 @@ import { computed, onMounted, onUnmounted, ref, watch } from 'vue';
|
||||
import { useCampaignService } from '~/services/Campaign.js';
|
||||
import { emitter } from '~/services/Emitter';
|
||||
import Server from '~/services/Server';
|
||||
import { CreateWindow } from '~/services/Windows';
|
||||
|
||||
const { Campaign } = useCampaignService();
|
||||
const notes = ref([]);
|
||||
@@ -64,14 +63,31 @@ function toggleSidebar() {
|
||||
sidebarCollapsed.value = !sidebarCollapsed.value;
|
||||
}
|
||||
|
||||
function openCreateNoteWindow() {
|
||||
async function createNote() {
|
||||
if (!Campaign.value) {
|
||||
return;
|
||||
}
|
||||
|
||||
CreateWindow('create_note');
|
||||
const campaignId = Campaign.value?._id
|
||||
|
||||
try {
|
||||
const response = await Server().post('/note/create', {
|
||||
title: 'New note',
|
||||
content: "",
|
||||
campaign: campaignId
|
||||
});
|
||||
|
||||
if (response.data.status !== 'ok') {
|
||||
return;
|
||||
}
|
||||
|
||||
emitter.emit('note-created', response.data.note);
|
||||
} catch (err) {
|
||||
console.log(err);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
function openNote(note) {
|
||||
emitter.emit('push-note', note);
|
||||
}
|
||||
@@ -136,7 +152,7 @@ watch(Campaign, () => {
|
||||
<button
|
||||
class="sidebar-action"
|
||||
type="button"
|
||||
@click="openCreateNoteWindow"
|
||||
@click="createNote"
|
||||
:disabled="!Campaign"
|
||||
title="New note"
|
||||
aria-label="New note"
|
||||
|
||||
@@ -2,10 +2,9 @@
|
||||
import { onMounted, ref } from 'vue';
|
||||
import { GetUser, LogoutUser } from '@/services/User'
|
||||
|
||||
import Server from '@/services/Server'
|
||||
import Server, { getBaseUrl } from '@/services/Server'
|
||||
|
||||
import { CreateWindow, CreateChildWindow, ClearWindow, GetFirstWindowId } from '../../services/Windows';
|
||||
import { backendUrl } from '../../services/BackendURL';
|
||||
import Spinner from './Spinner.vue';
|
||||
const loadedIcon = ref(false);
|
||||
|
||||
@@ -21,7 +20,7 @@ function retrieveAvatar(){
|
||||
Server().get('/user/retrieve-avatar?username=' + GetUser().username)
|
||||
.then((response) => {
|
||||
if(response.data.image){
|
||||
const imgUrl = backendUrl + "/public/" + response.data.image;
|
||||
const imgUrl = getBaseUrl() + "/public/" + response.data.image;
|
||||
|
||||
// Wait for the image to fully load
|
||||
const img = new Image();
|
||||
|
||||
@@ -10,12 +10,30 @@ const campaignName = computed(() => {
|
||||
return Campaign.value?.name ?? 'Campaign';
|
||||
});
|
||||
|
||||
function openCreateNoteWindow() {
|
||||
async function createNote() {
|
||||
if (!Campaign.value) {
|
||||
return;
|
||||
}
|
||||
|
||||
CreateWindow('create_note');
|
||||
const campaignId = Campaign.value?._id
|
||||
|
||||
try {
|
||||
const response = await Server().post('/note/create', {
|
||||
title: 'New note',
|
||||
content: content.value,
|
||||
campaign: campaignId
|
||||
});
|
||||
|
||||
if (response.data.status !== 'ok') {
|
||||
return;
|
||||
}
|
||||
|
||||
emitter.emit('note-created', response.data.note);
|
||||
} catch (err) {
|
||||
error.value = 'Unable to create note.';
|
||||
} finally {
|
||||
isSaving.value = false;
|
||||
}
|
||||
}
|
||||
|
||||
function exitToMainMenu() {
|
||||
@@ -42,7 +60,7 @@ function exitToMainMenu() {
|
||||
<img class="top-bar-button-icon" src="/icons/iconoir/regular/nav-arrow-left.svg" alt="" aria-hidden="true">
|
||||
<span>Main Menu</span>
|
||||
</button>
|
||||
<button class="note-button sound-click" type="button" @click="openCreateNoteWindow" :disabled="!Campaign">
|
||||
<button class="note-button sound-click" type="button" @click="createNote" :disabled="!Campaign">
|
||||
<img class="note-button-icon" src="/icons/iconoir/regular/plus.svg" alt="" aria-hidden="true">
|
||||
<span>New Note</span>
|
||||
</button>
|
||||
|
||||
@@ -28,11 +28,14 @@ const compiledMarkdown = computed(() => {
|
||||
});
|
||||
|
||||
function mountComponents() {
|
||||
const nodes = document.querySelectorAll('.vue-component');
|
||||
|
||||
nodes.forEach(el => {
|
||||
const app = createApp(GetWidget(el.dataset.component), { content: el.dataset.content });
|
||||
app.mount(el);
|
||||
// Should no need more
|
||||
const widget_types = ['display', 'inline'];
|
||||
widget_types.forEach((widget_type) => {
|
||||
const nodes = document.querySelectorAll('.vue-component-' + widget_type);
|
||||
nodes.forEach(el => {
|
||||
const app = createApp(GetWidget(widget_type, el.dataset.component), { content: el.dataset.content });
|
||||
app.mount(el);
|
||||
});
|
||||
});
|
||||
}
|
||||
///
|
||||
|
||||
@@ -0,0 +1,177 @@
|
||||
<script setup>
|
||||
const props = defineProps(['content']);
|
||||
|
||||
import { parse } from '~/services/widgets/DiceParser';
|
||||
import { AddSound } from '~/services/Sound';
|
||||
|
||||
const container = ref(null);
|
||||
const resultText = ref("");
|
||||
const steps = ref(null);
|
||||
const stepsHtml = ref("");
|
||||
|
||||
const rollDice = () => {
|
||||
const result = parse(props.content);
|
||||
resultText.value = result.total;
|
||||
stepsHtml.value = result.steps.map(renderStep).join('');
|
||||
};
|
||||
|
||||
const renderStep = (s) => {
|
||||
if (s.type === 'op') {
|
||||
const label = s.op === '*' ? '×' : s.op === '/' ? '÷' : s.op;
|
||||
return `<span class="step-op">${label}</span>`;
|
||||
}
|
||||
|
||||
if (s.type === 'const') {
|
||||
return `<span class="step-const">${s.value}</span>`;
|
||||
}
|
||||
|
||||
if (s.type === 'dice') {
|
||||
const { entry } = s;
|
||||
const { rawRolls, kept, sides, mod, value } = entry;
|
||||
|
||||
const keptCopy = [...kept];
|
||||
const tagged = rawRolls.map(v => {
|
||||
const i = keptCopy.indexOf(v);
|
||||
if (i !== -1) { keptCopy.splice(i, 1); return { v, kept: true }; }
|
||||
return { v, kept: false };
|
||||
});
|
||||
|
||||
let html = '';
|
||||
|
||||
tagged.forEach(({ v, kept }) => {
|
||||
const isMax = v === sides, isMin = v === 1;
|
||||
const cls = !kept ? 'roll-val dropped'
|
||||
: isMax ? 'roll-val max-val'
|
||||
: isMin ? 'roll-val min-val'
|
||||
: 'roll-val kept';
|
||||
html += `<span class="${cls}">${v}</span>`;
|
||||
});
|
||||
|
||||
if (kept.length < rawRolls.length || kept.length > 1) {
|
||||
html += `<span class="step-sum">=${value}</span>`;
|
||||
}
|
||||
|
||||
return html;
|
||||
}
|
||||
|
||||
return '';
|
||||
};
|
||||
|
||||
onMounted(() => {
|
||||
AddSound(container.value);
|
||||
});
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div class="roll-widget" ref="container">
|
||||
<div class="roll-widget-body">
|
||||
<span class="result-text">{{ resultText || '-' }}</span>
|
||||
<button class="btn-primary roll-btn sound-click" @click="rollDice">
|
||||
<span class="dice-content">
|
||||
<!-- Dice icon (SVG) -->
|
||||
<img class="icon" src="/icons/iconoir/regular/dice-three.svg" draggable="false">
|
||||
</span>
|
||||
</button>
|
||||
</div>
|
||||
<div class="roll-widget-results">
|
||||
<span class="formula">{{ "[" + props.content + "]" }}</span>
|
||||
<div class="steps" v-html="stepsHtml"></div>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<style scoped>
|
||||
.steps {
|
||||
margin-left: 8px;
|
||||
height: 22px;
|
||||
> {
|
||||
font-size: 12px;
|
||||
}
|
||||
}
|
||||
.steps :deep(.roll-val){
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
min-width: 18px;
|
||||
padding: 1px 2px;
|
||||
border-radius: 3px;
|
||||
margin: 2px;
|
||||
font-size: 12px;
|
||||
border: 1px solid;
|
||||
}
|
||||
.steps :deep(.roll-val.kept){
|
||||
background: rgba(93,184,122,0.12);
|
||||
border-color: #4a8c5c;
|
||||
color: #a8d4b4;
|
||||
}
|
||||
|
||||
.steps :deep(.roll-val.dropped) {
|
||||
background: transparent;
|
||||
border-color: var(--color-border);
|
||||
color: var(--color-text-tertiary);
|
||||
text-decoration: line-through;
|
||||
}
|
||||
|
||||
.steps :deep(.roll-val.max-val) {
|
||||
background: rgba(93,184,122,0.2);
|
||||
border-color: #5db87a;
|
||||
color: #5db87a;
|
||||
}
|
||||
|
||||
.steps :deep(.roll-val.min-val) {
|
||||
background: rgba(201,95,95,0.12);
|
||||
border-color: #c95f5f;
|
||||
color: #c95f5f;
|
||||
}
|
||||
|
||||
.steps :deep(.step-op) { color: var(--color-text-secondary); padding: 0 4px; font-size: 13px; }
|
||||
.steps :deep(.step-const) { font-size: 13px; color: var(--color-text-primary); padding: 0 2px; }
|
||||
.steps :deep(.step-dice-label) { font-size: 11px; color: var(--color-text-tertiary); margin-right: 2px; }
|
||||
.steps :deep(.step-sum) { font-size: 11px; color: var(--color-text-tertiary); margin-left: 2px; }
|
||||
.steps :deep(.dice-mod) { font-style: normal; margin-left: 2px; }
|
||||
|
||||
.result-text {
|
||||
font-size: 24px;
|
||||
vertical-align: center;
|
||||
}
|
||||
|
||||
.roll-widget-body {
|
||||
width: 100%;
|
||||
display: flex;
|
||||
flex-direction: row;
|
||||
justify-content: space-between;
|
||||
align-items: center;
|
||||
}
|
||||
|
||||
.result-text {
|
||||
margin-left: 12px;
|
||||
}
|
||||
|
||||
.formula {
|
||||
margin-left: 12px;
|
||||
font-family: ui-monospace, monospace;
|
||||
font-size: 12px;
|
||||
color: var(--color-gray);
|
||||
}
|
||||
|
||||
.roll-widget-results {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
padding-bottom: 10px;
|
||||
}
|
||||
|
||||
.roll-widget {
|
||||
width: 100%;
|
||||
background-color: var(--color-background-light);
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
margin-bottom: 8px;
|
||||
border-radius: 6px;
|
||||
}
|
||||
|
||||
.roll-btn {
|
||||
padding: 8px;
|
||||
margin-right: 8px;
|
||||
}
|
||||
|
||||
</style>
|
||||
@@ -1,150 +0,0 @@
|
||||
<script setup>
|
||||
import { computed, onMounted, ref } from 'vue';
|
||||
import { SetupHandle, SetSize, ResetPosition, Top, ClearWindow } from '@/services/Windows';
|
||||
import WindowHandle from './partials/WindowHandle.vue';
|
||||
import Server from '~/services/Server';
|
||||
import { emitter } from '~/services/Emitter';
|
||||
import { useCampaignService } from '~/services/Campaign';
|
||||
|
||||
const handle = ref(null);
|
||||
const wrapper = ref(null);
|
||||
|
||||
const props = defineProps(['data']);
|
||||
const data = props.data;
|
||||
|
||||
const { Campaign } = useCampaignService();
|
||||
|
||||
const id = data.id;
|
||||
const title = ref('');
|
||||
const content = ref('');
|
||||
const isSaving = ref(false);
|
||||
const error = ref('');
|
||||
|
||||
const campaignId = computed(() => {
|
||||
return Campaign.value?._id ?? Campaign.value?.id ?? null;
|
||||
});
|
||||
|
||||
onMounted(() => {
|
||||
Top(wrapper);
|
||||
SetupHandle(id, handle);
|
||||
SetSize(id, { width: 640, height: 520 });
|
||||
ResetPosition(id, "center");
|
||||
});
|
||||
|
||||
async function createNote() {
|
||||
if (!campaignId.value || isSaving.value) {
|
||||
return;
|
||||
}
|
||||
|
||||
isSaving.value = true;
|
||||
error.value = '';
|
||||
|
||||
try {
|
||||
const response = await Server().post('/note/create', {
|
||||
title: title.value.trim() || 'Untitled Note',
|
||||
content: content.value,
|
||||
campaign: campaignId.value
|
||||
});
|
||||
|
||||
if (response.data.status !== 'ok') {
|
||||
error.value = response.data.msg ?? 'Unable to create note.';
|
||||
return;
|
||||
}
|
||||
|
||||
emitter.emit('note-created', response.data.note);
|
||||
ClearWindow({ id });
|
||||
} catch (err) {
|
||||
error.value = 'Unable to create note.';
|
||||
} finally {
|
||||
isSaving.value = false;
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div class="window-wrapper" :id="'window-wrapper-' + id" ref="wrapper">
|
||||
<WindowHandle :window="id" ref="handle"></WindowHandle>
|
||||
|
||||
<div class="body">
|
||||
<form @submit.prevent="createNote">
|
||||
<div class="form-field">
|
||||
<label>Title</label>
|
||||
<input v-model="title" type="text" name="noteTitle" placeholder="Enter a note title" autocomplete="off">
|
||||
</div>
|
||||
|
||||
<div class="form-field stacked">
|
||||
<label>Content</label>
|
||||
<textarea v-model="content" name="noteContent" placeholder="Write your note here"></textarea>
|
||||
</div>
|
||||
|
||||
<div v-if="error" class="form-error">
|
||||
{{ error }}
|
||||
</div>
|
||||
|
||||
<div class="form-actions">
|
||||
<button class="btn-primary sound-click" :disabled="isSaving">
|
||||
{{ isSaving ? 'Creating...' : 'Create Note' }}
|
||||
</button>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<style scoped>
|
||||
.window-wrapper {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
flex-direction: column;
|
||||
}
|
||||
|
||||
.body {
|
||||
width: 100%;
|
||||
}
|
||||
|
||||
form {
|
||||
margin: 10px;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 12px;
|
||||
}
|
||||
|
||||
.form-field {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 12px;
|
||||
}
|
||||
|
||||
.form-field > * {
|
||||
flex: 1;
|
||||
}
|
||||
|
||||
.stacked {
|
||||
align-items: stretch;
|
||||
flex-direction: column;
|
||||
gap: 6px;
|
||||
}
|
||||
|
||||
label {
|
||||
text-align: left;
|
||||
}
|
||||
|
||||
textarea {
|
||||
min-height: 300px;
|
||||
resize: vertical;
|
||||
}
|
||||
|
||||
.form-error {
|
||||
color: #9e2a2b;
|
||||
font-size: 14px;
|
||||
}
|
||||
|
||||
.form-actions {
|
||||
display: flex;
|
||||
justify-content: center;
|
||||
}
|
||||
|
||||
.form-actions button {
|
||||
width: 100%;
|
||||
}
|
||||
</style>
|
||||
6
frontend/app/plugins/api.ts
Normal file
6
frontend/app/plugins/api.ts
Normal file
@@ -0,0 +1,6 @@
|
||||
import { initApi } from '../services/Server';
|
||||
|
||||
export default defineNuxtPlugin(() => {
|
||||
const config = useRuntimeConfig();
|
||||
initApi(config.public.apiBaseUrl);
|
||||
});
|
||||
@@ -5,7 +5,6 @@ function loadLocaleMessages() {
|
||||
const messages: Record<string, any> = {}
|
||||
|
||||
for (const path in locales) {
|
||||
console.log(path);
|
||||
const matched = path.match(/i18n\/locales\/(\w+)\/(.*)\.json$/)
|
||||
if (!matched) continue
|
||||
|
||||
@@ -18,7 +17,6 @@ function loadLocaleMessages() {
|
||||
messages[locale][file] = (locales[path] as any).default
|
||||
}
|
||||
|
||||
console.log(messages);
|
||||
return messages
|
||||
}
|
||||
|
||||
|
||||
@@ -1,5 +0,0 @@
|
||||
const backendUrl = import.meta.env.API_BASE_URL || 'http://localhost:5000/api'
|
||||
|
||||
export {
|
||||
backendUrl
|
||||
};
|
||||
@@ -1,27 +1,33 @@
|
||||
import { Marked } from "marked";
|
||||
const widget_map = {
|
||||
test: () => import("~/components/viewer/widgets/TestWidget.vue"),
|
||||
table: () => import("~/components/viewer/widgets/TableWidget.vue"),
|
||||
roll: () => import("~/components/viewer/widgets/RollWidget.vue"),
|
||||
inline: {
|
||||
roll: () => import("~/components/viewer/widgets/inline/RollWidgetInline.vue"),
|
||||
},
|
||||
display: {
|
||||
roll: () => import("~/components/viewer/widgets/display/RollWidgetDisplay.vue"),
|
||||
}
|
||||
};
|
||||
|
||||
const componentCache = {}
|
||||
const componentCache = {
|
||||
inline: {},
|
||||
display: {}
|
||||
}
|
||||
|
||||
const GetWidget = (type) => {
|
||||
if (!componentCache[type]) {
|
||||
componentCache[type] = defineAsyncComponent(
|
||||
widget_map[type]
|
||||
const GetWidget = (type, name) => {
|
||||
if (!componentCache[type][name]) {
|
||||
componentCache[type][name] = defineAsyncComponent(
|
||||
widget_map[type][name]
|
||||
)
|
||||
}
|
||||
|
||||
return componentCache[type]
|
||||
return componentCache[type][name]
|
||||
}
|
||||
|
||||
|
||||
const marker = new Marked();
|
||||
|
||||
const extension = {
|
||||
name: "something",
|
||||
name: "widget",
|
||||
level: "block",
|
||||
|
||||
tokenizer(src) {
|
||||
@@ -31,7 +37,7 @@ const extension = {
|
||||
if (!match) return;
|
||||
|
||||
return {
|
||||
type: "something",
|
||||
type: "widget",
|
||||
raw: match[0],
|
||||
name: match[1],
|
||||
text: match[2],
|
||||
@@ -39,12 +45,12 @@ const extension = {
|
||||
},
|
||||
|
||||
renderer(token) {
|
||||
return `<div class="vue-component" data-component="${token.name}" data-content="${token.text}"></div>`;
|
||||
return `<div class="vue-component-display" data-component="${token.name}" data-content="${token.text}"></div>`;
|
||||
},
|
||||
};
|
||||
|
||||
const inlineExtension = {
|
||||
name: "something_inline",
|
||||
name: "widget_inline",
|
||||
level: "inline",
|
||||
start(src) {
|
||||
return src.indexOf("@");
|
||||
@@ -56,7 +62,7 @@ const inlineExtension = {
|
||||
if (!match) return;
|
||||
|
||||
return {
|
||||
type: "something_inline",
|
||||
type: "widget_inline",
|
||||
raw: match[0],
|
||||
name: match[1],
|
||||
text: match[2],
|
||||
@@ -64,12 +70,36 @@ const inlineExtension = {
|
||||
},
|
||||
|
||||
renderer(token) {
|
||||
return `<span class="vue-component" data-component="${token.name}" data-content="${token.text}"></span>`;
|
||||
return `<span class="vue-component-inline" data-component="${token.name}" data-content="${token.text}"></span>`;
|
||||
},
|
||||
};
|
||||
|
||||
const linkExtension = {
|
||||
name: "link_to",
|
||||
level: "inline",
|
||||
start(src) {
|
||||
return src.indexOf("[[");
|
||||
},
|
||||
|
||||
tokenizer(src) {
|
||||
const rule = /^\[\[([^\n]*)\]\]/;
|
||||
const match = rule.exec(src);
|
||||
if (!match) return;
|
||||
|
||||
return {
|
||||
type: "link_to",
|
||||
raw: match[0],
|
||||
link: match[1],
|
||||
};
|
||||
},
|
||||
|
||||
renderer(token) {
|
||||
return `<span class="vue-link" data-href="${token.link}"></span>`;
|
||||
},
|
||||
};
|
||||
|
||||
marker.use({
|
||||
extensions: [extension, inlineExtension],
|
||||
extensions: [extension, inlineExtension, linkExtension],
|
||||
});
|
||||
|
||||
function ParseMarkdown(source) {
|
||||
|
||||
@@ -1,13 +1,16 @@
|
||||
import axios from 'axios';
|
||||
|
||||
const server = axios.create({
|
||||
baseURL: import.meta.env.API_BASE_URL || 'http://localhost:5000/api',
|
||||
baseURL: 'http://localhost:5000/api', // fallback only
|
||||
headers: {
|
||||
"Access-Control-Allow-Origin": "*",
|
||||
}
|
||||
});
|
||||
|
||||
// Attach token dynamically on each request via interceptor
|
||||
export const initApi = (baseURL) => {
|
||||
server.defaults.baseURL = baseURL;
|
||||
};
|
||||
|
||||
server.interceptors.request.use((config) => {
|
||||
const token = localStorage.getItem('token');
|
||||
if (token) {
|
||||
@@ -16,4 +19,6 @@ server.interceptors.request.use((config) => {
|
||||
return config;
|
||||
});
|
||||
|
||||
export default () => server;
|
||||
export default () => server;
|
||||
|
||||
export const getBaseUrl = () => server.defaults.baseURL;
|
||||
@@ -34,12 +34,6 @@ const defWindows = {
|
||||
component: () => import('~/components/windows/CreateCampaignWindow.vue'),
|
||||
close: () => ClearWindow({type: 'create_campaign'}),
|
||||
movable: true
|
||||
},
|
||||
create_note: {
|
||||
title: "Create note",
|
||||
component: () => import('~/components/windows/CreateNoteWindow.vue'),
|
||||
close: () => ClearWindow({type: 'create_note'}),
|
||||
movable: true
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
// dice-parser.js
|
||||
// DiceParser.js
|
||||
|
||||
function roll(sides) {
|
||||
return Math.floor(Math.random() * sides) + 1;
|
||||
@@ -27,10 +27,9 @@ export function parse(expr) {
|
||||
const tokens = tokenize(expr);
|
||||
if (!tokens.length) throw new Error('Empty expression');
|
||||
let pos = 0;
|
||||
const rolls = [];
|
||||
|
||||
function peek() { return tokens[pos]; }
|
||||
function consume() { return tokens[pos++]; }
|
||||
const peek = () => tokens[pos];
|
||||
const consume = () => tokens[pos++];
|
||||
|
||||
function parseExpr() { return parseAddSub(); }
|
||||
|
||||
@@ -41,7 +40,7 @@ export function parse(expr) {
|
||||
const right = parseMulDiv();
|
||||
left = {
|
||||
value: op === '+' ? left.value + right.value : left.value - right.value,
|
||||
rolls: [...left.rolls, ...right.rolls],
|
||||
steps: [...left.steps, { type: 'op', op }, ...right.steps],
|
||||
};
|
||||
}
|
||||
return left;
|
||||
@@ -55,7 +54,7 @@ export function parse(expr) {
|
||||
if (op === '/' && right.value === 0) throw new Error('Division by zero');
|
||||
left = {
|
||||
value: op === '*' ? left.value * right.value : Math.floor(left.value / right.value),
|
||||
rolls: [...left.rolls, ...right.rolls],
|
||||
steps: [...left.steps, { type: 'op', op }, ...right.steps],
|
||||
};
|
||||
}
|
||||
return left;
|
||||
@@ -65,7 +64,7 @@ export function parse(expr) {
|
||||
if (peek() === '-') {
|
||||
consume();
|
||||
const r = parsePrimary();
|
||||
return { value: -r.value, rolls: r.rolls };
|
||||
return { value: -r.value, steps: [{ type: 'op', op: '-' }, ...r.steps] };
|
||||
}
|
||||
return parsePrimary();
|
||||
}
|
||||
@@ -79,7 +78,10 @@ export function parse(expr) {
|
||||
const inner = parseExpr();
|
||||
if (peek() !== ')') throw new Error('Missing closing )');
|
||||
consume();
|
||||
return inner;
|
||||
return {
|
||||
value: inner.value,
|
||||
steps: [{ type: 'op', op: '(' }, ...inner.steps, { type: 'op', op: ')' }],
|
||||
};
|
||||
}
|
||||
|
||||
const diceInfo = parseDiceToken(tok);
|
||||
@@ -90,7 +92,8 @@ export function parse(expr) {
|
||||
|
||||
if (/^\d+$/.test(tok)) {
|
||||
consume();
|
||||
return { value: parseInt(tok), rolls: [] };
|
||||
const v = parseInt(tok);
|
||||
return { value: v, steps: [{ type: 'const', value: v }] };
|
||||
}
|
||||
|
||||
throw new Error(`Unexpected token: ${tok}`);
|
||||
@@ -119,12 +122,13 @@ export function parse(expr) {
|
||||
}
|
||||
|
||||
const entry = { sides, rawRolls, kept, mod, value: kept.reduce((a, b) => a + b, 0) };
|
||||
rolls.push(entry);
|
||||
return { value: entry.value, rolls: [entry] };
|
||||
return {
|
||||
value: entry.value,
|
||||
steps: [{ type: 'dice', entry }],
|
||||
};
|
||||
}
|
||||
|
||||
const result = parseExpr();
|
||||
if (pos < tokens.length) throw new Error(`Unexpected token: ${tokens[pos]}`);
|
||||
|
||||
return { total: result.value, rolls: result.rolls };
|
||||
return { total: result.value, steps: result.steps };
|
||||
}
|
||||
@@ -43,7 +43,7 @@ export default defineNuxtConfig({
|
||||
|
||||
runtimeConfig: {
|
||||
public: {
|
||||
apiBaseUrl: process.env.API_BASE_URL || 'http://localhost:5000/api',
|
||||
apiBaseUrl: process.env.NUXT_PUBLIC_API_BASE_URL || 'http://localhost:5000/api',
|
||||
gitCommit: git.commit,
|
||||
gitTag: git.tag,
|
||||
gitBranch: git.branch,
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
"type": "module",
|
||||
"private": true,
|
||||
"scripts": {
|
||||
"build": "nuxt build",
|
||||
"build": "nuxt build --dotenv .env.production",
|
||||
"dev": "nuxt dev",
|
||||
"generate": "nuxt generate",
|
||||
"preview": "nuxt preview",
|
||||
|
||||
Reference in New Issue
Block a user