Skip to content

Commit

Permalink
Merge branch 'dev'
Browse files Browse the repository at this point in the history
  • Loading branch information
n4mr3g committed May 3, 2024
2 parents 7513e56 + 885ed09 commit 983c174
Show file tree
Hide file tree
Showing 121 changed files with 16,635 additions and 8,978 deletions.
8 changes: 8 additions & 0 deletions .env
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# THESE ARE PUBLIC ENVIRONMENT VARIABLES AND SHOULD BE COMMITED

NEXT_PUBLIC_CLERK_SIGN_IN_URL="/sign-in"
NEXT_PUBLIC_CLERK_SIGN_UP_URL="/sign-up"
NEXT_PUBLIC_CLERK_AFTER_SIGN_IN_URL="/"
NEXT_PUBLIC_CLERK_AFTER_SIGN_UP_URL="/"

NEXT_PUBLIC_CLERK_PUBLISHABLE_KEY="pk_test_ZGlzY3JldGUtcGFudGhlci0xNS5jbGVyay5hY2NvdW50cy5kZXYk"
5 changes: 5 additions & 0 deletions .env.local.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
CLERK_SECRET_KEY=
NEXT_PUBLIC_SERVER_URL=http://0.0.0.0:3000
MONGODB_URI=
DB_NAME="project_holodeck"
OPENAI_API_KEY=
10 changes: 10 additions & 0 deletions .eslintrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"extends": [
// "eslint:recommended",
"next",
"prettier",
"plugin:jest-dom/recommended",
"plugin:testing-library/react"
],
"rules": {}
}
39 changes: 33 additions & 6 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,15 +1,42 @@
# See https://help.github.com/articles/ignoring-files/ for more about ignoring files.

.env*
# dependencies
/node_modules
/.pnp
.pnp.js

# testing
/coverage

# next.js
/.next/
/out/

# production
/build

# misc
.DS_Store
*.pem

# debug
npm-debug.log*
yarn-debug.log*
yarn-error.log*

# local env files
.env*.local
.flaskenv*
!.env.project
!.env.vault
/.vscode

# vercel
.vercel

