├── src ├── react-app-env.d.ts ├── assets │ ├── img │ │ ├── items.png │ │ ├── momup.png │ │ ├── carolup.png │ │ ├── henryup.png │ │ ├── joshyup.png │ │ ├── momdown.png │ │ ├── momleft.png │ │ ├── caroldown.png │ │ ├── carolleft.png │ │ ├── carolright.png │ │ ├── embySprite.png │ │ ├── henrydown.png │ │ ├── henryleft.png │ │ ├── henryright.png │ │ ├── joshydown.png │ │ ├── joshyleft.png │ │ ├── joshyright.png │ │ ├── momright.png │ │ ├── playerdown.png │ │ ├── playerleft.png │ │ ├── playerup.png │ │ ├── townMap400.png │ │ ├── playerright.png │ │ ├── draggleSprite.png │ │ ├── townBackground │ │ │ ├── image_part_001.png │ │ │ ├── image_part_002.png │ │ │ ├── image_part_003.png │ │ │ ├── image_part_004.png │ │ │ ├── image_part_005.png │ │ │ ├── image_part_006.png │ │ │ ├── image_part_007.png │ │ │ ├── image_part_008.png │ │ │ ├── image_part_009.png │ │ │ ├── image_part_010.png │ │ │ ├── image_part_011.png │ │ │ ├── image_part_012.png │ │ │ ├── image_part_013.png │ │ │ ├── image_part_014.png │ │ │ ├── image_part_015.png │ │ │ └── image_part_016.png │ │ └── townForeground │ │ │ ├── image_part_001.png │ │ │ ├── image_part_002.png │ │ │ ├── image_part_003.png │ │ │ ├── image_part_004.png │ │ │ ├── image_part_005.png │ │ │ ├── image_part_006.png │ │ │ ├── image_part_007.png │ │ │ ├── image_part_008.png │ │ │ ├── image_part_009.png │ │ │ ├── image_part_010.png │ │ │ ├── image_part_011.png │ │ │ ├── image_part_012.png │ │ │ ├── image_part_013.png │ │ │ ├── image_part_014.png │ │ │ ├── image_part_015.png │ │ │ └── image_part_016.png │ └── collision │ │ ├── townCollision.ts │ │ └── townLocation.ts ├── frontend │ ├── engine │ │ ├── comps │ │ │ ├── CClickable.ts │ │ │ ├── CGridCollider.ts │ │ │ ├── CTransform.ts │ │ │ ├── CInteractive.ts │ │ │ ├── CBackgroundTile.ts │ │ │ ├── CForegroundTile.ts │ │ │ ├── CAgent.ts │ │ │ ├── CInventory.ts │ │ │ └── CSprite.ts │ │ ├── systems │ │ │ ├── SpriteLocationSystem.ts │ │ │ ├── rendering │ │ │ │ ├── BackgroundRenderSystem.ts │ │ │ │ ├── ForegroundRenderSystem.ts │ │ │ │ └── SpriteRenderSystem.ts │ │ │ ├── MousePickerSystem.ts │ │ │ ├── PlayerInteractionSystem.ts │ │ │ ├── GridMovementSystem.ts │ │ │ └── AgentMovementSystem.ts │ │ ├── GameContext.ts │ │ └── TypedAsset.ts │ ├── components │ │ ├── LoadingIndicator.tsx │ │ ├── GameCanvas.tsx │ │ ├── Conversation.tsx │ │ └── Game.tsx │ ├── styles │ │ └── components │ │ │ ├── Game.css │ │ │ ├── LoadingIndicator.css │ │ │ └── Conversation.css │ └── infra │ │ ├── BoundedBox.ts │ │ ├── KeyListener.ts │ │ ├── Inputmapper.ts │ │ ├── MouseListener.ts │ │ ├── ShortestPath.ts │ │ ├── LinAlg.ts │ │ └── Ecs.ts ├── setupTests.ts ├── App.tsx ├── backend │ ├── models │ │ ├── ConversationModel.ts │ │ └── MessageModel.ts │ ├── repos │ │ └── NpcRepo.ts │ ├── services │ │ ├── LocationService.ts │ │ └── ConversationService.ts │ ├── interfaces │ │ ├── INpcRepo.ts │ │ └── IConversationService.ts │ └── data │ │ ├── locationData.ts │ │ └── npcs │ │ └── NpcData.ts ├── App.test.tsx ├── index.css ├── reportWebVitals.ts ├── index.tsx ├── GptTest.tsx ├── App.css ├── Api.tsx └── logo.svg ├── public ├── favicon.ico ├── logo192.png ├── logo512.png ├── robots.txt ├── manifest.json └── index.html ├── .gitignore ├── tsconfig.json ├── LICENSE.md ├── package.json └── README.md /src/react-app-env.d.ts: -------------------------------------------------------------------------------- 1 | /// 2 | -------------------------------------------------------------------------------- /public/favicon.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/blurrypiano/monster-chat/HEAD/public/favicon.ico -------------------------------------------------------------------------------- /public/logo192.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/blurrypiano/monster-chat/HEAD/public/logo192.png -------------------------------------------------------------------------------- /public/logo512.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/blurrypiano/monster-chat/HEAD/public/logo512.png -------------------------------------------------------------------------------- /public/robots.txt: -------------------------------------------------------------------------------- 1 | # https://www.robotstxt.org/robotstxt.html 2 | User-agent: * 3 | Disallow: 4 | -------------------------------------------------------------------------------- /src/assets/img/items.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/blurrypiano/monster-chat/HEAD/src/assets/img/items.png -------------------------------------------------------------------------------- /src/assets/img/momup.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/blurrypiano/monster-chat/HEAD/src/assets/img/momup.png -------------------------------------------------------------------------------- /src/assets/img/carolup.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/blurrypiano/monster-chat/HEAD/src/assets/img/carolup.png -------------------------------------------------------------------------------- /src/assets/img/henryup.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/blurrypiano/monster-chat/HEAD/src/assets/img/henryup.png -------------------------------------------------------------------------------- /src/assets/img/joshyup.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/blurrypiano/monster-chat/HEAD/src/assets/img/joshyup.png -------------------------------------------------------------------------------- /src/assets/img/momdown.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/blurrypiano/monster-chat/HEAD/src/assets/img/momdown.png -------------------------------------------------------------------------------- /src/assets/img/momleft.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/blurrypiano/monster-chat/HEAD/src/assets/img/momleft.png -------------------------------------------------------------------------------- /src/assets/img/caroldown.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/blurrypiano/monster-chat/HEAD/src/assets/img/caroldown.png -------------------------------------------------------------------------------- /src/assets/img/carolleft.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/blurrypiano/monster-chat/HEAD/src/assets/img/carolleft.png -------------------------------------------------------------------------------- /src/assets/img/carolright.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/blurrypiano/monster-chat/HEAD/src/assets/img/carolright.png -------------------------------------------------------------------------------- /src/assets/img/embySprite.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/blurrypiano/monster-chat/HEAD/src/assets/img/embySprite.png -------------------------------------------------------------------------------- /src/assets/img/henrydown.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/blurrypiano/monster-chat/HEAD/src/assets/img/henrydown.png -------------------------------------------------------------------------------- /src/assets/img/henryleft.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/blurrypiano/monster-chat/HEAD/src/assets/img/henryleft.png -------------------------------------------------------------------------------- /src/assets/img/henryright.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/blurrypiano/monster-chat/HEAD/src/assets/img/henryright.png -------------------------------------------------------------------------------- /src/assets/img/joshydown.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/blurrypiano/monster-chat/HEAD/src/assets/img/joshydown.png -------------------------------------------------------------------------------- /src/assets/img/joshyleft.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/blurrypiano/monster-chat/HEAD/src/assets/img/joshyleft.png -------------------------------------------------------------------------------- /src/assets/img/joshyright.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/blurrypiano/monster-chat/HEAD/src/assets/img/joshyright.png -------------------------------------------------------------------------------- /src/assets/img/momright.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/blurrypiano/monster-chat/HEAD/src/assets/img/momright.png -------------------------------------------------------------------------------- /src/assets/img/playerdown.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/blurrypiano/monster-chat/HEAD/src/assets/img/playerdown.png -------------------------------------------------------------------------------- /src/assets/img/playerleft.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/blurrypiano/monster-chat/HEAD/src/assets/img/playerleft.png -------------------------------------------------------------------------------- /src/assets/img/playerup.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/blurrypiano/monster-chat/HEAD/src/assets/img/playerup.png -------------------------------------------------------------------------------- /src/assets/img/townMap400.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/blurrypiano/monster-chat/HEAD/src/assets/img/townMap400.png -------------------------------------------------------------------------------- /src/assets/img/playerright.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/blurrypiano/monster-chat/HEAD/src/assets/img/playerright.png -------------------------------------------------------------------------------- /src/assets/img/draggleSprite.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/blurrypiano/monster-chat/HEAD/src/assets/img/draggleSprite.png -------------------------------------------------------------------------------- /src/assets/img/townBackground/image_part_001.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/blurrypiano/monster-chat/HEAD/src/assets/img/townBackground/image_part_001.png -------------------------------------------------------------------------------- /src/assets/img/townBackground/image_part_002.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/blurrypiano/monster-chat/HEAD/src/assets/img/townBackground/image_part_002.png -------------------------------------------------------------------------------- /src/assets/img/townBackground/image_part_003.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/blurrypiano/monster-chat/HEAD/src/assets/img/townBackground/image_part_003.png -------------------------------------------------------------------------------- /src/assets/img/townBackground/image_part_004.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/blurrypiano/monster-chat/HEAD/src/assets/img/townBackground/image_part_004.png -------------------------------------------------------------------------------- /src/assets/img/townBackground/image_part_005.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/blurrypiano/monster-chat/HEAD/src/assets/img/townBackground/image_part_005.png -------------------------------------------------------------------------------- /src/assets/img/townBackground/image_part_006.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/blurrypiano/monster-chat/HEAD/src/assets/img/townBackground/image_part_006.png -------------------------------------------------------------------------------- /src/assets/img/townBackground/image_part_007.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/blurrypiano/monster-chat/HEAD/src/assets/img/townBackground/image_part_007.png -------------------------------------------------------------------------------- /src/assets/img/townBackground/image_part_008.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/blurrypiano/monster-chat/HEAD/src/assets/img/townBackground/image_part_008.png -------------------------------------------------------------------------------- /src/assets/img/townBackground/image_part_009.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/blurrypiano/monster-chat/HEAD/src/assets/img/townBackground/image_part_009.png -------------------------------------------------------------------------------- /src/assets/img/townBackground/image_part_010.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/blurrypiano/monster-chat/HEAD/src/assets/img/townBackground/image_part_010.png -------------------------------------------------------------------------------- /src/assets/img/townBackground/image_part_011.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/blurrypiano/monster-chat/HEAD/src/assets/img/townBackground/image_part_011.png -------------------------------------------------------------------------------- /src/assets/img/townBackground/image_part_012.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/blurrypiano/monster-chat/HEAD/src/assets/img/townBackground/image_part_012.png -------------------------------------------------------------------------------- /src/assets/img/townBackground/image_part_013.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/blurrypiano/monster-chat/HEAD/src/assets/img/townBackground/image_part_013.png -------------------------------------------------------------------------------- /src/assets/img/townBackground/image_part_014.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/blurrypiano/monster-chat/HEAD/src/assets/img/townBackground/image_part_014.png -------------------------------------------------------------------------------- /src/assets/img/townBackground/image_part_015.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/blurrypiano/monster-chat/HEAD/src/assets/img/townBackground/image_part_015.png -------------------------------------------------------------------------------- /src/assets/img/townBackground/image_part_016.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/blurrypiano/monster-chat/HEAD/src/assets/img/townBackground/image_part_016.png -------------------------------------------------------------------------------- /src/assets/img/townForeground/image_part_001.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/blurrypiano/monster-chat/HEAD/src/assets/img/townForeground/image_part_001.png -------------------------------------------------------------------------------- /src/assets/img/townForeground/image_part_002.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/blurrypiano/monster-chat/HEAD/src/assets/img/townForeground/image_part_002.png -------------------------------------------------------------------------------- /src/assets/img/townForeground/image_part_003.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/blurrypiano/monster-chat/HEAD/src/assets/img/townForeground/image_part_003.png -------------------------------------------------------------------------------- /src/assets/img/townForeground/image_part_004.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/blurrypiano/monster-chat/HEAD/src/assets/img/townForeground/image_part_004.png -------------------------------------------------------------------------------- /src/assets/img/townForeground/image_part_005.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/blurrypiano/monster-chat/HEAD/src/assets/img/townForeground/image_part_005.png -------------------------------------------------------------------------------- /src/assets/img/townForeground/image_part_006.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/blurrypiano/monster-chat/HEAD/src/assets/img/townForeground/image_part_006.png -------------------------------------------------------------------------------- /src/assets/img/townForeground/image_part_007.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/blurrypiano/monster-chat/HEAD/src/assets/img/townForeground/image_part_007.png -------------------------------------------------------------------------------- /src/assets/img/townForeground/image_part_008.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/blurrypiano/monster-chat/HEAD/src/assets/img/townForeground/image_part_008.png -------------------------------------------------------------------------------- /src/assets/img/townForeground/image_part_009.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/blurrypiano/monster-chat/HEAD/src/assets/img/townForeground/image_part_009.png -------------------------------------------------------------------------------- /src/assets/img/townForeground/image_part_010.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/blurrypiano/monster-chat/HEAD/src/assets/img/townForeground/image_part_010.png -------------------------------------------------------------------------------- /src/assets/img/townForeground/image_part_011.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/blurrypiano/monster-chat/HEAD/src/assets/img/townForeground/image_part_011.png -------------------------------------------------------------------------------- /src/assets/img/townForeground/image_part_012.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/blurrypiano/monster-chat/HEAD/src/assets/img/townForeground/image_part_012.png -------------------------------------------------------------------------------- /src/assets/img/townForeground/image_part_013.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/blurrypiano/monster-chat/HEAD/src/assets/img/townForeground/image_part_013.png -------------------------------------------------------------------------------- /src/assets/img/townForeground/image_part_014.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/blurrypiano/monster-chat/HEAD/src/assets/img/townForeground/image_part_014.png -------------------------------------------------------------------------------- /src/assets/img/townForeground/image_part_015.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/blurrypiano/monster-chat/HEAD/src/assets/img/townForeground/image_part_015.png -------------------------------------------------------------------------------- /src/assets/img/townForeground/image_part_016.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/blurrypiano/monster-chat/HEAD/src/assets/img/townForeground/image_part_016.png -------------------------------------------------------------------------------- /src/frontend/engine/comps/CClickable.ts: -------------------------------------------------------------------------------- 1 | export default class CClickable { 2 | public isSelected: boolean = false; 3 | public isDraggable: boolean = false; 4 | } -------------------------------------------------------------------------------- /src/setupTests.ts: -------------------------------------------------------------------------------- 1 | // jest-dom adds custom jest matchers for asserting on DOM nodes. 2 | // allows you to do things like: 3 | // expect(element).toHaveTextContent(/react/i) 4 | // learn more: https://github.com/testing-library/jest-dom 5 | import '@testing-library/jest-dom'; 6 | -------------------------------------------------------------------------------- /src/App.tsx: -------------------------------------------------------------------------------- 1 | import React from 'react'; 2 | import './App.css'; 3 | import Game from './frontend/components/Game'; 4 | 5 | const App = () => { 6 | 7 | return ( 8 |
9 | 10 |
11 | ); 12 | } 13 | 14 | export default App; 15 | -------------------------------------------------------------------------------- /src/backend/models/ConversationModel.ts: -------------------------------------------------------------------------------- 1 | import { IConversationModel, IHistory, IMessageModel } from "../interfaces/IConversationService"; 2 | 3 | export default class ConversationModel implements IConversationModel { 4 | isActive: boolean = false; 5 | history: IHistory[] = []; 6 | messages: IMessageModel[] = []; 7 | } 8 | -------------------------------------------------------------------------------- /src/App.test.tsx: -------------------------------------------------------------------------------- 1 | import React from 'react'; 2 | import { render, screen } from '@testing-library/react'; 3 | import App from './App'; 4 | 5 | test('renders learn react link', () => { 6 | render(); 7 | const linkElement = screen.getByText(/learn react/i); 8 | expect(linkElement).toBeInTheDocument(); 9 | }); 10 | -------------------------------------------------------------------------------- /src/frontend/engine/comps/CGridCollider.ts: -------------------------------------------------------------------------------- 1 | import { IComponent } from "../../infra/Ecs"; 2 | import { Vec2 } from "../../infra/LinAlg"; 3 | 4 | export default class CGridCollider implements IComponent { 5 | // grid pos being in the collider here doesn't make a whole lot of sense 6 | // should be on the sprite or something 7 | public gridPos: Vec2 | null = null; 8 | public nextGridPos: Vec2 | null = null; 9 | } 10 | -------------------------------------------------------------------------------- /src/index.css: -------------------------------------------------------------------------------- 1 | body { 2 | margin: 0; 3 | font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Roboto', 'Oxygen', 4 | 'Ubuntu', 'Cantarell', 'Fira Sans', 'Droid Sans', 'Helvetica Neue', 5 | sans-serif; 6 | -webkit-font-smoothing: antialiased; 7 | -moz-osx-font-smoothing: grayscale; 8 | } 9 | 10 | code { 11 | font-family: source-code-pro, Menlo, Monaco, Consolas, 'Courier New', 12 | monospace; 13 | } 14 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # See https://help.github.com/articles/ignoring-files/ for more about ignoring files. 2 | 3 | # dependencies 4 | /node_modules 5 | /.pnp 6 | .pnp.js 7 | 8 | # testing 9 | /coverage 10 | 11 | # production 12 | /build 13 | 14 | # misc 15 | .DS_Store 16 | .env.local 17 | .env.development.local 18 | .env.test.local 19 | .env.production.local 20 | .apikeys* 21 | 22 | npm-debug.log* 23 | yarn-debug.log* 24 | yarn-error.log* 25 | -------------------------------------------------------------------------------- /src/backend/models/MessageModel.ts: -------------------------------------------------------------------------------- 1 | import { ResponseActionType } from "../interfaces/IConversationService"; 2 | 3 | export default class MessageModel { 4 | 5 | constructor( 6 | public readonly id: number, 7 | public readonly text: string, 8 | public readonly sender: 'me' | 'npc', 9 | public readonly fullText: string, 10 | public readonly errorMessage: string | undefined = undefined, 11 | public readonly action: ResponseActionType | undefined = undefined, 12 | ) { } 13 | } -------------------------------------------------------------------------------- /src/reportWebVitals.ts: -------------------------------------------------------------------------------- 1 | import { ReportHandler } from 'web-vitals'; 2 | 3 | const reportWebVitals = (onPerfEntry?: ReportHandler) => { 4 | if (onPerfEntry && onPerfEntry instanceof Function) { 5 | import('web-vitals').then(({ getCLS, getFID, getFCP, getLCP, getTTFB }) => { 6 | getCLS(onPerfEntry); 7 | getFID(onPerfEntry); 8 | getFCP(onPerfEntry); 9 | getLCP(onPerfEntry); 10 | getTTFB(onPerfEntry); 11 | }); 12 | } 13 | }; 14 | 15 | export default reportWebVitals; 16 | -------------------------------------------------------------------------------- /src/frontend/components/LoadingIndicator.tsx: -------------------------------------------------------------------------------- 1 | import React from 'react'; 2 | import '../styles/components/LoadingIndicator.css'; 3 | 4 | const LoadingIndicator: React.FC = () => { 5 | return ( 6 |
7 | 8 |
Loading...
9 |
10 | ); 11 | } 12 | 13 | export default LoadingIndicator; 14 | 15 | export const LoadingSpinner: React.FC = () => { 16 | return ( 17 |
18 | ) 19 | } -------------------------------------------------------------------------------- /public/manifest.json: -------------------------------------------------------------------------------- 1 | { 2 | "short_name": "React App", 3 | "name": "Create React App Sample", 4 | "icons": [ 5 | { 6 | "src": "favicon.ico", 7 | "sizes": "64x64 32x32 24x24 16x16", 8 | "type": "image/x-icon" 9 | }, 10 | { 11 | "src": "logo192.png", 12 | "type": "image/png", 13 | "sizes": "192x192" 14 | }, 15 | { 16 | "src": "logo512.png", 17 | "type": "image/png", 18 | "sizes": "512x512" 19 | } 20 | ], 21 | "start_url": ".", 22 | "display": "standalone", 23 | "theme_color": "#000000", 24 | "background_color": "#ffffff" 25 | } 26 | -------------------------------------------------------------------------------- /src/index.tsx: -------------------------------------------------------------------------------- 1 | import React from 'react'; 2 | import ReactDOM from 'react-dom/client'; 3 | import './index.css'; 4 | import App from './App'; 5 | import reportWebVitals from './reportWebVitals'; 6 | 7 | const root = ReactDOM.createRoot( 8 | document.getElementById('root') as HTMLElement 9 | ); 10 | root.render( 11 | 12 | 13 | 14 | ); 15 | 16 | // If you want to start measuring performance in your app, pass a function 17 | // to log results (for example: reportWebVitals(console.log)) 18 | // or send to an analytics endpoint. Learn more: https://bit.ly/CRA-vitals 19 | reportWebVitals(); 20 | -------------------------------------------------------------------------------- /tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | "target": "es6", 4 | "lib": [ 5 | "dom", 6 | "dom.iterable", 7 | "esnext" 8 | ], 9 | "allowJs": true, 10 | "skipLibCheck": true, 11 | "esModuleInterop": true, 12 | "allowSyntheticDefaultImports": true, 13 | "strict": true, 14 | "forceConsistentCasingInFileNames": true, 15 | "noFallthroughCasesInSwitch": true, 16 | "module": "esnext", 17 | "moduleResolution": "node", 18 | "resolveJsonModule": true, 19 | "isolatedModules": true, 20 | "noEmit": true, 21 | "jsx": "react-jsx" 22 | }, 23 | "include": [ 24 | "src" 25 | ] 26 | } -------------------------------------------------------------------------------- /src/frontend/styles/components/Game.css: -------------------------------------------------------------------------------- 1 | .canvas-chat-container { 2 | display: flex; 3 | flex: 1; 4 | flex-wrap: wrap; 5 | max-width: 1600px; 6 | border: 1px solid black; 7 | border-width: 4px; 8 | border-radius: 20px; 9 | overflow: hidden; 10 | } 11 | 12 | .canvas-container { 13 | flex: 1 1 50%; /* initial size of 50%, but can shrink if necessary */ 14 | display: flex; 15 | flex-wrap: wrap; 16 | align-items: flex-start; 17 | justify-content: center; 18 | background-color: red; 19 | min-width: 800px; 20 | } 21 | 22 | .chat-container { 23 | flex: 1 0 50%; /* initial size of 50%, but can shrink if necessary */ 24 | background-color: blue; 25 | min-width: 800px; 26 | } -------------------------------------------------------------------------------- /src/frontend/components/GameCanvas.tsx: -------------------------------------------------------------------------------- 1 | import React, { useEffect, useRef } from "react"; 2 | import { Vec2 } from "../infra/LinAlg"; 3 | 4 | interface GameProps { 5 | canvasSize: Vec2; 6 | onCanvasLoaded: (canvas: HTMLCanvasElement) => void; 7 | } 8 | 9 | const GameCanvas: React.FC = (props) => { 10 | 11 | // get canvas and pass to setupGame 12 | const canvasRef = useRef(null); 13 | useEffect(() => { 14 | const canvas = canvasRef.current; 15 | if (canvas) { 16 | props.onCanvasLoaded(canvas); 17 | } 18 | }, []); 19 | 20 | return ( 21 | 22 | ); 23 | }; 24 | export default GameCanvas; 25 | -------------------------------------------------------------------------------- /src/frontend/engine/comps/CTransform.ts: -------------------------------------------------------------------------------- 1 | import { IComponent } from "../../infra/Ecs"; 2 | import { Mat3, Vec2 } from "../../infra/LinAlg"; 3 | 4 | export default class CTransform implements IComponent { 5 | public translation = new Vec2(); 6 | public scale = new Vec2(1, 1); 7 | public rotation: number = 0; 8 | 9 | /** 10 | * 11 | * @returns Matrix corresponding to Translate * R * scale, 12 | */ 13 | public mat3(): Mat3 { 14 | const c = Math.cos(this.rotation); 15 | const s = Math.sin(this.rotation); 16 | 17 | return new Mat3( 18 | this.scale.x * c, -this.scale.y * s, -this.translation.x, 19 | this.scale.x * s, this.scale.y * c, -this.translation.y, 20 | 0, 0, 1 21 | ); 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /src/frontend/engine/comps/CInteractive.ts: -------------------------------------------------------------------------------- 1 | import EcsManager from "../../infra/Ecs"; 2 | import GameContext from "../GameContext"; 3 | 4 | 5 | export type InteractiveAction = Generator; 6 | 7 | // the way this works is on the first interaction, the on interact is 8 | // called, does any initial set up and then returns and interactive action 9 | // InteractiveActions are generators whose next function will be called 10 | // each time the interact button is pressed again. The interaction 11 | // is finished when the generator says it is done (or the interaction is cleared on the game context) 12 | export default class CInteractive { 13 | constructor(public readonly onInteract: (gc: GameContext, ecs: EcsManager, entId: number) => InteractiveAction) { } 14 | } -------------------------------------------------------------------------------- /src/frontend/engine/comps/CBackgroundTile.ts: -------------------------------------------------------------------------------- 1 | import { IComponent } from "../../infra/Ecs"; 2 | 3 | export default class CBackgroundTile implements IComponent { 4 | 5 | // TODO use image loader to manager resources 6 | public img: HTMLImageElement | null = null; 7 | private isLoaded: boolean = false; 8 | 9 | constructor( 10 | public readonly imgPath: string = "", 11 | public readonly width: number = 0, 12 | public readonly height: number = 0, 13 | ) { 14 | this.loadImage(); 15 | } 16 | 17 | public loadImage() { 18 | this.img = new Image(); 19 | this.img.src = this.imgPath; 20 | this.img.onload = () => { 21 | this.isLoaded = true; 22 | } 23 | } 24 | 25 | public isImageLoaded() { 26 | return this.isLoaded; 27 | } 28 | } -------------------------------------------------------------------------------- /src/frontend/engine/comps/CForegroundTile.ts: -------------------------------------------------------------------------------- 1 | import { IComponent } from "../../infra/Ecs"; 2 | 3 | export default class CForegroundTile implements IComponent { 4 | 5 | // TODO use image loader to manager resources 6 | public img: HTMLImageElement | null = null; 7 | private isLoaded: boolean = false; 8 | 9 | constructor( 10 | public readonly imgPath: string = "", 11 | public readonly width: number = 0, 12 | public readonly height: number = 0, 13 | ) { 14 | this.loadImage(); 15 | } 16 | 17 | public loadImage() { 18 | this.img = new Image(); 19 | this.img.src = this.imgPath; 20 | this.img.onload = () => { 21 | this.isLoaded = true; 22 | } 23 | } 24 | 25 | public isImageLoaded() { 26 | return this.isLoaded; 27 | } 28 | } -------------------------------------------------------------------------------- /src/frontend/engine/comps/CAgent.ts: -------------------------------------------------------------------------------- 1 | import { Vec2 } from "../../infra/LinAlg"; 2 | 3 | export type AgentActionType = "standby" | "move"; 4 | 5 | export default class CAgent { 6 | 7 | constructor(public readonly agentId: number) { } 8 | public targetGridPos: Vec2 | null = null; 9 | public movementPath: Vec2[] | null = null; 10 | public movementPathIndex: number = -1; 11 | public currentAction: AgentActionType = "standby"; 12 | 13 | get currentPathPos(): Vec2 | null { 14 | // return null if path is invalid 15 | if (!this.movementPath) return null; 16 | if (this.movementPathIndex === null) return null; 17 | if (this.movementPathIndex < 0) return null; 18 | if (this.movementPathIndex >= this.movementPath.length) return null; 19 | return this.movementPath[this.movementPathIndex]; 20 | } 21 | } -------------------------------------------------------------------------------- /src/frontend/styles/components/LoadingIndicator.css: -------------------------------------------------------------------------------- 1 | .loading-indicator-container { 2 | position: relative; 3 | height: 100%; 4 | } 5 | 6 | .loading-indicator { 7 | position: absolute; 8 | top: 0; 9 | left: 0; 10 | width: 100%; 11 | height: 100%; 12 | background-color: rgba(255, 255, 255, 0.8); 13 | display: flex; 14 | flex-direction: column; 15 | justify-content: center; 16 | align-items: center; 17 | } 18 | 19 | .loading-spinner { 20 | border: 8px solid #f3f3f3; 21 | border-top: 8px solid #7289da; 22 | border-radius: 50%; 23 | width: 40px; 24 | height: 40px; 25 | animation: spin 2s linear infinite; 26 | } 27 | 28 | .loading-text { 29 | font-size: 20px; 30 | margin-top: 10px; 31 | } 32 | 33 | @keyframes spin { 34 | 0% { transform: rotate(0deg); } 35 | 100% { transform: rotate(360deg); } 36 | } -------------------------------------------------------------------------------- /src/backend/repos/NpcRepo.ts: -------------------------------------------------------------------------------- 1 | import npcData from "../data/npcs/NpcData"; 2 | import INpcRepo, { INpcModel } from "../interfaces/INpcRepo"; 3 | 4 | export default class NpcRepo implements INpcRepo { 5 | 6 | public async getById(id: number): Promise { 7 | const index = this.getIndexOf(id); 8 | return npcData[index]!; 9 | } 10 | 11 | public async update(updated: INpcModel): Promise { 12 | const index = this.getIndexOf(updated.id); 13 | if (index < 0) throw new Error(`NpcRepo could not find model with id ${updated.id}`); 14 | npcData[index] = updated; 15 | return updated; 16 | } 17 | 18 | private getIndexOf(npcId: number): number { 19 | const index = npcData.findIndex(npc => npc?.id === npcId); 20 | if (index < 0) throw new Error(`NpcRepo could not find model with id ${npcId}`); 21 | return index; 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /src/frontend/engine/systems/SpriteLocationSystem.ts: -------------------------------------------------------------------------------- 1 | import EcsManager, { EntsWith } from "../../infra/Ecs"; 2 | import CGridCollider from "../comps/CGridCollider"; 3 | import CSprite from "../comps/CSprite"; 4 | import GameContext from "../GameContext"; 5 | 6 | type CompOrder = [CSprite, CGridCollider]; 7 | const constructors = [CSprite, CGridCollider]; 8 | 9 | export default class SpriteLocationSystem { 10 | 11 | public run(gc: GameContext, ecs: EcsManager): void { 12 | 13 | gc.spriteLookup.clear(); 14 | const ents: EntsWith = ecs.getEntsWith(...constructors); 15 | 16 | // put any sprites into the lookup map 17 | for (const [eid, [, collider]] of ents) { 18 | if (!collider.gridPos) continue; 19 | var hash = collider.gridPos.toString(); 20 | 21 | if (gc.spriteLookup.has(hash)) { 22 | var entIdList = gc.spriteLookup.get(hash)!; 23 | entIdList.push(eid); 24 | } else { 25 | gc.spriteLookup.set(hash, [eid]); 26 | } 27 | } 28 | } 29 | } -------------------------------------------------------------------------------- /src/backend/services/LocationService.ts: -------------------------------------------------------------------------------- 1 | import { ITileLayer } from "../../frontend/engine/systems/GridMovementSystem"; 2 | import { Vec2 } from "../../frontend/infra/LinAlg"; 3 | import { ILocationContextInfo } from "../data/locationData"; 4 | 5 | export default class LocationService { 6 | 7 | private _lookup: Map = new Map(); 8 | 9 | constructor(public locationContext: { [key: number]: ILocationContextInfo }, tileLayer: ITileLayer) { 10 | 11 | // build look up map to get location context 12 | for (var i = 0; i < tileLayer.width; i++) { 13 | for (var j = 0; j < tileLayer.height; j++) { 14 | const value = tileLayer.data[i * tileLayer.width + j]; 15 | if (value > 0 && locationContext[value]) { 16 | var gridPos = new Vec2(j, i); 17 | this._lookup.set(gridPos.toString(), locationContext[value]); 18 | } 19 | } 20 | } 21 | } 22 | 23 | public lookup(pos: Vec2): ILocationContextInfo | null { 24 | return this._lookup.get(pos.toString()) || null; 25 | } 26 | } -------------------------------------------------------------------------------- /src/frontend/engine/systems/rendering/BackgroundRenderSystem.ts: -------------------------------------------------------------------------------- 1 | import { ISystem } from "../../../infra/Ecs"; 2 | import { Vec3 } from "../../../infra/LinAlg"; 3 | import CBackgroundTile from "../../comps/CBackgroundTile"; 4 | import CTransform from "../../comps/CTransform"; 5 | import GameContext from "../../GameContext"; 6 | 7 | type ComponentOrder = [CTransform, CBackgroundTile]; 8 | 9 | export default class BackgroundRenderSystem implements ISystem { 10 | 11 | public run(gc: GameContext, ents: IterableIterator<[number, ComponentOrder]>): void { 12 | 13 | for (const [, [transform, background]] of ents) { 14 | const pos = gc.viewTransform.mulVec(new Vec3(transform.translation.x, transform.translation.y, 1)); 15 | if (pos.x + background.width < 0) continue; 16 | if (pos.x > gc.canvas.width) continue; 17 | if (pos.y + background.height < 0) continue; 18 | if (pos.y > gc.canvas.height) continue; 19 | 20 | if (background.isImageLoaded()) { 21 | gc.canvasCtx.drawImage(background.img!, pos.x, pos.y); 22 | } 23 | } 24 | } 25 | } -------------------------------------------------------------------------------- /src/frontend/engine/systems/rendering/ForegroundRenderSystem.ts: -------------------------------------------------------------------------------- 1 | import { ISystem } from "../../../infra/Ecs"; 2 | import { Vec3 } from "../../../infra/LinAlg"; 3 | import CForegroundTile from "../../comps/CForegroundTile"; 4 | import CTransform from "../../comps/CTransform"; 5 | import GameContext from "../../GameContext"; 6 | 7 | type ComponentOrder = [CTransform, CForegroundTile]; 8 | 9 | export default class ForegroundRenderSystem implements ISystem { 10 | 11 | public run(gc: GameContext, ents: IterableIterator<[number, ComponentOrder]>): void { 12 | 13 | for (const [, [transform, foreground]] of ents) { 14 | const pos = gc.viewTransform.mulVec(new Vec3(transform.translation.x, transform.translation.y, 1)); 15 | if (pos.x + foreground.width < 0) continue; 16 | if (pos.x > gc.canvas.width) continue; 17 | if (pos.y + foreground.height < 0) continue; 18 | if (pos.y > gc.canvas.height) continue; 19 | 20 | if (foreground.isImageLoaded()) { 21 | gc.canvasCtx.drawImage(foreground.img!, pos.x, pos.y); 22 | } 23 | } 24 | } 25 | } -------------------------------------------------------------------------------- /LICENSE.md: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2023 Brendan Galea 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /src/frontend/infra/BoundedBox.ts: -------------------------------------------------------------------------------- 1 | import CSprite from "../engine/comps/CSprite"; 2 | import CTransform from "../engine/comps/CTransform"; 3 | import { Vec2 } from "./LinAlg" 4 | 5 | export default class BoundedBox { 6 | 7 | public readonly bottomRight: Vec2 8 | constructor( 9 | public readonly x: number, 10 | public readonly y: number, 11 | public readonly w: number, 12 | public readonly h: number 13 | ) { 14 | this.bottomRight = new Vec2(x + w, y + h); 15 | } 16 | 17 | public contains(x: number, y: number): boolean { 18 | return x > this.x && x < this.bottomRight.x 19 | && y > this.y && y < this.bottomRight.y; 20 | } 21 | 22 | public equals(other: BoundedBox): boolean { 23 | return ( 24 | this.x === other.x && 25 | this.y === other.y && 26 | this.w === other.w && 27 | this.h === other.h 28 | ); 29 | } 30 | 31 | static forSpriteTransform(sprite: CSprite, transform: CTransform): BoundedBox { 32 | return new BoundedBox( 33 | transform.translation.x, 34 | transform.translation.y, 35 | sprite.width, 36 | sprite.height, 37 | ); 38 | } 39 | 40 | } -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "gpet-client", 3 | "version": "0.1.0", 4 | "private": true, 5 | "dependencies": { 6 | "@testing-library/jest-dom": "^5.14.1", 7 | "@testing-library/react": "^13.0.0", 8 | "@testing-library/user-event": "^13.2.1", 9 | "@types/jest": "^27.0.1", 10 | "@types/node": "^16.7.13", 11 | "@types/react": "^18.0.0", 12 | "@types/react-dom": "^18.0.0", 13 | "axios": "^1.3.4", 14 | "react": "^18.2.0", 15 | "react-dom": "^18.2.0", 16 | "react-scripts": "5.0.1", 17 | "swr": "^2.1.1", 18 | "typescript": "^4.4.2", 19 | "web-vitals": "^2.1.0" 20 | }, 21 | "scripts": { 22 | "start": "react-scripts start", 23 | "build": "react-scripts build", 24 | "test": "react-scripts test", 25 | "eject": "react-scripts eject" 26 | }, 27 | "eslintConfig": { 28 | "extends": [ 29 | "react-app", 30 | "react-app/jest" 31 | ] 32 | }, 33 | "browserslist": { 34 | "production": [ 35 | ">0.2%", 36 | "not dead", 37 | "not op_mini all" 38 | ], 39 | "development": [ 40 | "last 1 chrome version", 41 | "last 1 firefox version", 42 | "last 1 safari version" 43 | ] 44 | }, 45 | "devDependencies": {} 46 | } 47 | -------------------------------------------------------------------------------- /src/frontend/engine/systems/MousePickerSystem.ts: -------------------------------------------------------------------------------- 1 | import BoundedBox from "../../infra/BoundedBox"; 2 | import EcsManager, { EntsWith } from "../../infra/Ecs"; 3 | import { Vec2 } from "../../infra/LinAlg"; 4 | import CClickable from "../comps/CClickable"; 5 | import CSprite from "../comps/CSprite"; 6 | import CTransform from "../comps/CTransform"; 7 | import GameContext from "../GameContext"; 8 | 9 | type CompOrder = [CSprite, CClickable, CTransform]; 10 | const constructors = [CSprite, CClickable, CTransform]; 11 | 12 | export default class MousePickerSystem { 13 | 14 | public run(gc: GameContext, ecs: EcsManager): void { 15 | 16 | const invViewTranslation = new Vec2(-1 * gc.viewTransform.m13, -1 * gc.viewTransform.m23); 17 | const clickWorldSpace = gc.mouse.lastClick?.add(invViewTranslation); 18 | gc.mouse.clearLastClick(); 19 | 20 | const ents: EntsWith = ecs.getEntsWith(...constructors); 21 | 22 | if (!clickWorldSpace) return; 23 | 24 | // get clickable sprites 25 | for (const [eid, [sprite, clickable, transform]] of ents) { 26 | const bb = BoundedBox.forSpriteTransform(sprite, transform); 27 | if (bb.contains(clickWorldSpace.x, clickWorldSpace.y)) { 28 | clickable.isSelected = true; 29 | console.log(eid, ecs.debugEnt(eid)); 30 | } else { 31 | clickable.isSelected = false; 32 | } 33 | } 34 | } 35 | } -------------------------------------------------------------------------------- /src/GptTest.tsx: -------------------------------------------------------------------------------- 1 | import React, { useState } from 'react'; 2 | import { postChatGpt, useChat } from './Api'; 3 | 4 | const GptTest = () => { 5 | const [question, setQuestion] = useState(''); 6 | const [submittedQuestion, setSubmittedQuestion] = useState(''); 7 | 8 | const response = useChat(submittedQuestion); 9 | 10 | const handleQuestionChange = (event: any) => { 11 | setQuestion(event.target.value); 12 | } 13 | 14 | const handleSubmit = (event: any) => { 15 | event.preventDefault(); 16 | // Do something with the question and response 17 | console.log(`Question: ${submittedQuestion}\nResponse: `); 18 | console.log(response); 19 | 20 | // setSubmittedQuestion(question); 21 | // postChatGpt(question); 22 | } 23 | 24 | const handleClear = (event: any) => { 25 | // Clear the form 26 | setQuestion(''); 27 | } 28 | 29 | return ( 30 |
31 | 35 |
36 |