Skip to content

Commit

Permalink
Experiment basic information's type system.
Browse files Browse the repository at this point in the history
  • Loading branch information
bugcaptor committed Mar 30, 2024
1 parent f3a6330 commit 22398a3
Show file tree
Hide file tree
Showing 12 changed files with 256 additions and 1 deletion.
52 changes: 52 additions & 0 deletions .github/workflows/static.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
# Simple workflow for deploying static content to GitHub Pages
name: Deploy static content to Pages

on:
# Runs on pushes targeting the default branch
push:
branches: ["main"]

# Allows you to run this workflow manually from the Actions tab
workflow_dispatch:

# Sets permissions of the GITHUB_TOKEN to allow deployment to GitHub Pages
permissions:
contents: read
pages: write
id-token: write

# Allow only one concurrent deployment, skipping runs queued between the run in-progress and latest queued.
# However, do NOT cancel in-progress runs as we want to allow these production deployments to complete.
concurrency:
group: "pages"
cancel-in-progress: true

jobs:
# Single deploy job since we're just deploying
deploy:
environment:
name: github-pages
url: ${{ steps.deployment.outputs.page_url }}
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Set up node
uses: actions/setup-node@v4
with:
node-version: 20
cache: 'npm'
- name: Install dependencies
run: npm ci
- name: Build
run: npm run build
- name: Setup Pages
uses: actions/configure-pages@v5
- name: Upload artifact
uses: actions/upload-pages-artifact@v3
with:
# Upload entire repository
path: './dist'
- name: Deploy to GitHub Pages
id: deployment
uses: actions/deploy-pages@v4
8 changes: 8 additions & 0 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,14 @@
<body>
<div id="app">
</div>

<h2>Galaxy</h2>
<div id="galaxy">
</div>

<h2>Ideas</h2>
<div id="ideas">
</div>
<script type="module" src="/src/main.ts"></script>
</body>
</html>
40 changes: 40 additions & 0 deletions src/base_types/idea_base.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
export abstract class IdeaBase {
title: string;
note: string;
tags: string[];
references: string[];
derivedFrom: IdeaBase[];

constructor() {
this.title = "";
this.note = "";
this.tags = [];
this.references = [];
this.derivedFrom = [];
}

describe(indent: string = "") {
const descriptions: string[] = [];
const thisTypeName = this.constructor.name;
descriptions.push(`${indent}- <a href='#IDEA_${thisTypeName}'>${this.title}</a>`);
descriptions.push(`${indent} - ${this.note}`);
if (this.tags.length > 0) {
descriptions.push(`${indent} - Tags: ${this.tags.join(", ")}`);
}
if (this.references.length > 0) {
descriptions.push(`${indent} - References:`);
for (const reference of this.references) {
descriptions.push(`${indent} - ${reference}`);
}
}
if (this.derivedFrom.length > 0) {
descriptions.push(`${indent} - Derived from:`);
for (const idea of this.derivedFrom) {
const typeName = idea.constructor.name;
descriptions.push(`${indent} - <a href='#IDEA_${typeName}'>${typeName}</a>`);
}
}
return descriptions.join("\n");
}
}

20 changes: 20 additions & 0 deletions src/base_types/star_system_base.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
export abstract class StarSystemBase {
name: string;
index: number;
coordinates: number[];

constructor() {
this.name = "";
this.index = 0;
this.coordinates = [];
}

describe(indent: string = "") {
const descriptions: string[] = [];
const thisTypeName = this.constructor.name;
descriptions.push(`${indent}- <a href='#STAR_${thisTypeName}'>${this.name}</a>`);
descriptions.push(`${indent} - Index: ${this.index}`);
descriptions.push(`${indent} - Coordinates: (${this.coordinates.join(", ")})`);
return descriptions.join("\n");
}
}
33 changes: 33 additions & 0 deletions src/galaxy.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import { marked } from "marked";
import { Star1 } from "./stars/star_1";

class Galaxy {
stars: Star1[];

constructor() {
this.stars = [];
}

add_star(star: Star1) {
this.stars.push(star);
}

get_stars() {
return this.stars;
}
}

