Skip to content

Commit

Permalink
add forum sql files
Browse files Browse the repository at this point in the history
  • Loading branch information
djsisson committed Aug 26, 2024
1 parent e966400 commit e65cfc4
Show file tree
Hide file tree
Showing 21 changed files with 2,083 additions and 136 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/build.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,4 @@ jobs:
tags: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:latest
- name: Deploy to Coolify
run: |
curl --request GET '${{ secrets.COOLIFY_WEBHOOK }}' --header 'Authorization: Bearer ${{ secrets.COOLIFY_TOKEN }}'
curl --request GET '${{ secrets.COOLIFY_WEBHOOK }}' --header 'Authorization: Bearer ${{ secrets.COOLIFY_TOKEN }}' --header 'CF-Access-Client-Id: ${{ secrets.CF_ID }}' --header 'CF-Access-Client-Secret: ${{ secrets.CF_SECRET }}'
1 change: 1 addition & 0 deletions drizzle.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ export default defineConfig({
"./src/db/genshin/schema.ts",
"./src/db/todos/schema.ts",
"./src/db/tilez/schema.ts",
"./src/db/forum/schema.ts",
],
out: "./src/db/migrations",
dialect: "postgresql",
Expand Down
2 changes: 1 addition & 1 deletion next.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ const nextConfig = {
source: "/assets/:slug*",
headers: [
{
key: "Cache-Control,",
key: "Cache-Control",
value: "public, max-age=31536000, immutable",
},
],
Expand Down
28 changes: 11 additions & 17 deletions src/app/asteroidz/components/Button.tsx
Original file line number Diff line number Diff line change
@@ -1,21 +1,15 @@
"use client";
import Tooltip from "./Tooltip";
import {
useGameState,
useGameStateDispatch,
useGameObject,
gameStateActionType,
} from "./Context";
import { useGameState, useGameStateDispatch, useGameObject } from "./Context";
import { useEffect, useState, useId } from "react";

enum containerType {
Inventory = "Inventory",
Research = "Research",
Upgrades = "Upgrades",
Shop = "Shop",
}

const Button = ({ type, name }: { type: containerType; name: string }) => {
const Button = ({
type,
name,
}: {
type: "Inventory" | "Research" | "Upgrades" | "Shop";
name: string;
}) => {
const dispatch = useGameStateDispatch();
const score = useGameState().currentScore;
const research = useGameState().researched;
Expand Down Expand Up @@ -178,21 +172,21 @@ const Button = ({ type, name }: { type: containerType; name: string }) => {
switch (type) {
case "Research": {
dispatch({
type: gameStateActionType.BUYRESEARCH,
type: "buyResearch",
value: name,
});
return;
}
case "Upgrades": {
dispatch({
type: gameStateActionType.BUYUPGRADE,
type: "buyUpgrade",
value: name,
});
return;
}
case "Shop": {
dispatch({
type: gameStateActionType.BUYITEM,
type: "buyItem",
value: name,
});
return;
Expand Down
9 changes: 1 addition & 8 deletions src/app/asteroidz/components/Container.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,7 @@ type requiredResearch = {
description: string;
};

enum containerType {
Inventory = "Inventory",
Research = "Research",
Upgrades = "Upgrades",
Shop = "Shop",
}

const Container = ({ type }: { type: containerType }) => {
const Container = ({ type }: { type: "Inventory" | "Research" | "Upgrades" | "Shop" }) => {
const [buttonList, setButtonList] = useState([] as ButtonList | typeof inven);
const inven = useGameState().items;
const research = useGameState().researched;
Expand Down
37 changes: 12 additions & 25 deletions src/app/asteroidz/components/Context.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,54 +10,41 @@ import React, {
} from "react";
import { gameObject, gameState } from "../data";

export enum gameStateActionType {
CLICK = "click",
ADDCPS = "addCps",
BUYRESEARCH = "buyResearch",
BUYUPGRADE = "buyUpgrade",
BUYITEM = "buyItem",
UPDATEAVERAGE = "updateAverage",
CHANGETHEME = "changeTheme",
CHANGENAME = "changeName",
LOAD_GAME = "loadGame",
NEW_GAME = "newGame",
}

type gameAction =
| {
type: gameStateActionType.CLICK;
type: "click";
value: number;
}
| {
type: gameStateActionType.ADDCPS;
type: "addCps";
value: number;
}
| {
type: gameStateActionType.BUYRESEARCH;
type: "buyResearch";
value: string;
}
| {
type: gameStateActionType.BUYUPGRADE;
type: "buyUpgrade";
value: string;
}
| {
type: gameStateActionType.BUYITEM;
type: "buyItem";
value: string;
}
| {
type: gameStateActionType.CHANGETHEME;
type: "changeTheme";
value: string;
}
| {
type: gameStateActionType.CHANGENAME;
type: "changeName";
value: string;
}
| {
type: gameStateActionType.LOAD_GAME;
type: "loadGame";
payload: typeof gameState;
}
| {
type: gameStateActionType.NEW_GAME;
type: "newGame";
payload: typeof gameState;
};

Expand Down Expand Up @@ -92,12 +79,12 @@ export const GameStateProvider = ({

if (!localState) {
const getGameState = async () => {
dispatch({ type: gameStateActionType.LOAD_GAME, payload: _gameState });
dispatch({ type: "loadGame", payload: _gameState });
};
getGameState();
} else {
dispatch({
type: gameStateActionType.LOAD_GAME,
type: "loadGame",
payload: JSON.parse(localState) as typeof gameState,
});
}
Expand Down Expand Up @@ -344,7 +331,7 @@ const gameStateReducer = (
}

default: {
throw new Error(`Unknown action: ${action.type}`);
throw new Error(`Unknown action`);
}
}
};
4 changes: 2 additions & 2 deletions src/app/asteroidz/components/Theme.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
"use client";

import { gameStateActionType, useGameStateDispatch } from "./Context";
import { useGameStateDispatch } from "./Context";

const Theme = () => {
const dispatch = useGameStateDispatch();
Expand All @@ -17,7 +17,7 @@ const Theme = () => {

const onClick = ({ colour }: { colour: string }) => {
dispatch({
type: gameStateActionType.CHANGETHEME,
type: "changeTheme",
value: colour,
});
};
Expand Down
8 changes: 2 additions & 6 deletions src/app/asteroidz/components/UserName.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@
"use client";
import {
useGameState,
useGameStateDispatch,
gameStateActionType,
} from "./Context";
import { useGameState, useGameStateDispatch } from "./Context";
import { useState, useRef, useEffect } from "react";

const UserName = () => {
Expand Down Expand Up @@ -47,7 +43,7 @@ const UserName = () => {

const onChange = (e: React.ChangeEvent<HTMLInputElement>) => {
dispatch({
type: gameStateActionType.CHANGENAME,
type: "changeName",
value: e.target.value,
});
};
Expand Down
5 changes: 2 additions & 3 deletions src/app/asteroidz/components/ViewPort.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import {
useGameState,
calcdamage,
useGameStateDispatch,
gameStateActionType,
stats,
} from "./Context";
import VisualScore from "./VisualScore";
Expand Down Expand Up @@ -80,7 +79,7 @@ const ViewPort = () => {
}));
setCpsValues((x) => [...x, ...cpsToAdd]);
dispatch({
type: gameStateActionType.ADDCPS,
type: "addCps",
value: updatedAverageDmg.reduce((i, x) => i + x.totaldamage, 0),
});
};
Expand All @@ -107,7 +106,7 @@ const ViewPort = () => {
} as Score,
]);
dispatch({
type: gameStateActionType.CLICK,
type: "click",
value: getCalcDamage.totaldamage,
});
};
Expand Down
15 changes: 4 additions & 11 deletions src/app/asteroidz/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,24 +8,17 @@ import { ThemeProvider } from "./components/ThemeProvider";
import Total from "./components/Total";
import ViewPort from "./components/ViewPort";

enum containerType {
Inventory = "Inventory",
Research = "Research",
Upgrades = "Upgrades",
Shop = "Shop",
}

export default async function Asteroidz() {

return (
<Suspense fallback={<div>Loading...</div>}>
<GameStateProvider _gameState={gameState} _gameObject={gameObject}>
<ThemeProvider>
<Header />
<Container type={containerType.Inventory} />
<Container type={containerType.Research} />
<Container type={containerType.Upgrades} />
<Container type={containerType.Shop} />
<Container type={"Inventory"} />
<Container type={"Research"} />
<Container type={"Upgrades"} />
<Container type={"Shop"} />
<ViewPort />
<Total />
<Footer />
Expand Down
5 changes: 2 additions & 3 deletions src/app/tilez/components/CurrentWord.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import { useGameState, useGameStateDispatch } from "./GameContext";
import { useEffect, useState, useRef } from "react";
import { uploadScore, getWordDefinition } from "../lib/GameLogic";
import { GameActionType } from "../lib/GameTypes";
import { Badge } from "@/components/ui/badge";
import Help from "./Help";
import {
Expand Down Expand Up @@ -35,7 +34,7 @@ export default function CurrentWord() {
async function upload() {
const uploaded = await uploadScore(gameState);
if (uploaded) {
dispatch({ type: GameActionType.UPLOADED });
dispatch({ type: "UPLOADED" });
setUploading(false);
}
}
Expand All @@ -62,7 +61,7 @@ export default function CurrentWord() {
if (allWords.includes(currentWord)) {
if (!gameState.found.includes(currentWord)) {
dispatch({
type: GameActionType.FOUND,
type: "FOUND",
});
}
if (!definitions.has(currentWord)) {
Expand Down
20 changes: 10 additions & 10 deletions src/app/tilez/components/GameContext.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
"use client";

import React, { createContext, useContext, useReducer, useEffect } from "react";
import { GameAction, GameState, GameActionType } from "../lib/GameTypes";
import { GameAction, GameState } from "../lib/GameTypes";
import { getWordsOnLoad, NewGame } from "../lib/GameLogic";

export const useGameState = () => {
Expand All @@ -28,19 +28,19 @@ const gameStateReducer = (
action: GameAction,
): GameState => {
switch (action.type) {
case GameActionType.LOAD_GAME: {
case "LOAD_GAME": {
return { ...(action.payload as GameState) };
}
case GameActionType.RESET: {
case "RESET": {
const words = Buffer.from(action.payload.words[0], "base64")
.toString("utf-8")
.split(",");
return { ...(action.payload as GameState), words: words };
}
case GameActionType.UPLOADED: {
case "UPLOADED": {
return { ...gameState, uploaded: true };
}
case GameActionType.FOUND: {
case "FOUND": {
const currentWord = gameState.rows
.map((x) => x.tiles[x.position + 1].letter)
.join("");
Expand Down Expand Up @@ -68,13 +68,13 @@ const gameStateReducer = (
}
return newState;
}
case GameActionType.GETSCORE: {
case "GETSCORE": {
return {
...gameState,
score: action.payload,
};
}
case GameActionType.MOVEROW: {
case "MOVEROW": {
return {
...gameState,
moves: gameState.completed ? gameState.moves : gameState.moves + 1,
Expand Down Expand Up @@ -112,7 +112,7 @@ export const GameStateProvider = ({

if (!localState) {
const getGameState = async () => {
dispatch({ type: GameActionType.LOAD_GAME, payload: await NewGame() });
dispatch({ type: "LOAD_GAME", payload: await NewGame() });
};
getGameState();
} else {
Expand All @@ -127,13 +127,13 @@ export const GameStateProvider = ({
.split(",");
loadGame.score = words.score;
dispatch({
type: GameActionType.LOAD_GAME,
type: "LOAD_GAME",
payload: loadGame,
});
} catch (e) {
localStorage.removeItem("Tilez");
dispatch({
type: GameActionType.LOAD_GAME,
type: "LOAD_GAME",
payload: await NewGame(),
});
}
Expand Down
Loading

0 comments on commit e65cfc4

Please sign in to comment.