From 3e50e84b0eb495c00e58e0b0ee08579427d2b12e Mon Sep 17 00:00:00 2001 From: Aelita4 Date: Fri, 8 Nov 2024 10:56:44 +0100 Subject: [PATCH] Add wiki section --- public/css/markdown.css | 7 ++ src/components/NavBar.astro | 7 ++ src/components/WikiEntry.astro | 22 ++++ src/layouts/Layout.astro | 1 + src/layouts/Wiki.astro | 105 ++++++++++++++++++ src/pages/wiki/buildings/fusion-reactor.md | 8 ++ src/pages/wiki/buildings/index.md | 5 + src/pages/wiki/game/fleet.md | 10 ++ src/pages/wiki/game/index.md | 7 ++ src/pages/wiki/game/system-management.md | 5 + src/pages/wiki/game/universe-structure.md | 18 +++ src/pages/wiki/index.md | 5 + src/pages/wiki/megastructures/dyson-sphere.md | 5 + src/pages/wiki/megastructures/index.md | 8 ++ src/types/WikiPageEntry.ts | 7 ++ 15 files changed, 220 insertions(+) create mode 100644 public/css/markdown.css create mode 100644 src/components/WikiEntry.astro create mode 100644 src/layouts/Wiki.astro create mode 100644 src/pages/wiki/buildings/fusion-reactor.md create mode 100644 src/pages/wiki/buildings/index.md create mode 100644 src/pages/wiki/game/fleet.md create mode 100644 src/pages/wiki/game/index.md create mode 100644 src/pages/wiki/game/system-management.md create mode 100644 src/pages/wiki/game/universe-structure.md create mode 100644 src/pages/wiki/index.md create mode 100644 src/pages/wiki/megastructures/dyson-sphere.md create mode 100644 src/pages/wiki/megastructures/index.md create mode 100644 src/types/WikiPageEntry.ts diff --git a/public/css/markdown.css b/public/css/markdown.css new file mode 100644 index 0000000..cf2a8ae --- /dev/null +++ b/public/css/markdown.css @@ -0,0 +1,7 @@ +.markdown { + line-height: 1.6; +} + +.markdown a { + color: #00a8cc; +} \ No newline at end of file diff --git a/src/components/NavBar.astro b/src/components/NavBar.astro index 7721bd9..5ec9a2e 100644 --- a/src/components/NavBar.astro +++ b/src/components/NavBar.astro @@ -42,6 +42,13 @@ const listOfElements: Array = [{ url: "#", show: "always", position: "top" +}, { + id: "wiki", + title: getName(lang, "general", "nav-wiki"), + type: "simple", + url: "/wiki", + show: "always", + position: "top" }, { id: "login", title: getName(lang, "general", "nav-login"), diff --git a/src/components/WikiEntry.astro b/src/components/WikiEntry.astro new file mode 100644 index 0000000..41d01ff --- /dev/null +++ b/src/components/WikiEntry.astro @@ -0,0 +1,22 @@ +--- +import WikiPageEntry from "../types/WikiPageEntry"; + +const { entry } = Astro.props as { entry: WikiPageEntry }; +--- +
  • + {entry.title} + {entry.children.length > 0 && ( +
      + {entry.children.map((child: WikiPageEntry) => )} +
    + )} +
  • + \ No newline at end of file diff --git a/src/layouts/Layout.astro b/src/layouts/Layout.astro index 7734ce7..c1d8aa8 100644 --- a/src/layouts/Layout.astro +++ b/src/layouts/Layout.astro @@ -27,6 +27,7 @@ if(!Astro.cookies.has('language')) { + {title} diff --git a/src/layouts/Wiki.astro b/src/layouts/Wiki.astro new file mode 100644 index 0000000..0ab73a3 --- /dev/null +++ b/src/layouts/Wiki.astro @@ -0,0 +1,105 @@ +--- +import Layout from '../layouts/Layout.astro'; +import NavBar from '../components/NavBar.astro'; +import WikiEntry from '../components/WikiEntry.astro'; +import WikiPageEntry from '../types/WikiPageEntry'; +import { getUserByAccessToken } from '../lib/db/users'; + +let loggedIn = false; +const loggedToken = Astro.cookies.get('sessionToken')?.value; +const username = Astro.cookies.get('username')?.value; +if(typeof loggedToken !== 'undefined' && typeof username !== 'undefined') { + const checkUser = await getUserByAccessToken(loggedToken); + if(checkUser !== null && checkUser.username === username) loggedIn = true; +} + +const wikiPages = await Astro.glob('../pages/wiki/**/*.md'); + +const pagesArray: Array = [{ + title: 'Home', + url: '/wiki', + depth: 0, + parent: '', + children: [] +}]; + +const tmp = []; + +for(const page of wikiPages) { + if(typeof page.url === 'undefined') continue; + if(page.url === '/wiki') continue; + const url = page.url?.split('/'); + const title = page.frontmatter.title; + const parent = url.slice(0, url.length - 1).join('/'); + const data: WikiPageEntry = { + title, + url: page.url, + depth: url.length - 2, + parent, + children: [] + } + tmp.push(data); +} + +function findRecursively(tree: Array, value: string): WikiPageEntry | null { + if(tree.length === 0) return null; + for(const page of tree) { + if(page.url === value) return page; + const res = findRecursively(page.children, value) + if(res !== null) return res; + } + + return null; +} + +for(const page of tmp.sort((a, b) => a.depth - b.depth)) { + if(page.depth === 1) { + pagesArray.push(page); + } else { + const parent = findRecursively(pagesArray, page.parent); + if(parent !== null) parent.children.push(page); + } +} + +const { frontmatter } = Astro.props; +--- + + +
    + +
    +

    {frontmatter.title}

    +
    + +
    +
    +
    +
    + \ No newline at end of file diff --git a/src/pages/wiki/buildings/fusion-reactor.md b/src/pages/wiki/buildings/fusion-reactor.md new file mode 100644 index 0000000..023de47 --- /dev/null +++ b/src/pages/wiki/buildings/fusion-reactor.md @@ -0,0 +1,8 @@ +--- +layout: ../../../layouts/Wiki.astro +title: Fusion reactor +--- +Fusion reactor is a type of reactor which uses nuclear fusion to generate heat, which is used for generating electricity. Their goal is to mimic the process ongoing inside the Sun, which theoretically could provide mankind with clean and sustainable energy source, without any radioactive waste. + +## Real-life examples +ITER (International Thermonuclear Experimental Reactor) located in France has ongoing research. \ No newline at end of file diff --git a/src/pages/wiki/buildings/index.md b/src/pages/wiki/buildings/index.md new file mode 100644 index 0000000..83b699a --- /dev/null +++ b/src/pages/wiki/buildings/index.md @@ -0,0 +1,5 @@ +--- +layout: ../../../layouts/Wiki.astro +title: Buildings +--- +There are many types of buildings present in-game, many of which are possible to be built in real life. \ No newline at end of file diff --git a/src/pages/wiki/game/fleet.md b/src/pages/wiki/game/fleet.md new file mode 100644 index 0000000..dd4af92 --- /dev/null +++ b/src/pages/wiki/game/fleet.md @@ -0,0 +1,10 @@ +--- +layout: ../../../layouts/Wiki.astro +title: Fleet +--- +Players can send their fleet to any planet for various tasks. + +## Mission types +- Attack - fight is initiated on destination. If there's at least one ship remaining after the fight, it will return to its origin +- Transport - transports resources to selected planet/system. After dropping resources the fleet returns to its origin +- Transfer - all ships will stay in destination planet and get added to this planet's available fleet \ No newline at end of file diff --git a/src/pages/wiki/game/index.md b/src/pages/wiki/game/index.md new file mode 100644 index 0000000..53d57b7 --- /dev/null +++ b/src/pages/wiki/game/index.md @@ -0,0 +1,7 @@ +--- +layout: ../../../layouts/Wiki.astro +title: How to play +--- +Welcome to AstroColony! To start, create an account [here](/register). + +You'll be assigned a single planet, from which you'll have to expand your astronomical empire. \ No newline at end of file diff --git a/src/pages/wiki/game/system-management.md b/src/pages/wiki/game/system-management.md new file mode 100644 index 0000000..3b0a299 --- /dev/null +++ b/src/pages/wiki/game/system-management.md @@ -0,0 +1,5 @@ +--- +layout: ../../../layouts/Wiki.astro +title: System management +--- +System manager allows for player to quickly view summary of each planet inside. Player can also switch currently active planet (shown by its name in resource bar). It's also possible to view system-wide [megastructures](/wiki/megastructures), space stations and asteroid manager. \ No newline at end of file diff --git a/src/pages/wiki/game/universe-structure.md b/src/pages/wiki/game/universe-structure.md new file mode 100644 index 0000000..95770c4 --- /dev/null +++ b/src/pages/wiki/game/universe-structure.md @@ -0,0 +1,18 @@ +--- +layout: ../../../layouts/Wiki.astro +title: Universe structure +--- +In-game universe consists of 4 galaxies, each has 8 predefined sectors: + +| Luminara | Thalor Prime | Zephyra | Nyxara | +| ---------------- | ------------------ | ---------------- | ----------------- | +| Voidcaller Reach | Dreamweaver Reach | Spectral Veil | Embered Fields | +| Starfire Expanse | Azure Chasm | Galecrest Sector | Obsidian Rift | +| Veil of Echoes | Ironclad Citadel | Sapphire Dunes | Lunar Shroud | +| Crystal Nebula | Frostwing Quadrant | Aurora's Embrace | Phantom Outlands | +| Whispering Abyss | Emberveil Rim | Nebulon Haven | Starlit Labyrinth | +| Radiant Outpost | Shadow Nexus | Celestia's Gate | Thorned Garden | +| Celestial Forge | Verdant Oasis | Mystic Falls | Infernal Depths | +| Twilight Bastion | Cosmic Tides | Ethereal Spire | Echoing Plains | + +Each player has their own solar system inside randomly-assigned sector in one of four galaxies. \ No newline at end of file diff --git a/src/pages/wiki/index.md b/src/pages/wiki/index.md new file mode 100644 index 0000000..c633deb --- /dev/null +++ b/src/pages/wiki/index.md @@ -0,0 +1,5 @@ +--- +layout: ../../layouts/Wiki.astro +title: Main page +--- +Welcome to AstroColony's built-in wiki! Here, you'll find various tips and tutorials for playing the game, but also a bit of trivia and interesting facts about various technologies described in the game. \ No newline at end of file diff --git a/src/pages/wiki/megastructures/dyson-sphere.md b/src/pages/wiki/megastructures/dyson-sphere.md new file mode 100644 index 0000000..4576da8 --- /dev/null +++ b/src/pages/wiki/megastructures/dyson-sphere.md @@ -0,0 +1,5 @@ +--- +layout: ../../../layouts/Wiki.astro +title: Dyson sphere +--- +Dyson Sphere (named after Freeman Dyson who proposed the idea in 1960) is a megastructure that harvests energy from star by having lots of solar energy-harvesting satellites orbiting it. \ No newline at end of file diff --git a/src/pages/wiki/megastructures/index.md b/src/pages/wiki/megastructures/index.md new file mode 100644 index 0000000..6b0f2f8 --- /dev/null +++ b/src/pages/wiki/megastructures/index.md @@ -0,0 +1,8 @@ +--- +layout: ../../../layouts/Wiki.astro +title: Megastructures +--- +Megastructure is a theoretical construct on a massive scale, designed to achieve specific functions, such as energy collection ([Dyson sphere](/wiki/megastructures/dyson-sphere)), habitat creation ([O'Neill cylinder](/wiki/megastructures/oneill-cylinder)) or planetary engineering. Construction of such megastructures requires astronomical number of resources, time, work and highly advanced technologies. + +## Real-life examples +There aren't any megastructures built by mankind yet. However, there's ongoing research into various materials and technologies that could allow creation of such megastructures. \ No newline at end of file diff --git a/src/types/WikiPageEntry.ts b/src/types/WikiPageEntry.ts new file mode 100644 index 0000000..1b2bc7f --- /dev/null +++ b/src/types/WikiPageEntry.ts @@ -0,0 +1,7 @@ +export default interface Page { + title: string; + url: string; + depth: number; + parent: string; + children: Page[]; +} \ No newline at end of file