Skip to content

Commit

Permalink
feat: character template
Browse files Browse the repository at this point in the history
  • Loading branch information
RPDeshaies committed Sep 11, 2023
1 parent 320bb5a commit ada0847
Show file tree
Hide file tree
Showing 199 changed files with 10,889 additions and 190 deletions.
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
# TODO

- [ ] templates
- [ ] not found route
- [ ] page meta checks
- [ ] full test suit

# [Fari](https://fari.app) - The Free and Open-Source Virtual Tabletop

<!-- ALL-CONTRIBUTORS-BADGE:START - Do not remove or modify this section -->
Expand Down
16 changes: 14 additions & 2 deletions app/characters/[id]/page.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import { CharacterTemplatesProvider } from "../../../lib/contexts/CharacterTemplatesContext/CharacterTemplatesContext";
import { CharacterRoute } from "../../../lib/routes/Character/CharacterRoute";
import { CharacterTemplateService } from "../../../lib/services/character-templates/CharacterTemplateService";
import { t } from "../../i18n";

export async function generateMetadata() {
Expand All @@ -8,6 +10,16 @@ export async function generateMetadata() {
};
}

export default function CharacterPage() {
return <CharacterRoute></CharacterRoute>;
export default async function CharacterPage() {
const templates = await CharacterTemplateService.getAll();

return (
<CharacterTemplatesProvider
value={{
templates,
}}
>
<CharacterRoute></CharacterRoute>;
</CharacterTemplatesProvider>
);
}
6 changes: 6 additions & 0 deletions app/characters/new/[category]/[name]/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,12 @@ export async function generateMetadata() {
description: t("new-character-route.meta.description"),
};
}
// {template && (
// <PageMeta
// title={`Use the ${template?.fileName} character sheet template on Fari App`}
// description={`Get started playing TTRPGs online with Fari App using this ${template?.fileName} template!`}
// />
// )}

export default function NewCharacterPage() {
return <NewCharacterRoute></NewCharacterRoute>;
Expand Down
13 changes: 13 additions & 0 deletions app/draw/page.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import { DrawRoute } from "../../lib/routes/Draw/DrawRoute";
import { t } from "../i18n";

export async function generateMetadata() {
return {
title: t("draw-route.meta.title"),
description: t("draw-route.meta.description"),
};
}

export default async function CharacterPage() {
return <DrawRoute></DrawRoute>;
}
1 change: 1 addition & 0 deletions app/layout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { Metadata } from "next/types";
import React from "react";
import { AppProviders } from "../lib/App";
import NoSSR from "../lib/components/NoSSR/NoSSR";

export const metadata: Metadata = {
title: "Fari App VTT | The Free and Open-Source Virtual Tabletop",
description: "",
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
"use client";
import { createContext } from "react";
import { ICharacterTemplate } from "../../services/character-templates/CharacterTemplateService";

export const CharacterTemplatesContext = createContext<{
templates: Array<ICharacterTemplate>;
}>(undefined as any);

export const CharacterTemplatesProvider = CharacterTemplatesContext.Provider;
2 changes: 1 addition & 1 deletion lib/contexts/CharactersContext/CharactersContext.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import React from "react";
import { CharacterFactory } from "../../domains/character/CharacterFactory";
import { ICharacterTemplate } from "../../domains/character/CharacterType";
import { ICharacter } from "../../domains/character/types";
import { getUnixFrom } from "../../domains/dayjs/getDayJS";
import { useAppEntity } from "../../hooks/useAppEntity/useAppEntity";
import { ICharacterTemplate } from "../../services/character-templates/CharacterTemplateService";

export const CharactersContext = React.createContext<
ReturnType<typeof useCharacters>
Expand Down
4 changes: 2 additions & 2 deletions lib/domains/character/CharacterFactory.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { produce } from "immer";
import { ICharacterTemplate } from "../../services/character-templates/CharacterTemplateService";
import { Id } from "../Id/Id";
import { getUnix } from "../dayjs/getDayJS";
import { IDiceCommandId } from "../dice/Dice";
import { Migrator } from "../migration/Migrator";
import { ICharacterTemplate } from "./CharacterType";
import {
BlockType,
IBlock,
Expand Down Expand Up @@ -33,7 +33,7 @@ import {
export const CharacterFactory = {
latestVersion: 4,
async make(template: ICharacterTemplate): Promise<ICharacter> {
const result = await template.importFunction();
const result = await fetch(template.fetchPath).then((r) => r.json());
const newCharacter = this.makeFromJson(result);
const characterWithNewName = {
...newCharacter,
Expand Down
54 changes: 0 additions & 54 deletions lib/domains/character/CharacterType.tsx
Original file line number Diff line number Diff line change
@@ -1,54 +0,0 @@
let allCharactersTemplatesFiles: Record<
string,
() => Promise<{
[key: string]: any;
}>
> = {};
try {
// allCharactersTemplatesFiles = import.meta.glob(
// "./character-templates/*/*.json"
// );
} catch (error) {}

export type ICharacterTemplate = {
category: string;
fileName: string;
importFunction: any;
};

export const allTemplates = Object.keys(allCharactersTemplatesFiles).reduce(
(acc: Array<ICharacterTemplate>, fileLocation): Array<ICharacterTemplate> => {
const importFunction = allCharactersTemplatesFiles[fileLocation];

const folderAndFileName = fileLocation
.split("./character-templates/")
.join("");
const folderName = folderAndFileName.split("/")[0];
const fileName = folderAndFileName.split("/")[1].split(".json")[0];

return [
...acc,
{
fileName,
category: folderName,
importFunction,
},
];
},
[],
);

export const CharacterTemplates = [...allTemplates].sort((a, b) => {
if (a.category === "Fari RPGs" && b.category === "Fari RPGs") {
return a.fileName.length - b.fileName.length;
}

if (a.category === "Fari RPGs") {
return -1;
}

if (a.category === b.category) {
return a.fileName.length - b.fileName.length;
}
return 0;
});
30 changes: 14 additions & 16 deletions lib/domains/character/DefaultTemplates.ts
Original file line number Diff line number Diff line change
@@ -1,22 +1,20 @@
import { ICharacterTemplate } from "./CharacterType";
import { ICharacterTemplate } from "../../services/character-templates/CharacterTemplateService";

export const DefaultTemplates = {
BlankTemplate: {
category: "Default",
fileName: "Blank",
importFunction: async () =>
import("./character-templates/Defaults/Blank.json"),
publisher: "Default",
name: "Blank",
fetchPath: "/public/character-templates/Blank/Blank.json",
} as ICharacterTemplate,
FateCondensed: {
category: "Default",
fileName: "FateCondensed",
importFunction: async () =>
import("./character-templates/Fate Condensed/Fate Condensed.json"),
} as ICharacterTemplate,
FateAccelerated: {
category: "Default",
fileName: "FateAccelerated",
importFunction: async () =>
import("./character-templates/Fate Accelerated/Fate Accelerated.json"),
} as ICharacterTemplate,
publisher: "Default",
name: "FateCondensed",
fetchPath: "/public/character-templates/Fate Condensed/Fate Condensed.json",
FateAccelerated: {
publisher: "Default",
name: "FateAccelerated",
fetchPath:
"/public/character-templates/Fate Accelerated/Fate Accelerated.json",
} as ICharacterTemplate,
},
} as const;

This file was deleted.

This file was deleted.

Loading

0 comments on commit ada0847

Please sign in to comment.