# dependencies
*/node_modules/*
/.pnp
.pnp.js
# typescript
*.tsbuildinfo
next-env.d.ts

# vscode
.vscode/*
/.vscode
6 changes: 6 additions & 0 deletions .prettierrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"plugins": ["prettier-plugin-tailwindcss"],
"singleQuote": true,
"trailingComma": "all",
"arrowParens": "avoid"
}
34 changes: 33 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,34 @@
# project-holodeck
This is a [Next.js](https://nextjs.org/) project bootstrapped with [`create-next-app`](https://github.com/vercel/next.js/tree/canary/packages/create-next-app).

## Getting Started

First, run the development server:

```bash
npm run dev
# or
yarn dev
# or
pnpm dev
```

Open [http://localhost:3000](http://localhost:3000) with your browser to see the result.

You can start editing the page by modifying `app/page.tsx`. The page auto-updates as you edit the file.

This project uses [`next/font`](https://nextjs.org/docs/basic-features/font-optimization) to automatically optimize and load Inter, a custom Google Font.

## Learn More

To learn more about Next.js, take a look at the following resources:

- [Next.js Documentation](https://nextjs.org/docs) - learn about Next.js features and API.
- [Learn Next.js](https://nextjs.org/learn) - an interactive Next.js tutorial.

You can check out [the Next.js GitHub repository](https://github.com/vercel/next.js/) - your feedback and contributions are welcome!

## Deploy on Vercel

The easiest way to deploy your Next.js app is to use the [Vercel Platform](https://vercel.com/new?utm_medium=default-template&filter=next.js&utm_source=create-next-app&utm_campaign=create-next-app-readme) from the creators of Next.js.

Check out our [Next.js deployment documentation](https://nextjs.org/docs/deployment) for more details.
92 changes: 0 additions & 92 deletions Untitled-1.js

This file was deleted.

File renamed without changes.
19 changes: 5 additions & 14 deletions client/pages/about.tsx → app/about/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,38 +8,29 @@ export default function About() {
interactive text-based games. These games are created using a
combination of artificial intelligence and human creativity.
</p>
<p>
This is my solo project for the{" "}
<a href="https://codeworks.me/" target="_blank">
Codeworks
</a>{" "}
bootcamp for full-stack software engineering. I built it using NextJS,
TypeScript, Node.js, Express, and MongoDB.
</p>

<p>
The name is inspired by the holodeck from Star Trek: The Next
Generation. The holodeck is a virtual reality facility that allows
users to interact with a simulated environment and its inhabitants.
</p>

<p>
I hope you enjoy it. If you have any questions, comments, or
suggestions, feel free to{" "}
suggestions, feel free to{' '}
<a href="mailto:[email protected]">send me an email</a>.
</p>
<p>
You can also check out{" "}
You can also check out{' '}
<a href="https://github.com/n4mr3g" target="_blank">
my GitHub
</a>{" "}
or{" "}
</a>{' '}
or{' '}
<a
href="https://www.linkedin.com/in/german-piccioni/"
target="_blank"
>
my LinkedIn
</a>{" "}
</a>{' '}
profiles.
</p>
</div>
Expand Down
24 changes: 24 additions & 0 deletions app/api/combat/[slug]/route.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import { resolveCombat } from '@/lib/game-logic/resolve-combat';
import { auth } from '@clerk/nextjs';
import { NextRequest } from 'next/server';

export async function POST(
req: NextRequest,
{ params }: { params: { slug: string } },
) {
const { userId }: { userId: string | null } = auth();

if (!userId) {
return new Response('Unauthorized', { status: 401 });
}

let itemOrMagicId: string | null = null;

if (req.headers.has('itemOrMagicId')) {
itemOrMagicId = req.headers.get('itemOrMagicId');
}

const combatResult = await resolveCombat(userId, params.slug, itemOrMagicId);

return new Response(JSON.stringify(combatResult), { status: 200 });
}
17 changes: 17 additions & 0 deletions app/api/encounter/route.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
// import { getEncounter } from '@/controllers/encounter.controller';
// import { auth } from '@clerk/nextjs';

// export async function GET() {
// const { userId }: { userId: string | null } = auth();
// if (!userId) {
// return new Response('Unauthorized', { status: 401 });
// }

// // this will create an encounter if one doesn't exist
// const encounter = await getEncounter(userId);
// // const player = await getPlayer(userId);

// return encounter
// ? new Response(JSON.stringify(encounter), { status: 200 })
// : new Response('Not found', { status: 404 });
// }
47 changes: 47 additions & 0 deletions app/api/openai/route.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
//! This was moved from pages/api/openai.ts. Needs review.

import { OpenAIStream, StreamingTextResponse } from 'ai';
import { Configuration, OpenAIApi } from 'openai-edge';

// Create an OpenAI API client (that's edge friendly!)
const config = new Configuration({
apiKey: process.env.OPENAI_API_KEY,
});
const openai = new OpenAIApi(config);

// IMPORTANT! Set the runtime to edge
export const runtime = 'edge';

export default async function POST(req: Request) {
// Extract the `messages` from the body of the request
const { messages } = await req.json();

// Ask OpenAI for a streaming chat completion given the prompt
const response = await openai.createChatCompletion({
model: 'gpt-3.5-turbo-16k',
stream: true,
max_tokens: 900,
temperature: 0.9,
messages,
});
// Convert the response into a friendly text-stream
const stream = OpenAIStream(response, {
onStart: async () => {
// This callback is called when the stream starts
// You can use this to save the prompt to your database
await savePromptToDatabase(messages);
},
onToken: async (token: string) => {
// This callback is called for each token in the stream
// You can use this to debug the stream or save the tokens to your database
console.log(token);
},
onCompletion: async (completion: string) => {
// This callback is called when the stream completes
// You can use this to save the final completion to your database
await saveCompletionToDatabase(completion);
},
});
// Respond with the stream
return new StreamingTextResponse(stream);
}
43 changes: 43 additions & 0 deletions app/api/players/route.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
// `server-only` guarantees any modules that import code in file will never run
// on the client. It's good practice to add `server-only` preemptively.
import 'server-only';

import { NextResponse, NextRequest } from 'next/server';
import { auth } from '@clerk/nextjs';
import { PlayerState } from '@/types/Player';
import {
getPlayerIfExists,
createPlayer,
} from '@/controllers/player.controller';

export async function GET() {
try {
const { userId }: { userId: string | null } = auth();
if (!userId) {
return new Response('Unauthorized', { status: 401 });
}

const player = await getPlayerIfExists(userId);

return NextResponse.json(player);
} catch (error) {
return new NextResponse('Not found', { status: 404 });
}
}

export async function POST(req: NextRequest) {
const { userId }: { userId: string | null } = auth();
if (!userId) {
return new Response('Unauthorized', { status: 401 });
}

// idk yet how to use this but I might need it later:
// const token = await getToken({template: ''})

const playerData = (await req.json()) as PlayerState;
// TODO: this may not be secure; player could cheat by sending a modified player object?

const newPlayer = await createPlayer(userId, playerData);

return NextResponse.json({ newPlayer });
}
Loading

0 comments on commit 983c174

Please sign in to comment.