export function drawGalaxy(galaxy_e: HTMLDivElement) {
const galaxy = new Galaxy();
galaxy.add_star(new Star1());

for (const star of galaxy.get_stars()) {
const starDescription = star.describe();

const star_e = document.createElement('div');
star_e.className = 'star';
star_e.innerHTML = marked(starDescription) as string;
galaxy_e.appendChild(star_e);
}
}

37 changes: 37 additions & 0 deletions src/idea_bank.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import { IdeaBase } from './base_types/idea_base';
import { marked } from 'marked';
import { StarHasMind } from './ideas/star_has_mind';
import { PlantShip } from './ideas/plant_ship';
import { SpaceTravelUsingStarMind } from './ideas/space_travel_using_star_mind';

class IdeaBank {
ideas: IdeaBase[];

constructor() {
this.ideas = [];
}

add_idea(idea: IdeaBase) {
this.ideas.push(idea);
}

get_ideas() {
return this.ideas;
}
}

export function drawAllIdea(ideas_e: HTMLDivElement) {
const ideaBank = new IdeaBank();
ideaBank.add_idea(new StarHasMind());
ideaBank.add_idea(new PlantShip());
ideaBank.add_idea(new SpaceTravelUsingStarMind());

for (const idea of ideaBank.get_ideas()) {
const ideaDescription = idea.describe();

const idea_e = document.createElement('div');
idea_e.className = 'idea';
idea_e.innerHTML = marked(ideaDescription) as string;
ideas_e.appendChild(idea_e);
}
}
15 changes: 15 additions & 0 deletions src/ideas/plant_ship.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import { IdeaBase } from "../base_types/idea_base";

export class PlantShip extends IdeaBase {

constructor() {
super();

this.title = "Plant Ship";
this.note = "A spaceship that is a living plant.";
this.tags = ["space_travel", "spaceship", "plant"];
this.references = [
"https://en.wikipedia.org/wiki/Bio-inspired_robotics",
];
}
}
19 changes: 19 additions & 0 deletions src/ideas/space_travel_using_star_mind.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import { IdeaBase } from "../base_types/idea_base";
import { StarHasMind } from "./star_has_mind";
import { PlantShip } from "./plant_ship";

export class SpaceTravelUsingStarMind extends IdeaBase {
constructor() {
super();

this.title = "Space Travel Using Star Mind";
this.note = "Traveling through space using the mind of a star.";
this.tags = ["star", "universe", "space_travel"];
this.references = [
];
this.derivedFrom = [
new StarHasMind(),
new PlantShip(),
];
}
}
14 changes: 14 additions & 0 deletions src/ideas/star_has_mind.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import { IdeaBase } from "../base_types/idea_base";

export class StarHasMind extends IdeaBase {
constructor() {
super();

this.title = "Star Has Mind";
this.note = "A star is a conscious entity.";
this.tags = ["star", "universe", "space_travel"];
this.references = [
"https://www.sheldrake.org/files/pdfs/papers/Is_the_Sun_Conscious.pdf",
];
}
}
5 changes: 5 additions & 0 deletions src/main.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
import './style.css';
import { drawAllIdea } from './idea_bank';
import { drawGalaxy } from './galaxy';

function startApp() {
console.log('App started');

drawGalaxy(document.getElementById('galaxy') as HTMLDivElement);
drawAllIdea(document.getElementById('ideas') as HTMLDivElement);
}

// when the page is loaded, the script will be executed
Expand Down
12 changes: 12 additions & 0 deletions src/stars/star_1.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import { StarSystemBase } from "../base_types/star_system_base";

export class Star1 extends StarSystemBase {
constructor() {
super();

this.name = "Star 1";
this.index = 1;
this.coordinates = [0.76, 0.43, 0.01];
}
}

2 changes: 1 addition & 1 deletion vite.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { defineConfig, loadEnv } from 'vite'
export default defineConfig(({ command, mode }) => {
const env = loadEnv(mode, process.cwd(), '')
return {
base: '/',
base: '/NatriumStory/',
plugins: [],
define: {
}
Expand Down

0 comments on commit 22398a3

Please sign in to comment.