aboutsummaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorLeonardo Bishop <me@leonardobishop.com>2024-03-10 00:13:25 +0000
committerLeonardo Bishop <me@leonardobishop.com>2024-03-10 00:13:25 +0000
commit9a11e0f4a38297006b89cc7bb2a60734111582e0 (patch)
tree5ebddde79e67b659714b5dbdbfcea289f06a4ae5 /lib
parent817478f3cf357fc09778d9dc3cf67a667e21f042 (diff)
Migrate to nuxt
Diffstat (limited to 'lib')
-rw-r--r--lib/materials.ts3
-rw-r--r--lib/questsLoader.ts68
-rw-r--r--lib/util.ts18
3 files changed, 89 insertions, 0 deletions
diff --git a/lib/materials.ts b/lib/materials.ts
new file mode 100644
index 0000000..36c5aee
--- /dev/null
+++ b/lib/materials.ts
@@ -0,0 +1,3 @@
+import materials from '@/data/materials.json';
+
+export default materials; \ No newline at end of file
diff --git a/lib/questsLoader.ts b/lib/questsLoader.ts
new file mode 100644
index 0000000..0623f04
--- /dev/null
+++ b/lib/questsLoader.ts
@@ -0,0 +1,68 @@
+import type { EditorQuest, EditorTask, EditorCategory } from '../stores/session';
+
+export function loadQuestsFromJson(config: any): EditorQuest[] {
+ return Object.keys(config).map((questid: any) => {
+ const quest = config[questid];
+
+ return {
+ id: questid,
+ display: {
+ name: quest.display.name,
+ lore: {
+ normal: quest.display['lore-normal'],
+ started: quest.display['lore-started'],
+ },
+ type: quest.display.type,
+ },
+ tasks: Object.fromEntries(Object.keys(quest.tasks).map((taskId: string) => {
+ return [taskId, {
+ id: taskId,
+ config: quest.tasks[taskId],
+ } as EditorTask];
+ })),
+ rewards: quest.rewards,
+ ...(quest.startcommands && { startCommands: quest.startcommands }),
+ ...(quest.startstring && { startString: quest.startstring }),
+ ...(quest.rewardstring && { rewardString: quest.rewardstring }),
+ ...(quest.placeholders && { placeholders: quest.placeholders }),
+ options: {
+ category: quest.options.category,
+ requirements: quest.options.requires || [],
+ permissionRequired: quest.options['permission-required'] || false,
+ cancellable: quest.options.cancellable || false,
+ countsTowardsLimit: quest.options['counts-towards-limit'] || true,
+ repeatable: quest.options.repeatable || false,
+ cooldown: {
+ enabled: quest.options.cooldown?.enabled || false,
+ time: quest.options.cooldown?.time || 0,
+ },
+ timeLimit: {
+ enabled: quest.options['time-limit']?.enabled || false,
+ time: quest.options['time-limit']?.time || 0,
+ },
+ sortOrder: quest.options['sort-order'] || 0,
+ autostart: quest.options.autostart || false,
+ ...(quest.options['completed-display'] && { completedDisplay: quest.options['completed-display'] }),
+ ...(quest.options['cooldown-display'] && { cooldownDisplay: quest.options['cooldown-display'] }),
+ ...(quest.options['permission-display'] && { permissionDisplay: quest.options['permission-display'] }),
+ ...(quest.options['locked-display'] && { lockedDisplay: quest.options['locked-display'] }),
+ },
+ } as EditorQuest;
+ });
+}
+
+export function loadCategoriesFromJson(config: any): EditorCategory[] {
+ return Object.keys(config).map((categoryid: any) => {
+ const category = config[categoryid];
+
+ return {
+ id: categoryid,
+ display: {
+ name: category.display.name,
+ lore: category.display.lore,
+ type: category.display.type,
+ },
+ permissionRequired: category['permission-required'],
+ };
+ });
+}
diff --git a/lib/util.ts b/lib/util.ts
new file mode 100644
index 0000000..b8be8cb
--- /dev/null
+++ b/lib/util.ts
@@ -0,0 +1,18 @@
+const COLOR_CODE_REGEX = /&[0-9a-fk-or]/i;
+const VALID_ID_REGEX = /^[a-z0-9_]+$/i;
+
+export function stripColorCodes(str: string): string {
+ return str.replace(COLOR_CODE_REGEX, '');
+}
+
+export function validateQuestId(id: string): boolean {
+ return VALID_ID_REGEX.test(id);
+}
+
+export function validateCategoryId(id: string): boolean {
+ return VALID_ID_REGEX.test(id);
+}
+
+export function validateTaskId(id: string): boolean {
+ return VALID_ID_REGEX.test(id);
+} \ No newline at end of file