Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature | Parkor GameScript #46

Draft
wants to merge 10 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions .zed/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
// Folder-specific settings
//
// For a full list of overridable settings, and general information on folder-specific settings,
// see the documentation: https://zed.dev/docs/configuring-zed#settings-files
{
"rust-analyzer": {
"linkedProjects": ["./lib/world/Cargo.toml"]
}
}
34 changes: 34 additions & 0 deletions Events.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@

The game has many scripts. The scripts control entities in the game.

Scripts have a list of actions that can be taken on them. These actions can be serilaized and sent over a server.
Example
(entityId, action, data) = ("player1", "move", "left")

You can query a player for all of its actions

Script data is not serilaized

Example Scripts
JumpScript,
MoveScript,
GravityScript,



Flow of events for user pressing space:
- JS creates a jump event
- Jump event sent over the wire (either to server or worker)
- Game recieves jump events and finds script for it
- Script looks up the event and executes it



Player Places block:
- Js creates a place block event
- Sent over wire
- Game recieves place block event and finds script for it
- Script looks up the event and executes it
- Chunks have been updateds so JS game scripts are called


10 changes: 4 additions & 6 deletions apps/web-client/index.html
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<head>
<title> TylerCraft </title>
<meta
name='viewport'
<meta
name='viewport'
content='width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0'
>
<link rel="stylesheet" type="text/css" href="app.css" />
Expand All @@ -13,7 +13,7 @@
<div id="loadingScreen" class="hidden">
<div>
<p id="loadingScreenMsg"></p>
<img src="./img/loading.gif"/>
<img alt="loading" src="./img/loading.gif"/>
</div>
</div>
<div id="startMenu">
Expand Down Expand Up @@ -78,8 +78,6 @@ <h3 id="subtitle"> A 3D sandbox by Tyler Tracy</h3>
<div class="toolbelt-item" id="toolbelt-item-9"></div>
</div>



<div id="healthBarOutline">
<div id="healthBar"></div>
</div>
Expand All @@ -96,5 +94,5 @@ <h3 id="subtitle"> A 3D sandbox by Tyler Tracy</h3>
</div>
</div>
</div>
<script type="module" src="/src/app.ts"></script>
<script type="module" src="/src/runner.ts"></script>
</body>
56 changes: 3 additions & 53 deletions apps/web-client/src/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,76 +3,26 @@
*/
import * as Engine from "@craft/engine";
console.log("Engine", Engine);
import {
camelCaseToNormalCase,
CONFIG,
Game,
IGameMetadata,
} from "@craft/engine";
import { camelCaseToNormalCase, CONFIG } from "@craft/engine";
import { SocketHandler } from "./socket";
import { renderWorldPicker } from "./world-picker";
import { createRoot } from "react-dom/client";
import { ClientDbGamesService } from "./services/sp-games-service";
import { NetworkGamesService } from "./services/mp-games-service";
import { BasicGScript } from "./game-scripts/basic-gscript";
import { hideElement, showElement } from "./utils";

// Add the world to this too
export interface IExtendedWindow extends Window {
game?: Game;
}

// Loading the engine
await Engine.WorldModule.load();

export const IS_MOBILE = /Mobi/.test(window.navigator.userAgent);
console.log("Is Mobile: ", IS_MOBILE);

// helper functions
function showElement(e: HTMLElement) {
e.classList.remove("hidden");
e.classList.add("shown");
}

function hideElement(e: HTMLElement) {
e.classList.add("hidden");
e.classList.remove("shown");
}

function getElementByIdOrThrow(id: string): HTMLElement {
const e = document.getElementById(id);
if (!e) {
throw new Error(`Element with id ${id} not found`);
}
return e;
}

// generate your unique id
// kind of bad to do this client side, but I can make it better later
const UID_KEY = "tylercraft-uid";
if (!localStorage.getItem(UID_KEY)) {
localStorage.setItem(UID_KEY, Math.random() + "");
}

export function getMyUid() {
const uid = localStorage.getItem(UID_KEY);
if (!uid) throw new Error("UID not defined");
return uid;
}

// Get all of the elements
const ePlayLocalButton = getElementByIdOrThrow("playLocalButton");
const ePlayOnlineButton = getElementByIdOrThrow("playOnlineButton");
export const eStartMenu = getElementByIdOrThrow("startMenu");
const eGameTypeScreen = getElementByIdOrThrow("pickGameTypeScreen");
export const ePickWorldScreen = getElementByIdOrThrow("pickWorldScreen");
const eBackButton = getElementByIdOrThrow("backButton");
const eWorldOptionsScreen = getElementByIdOrThrow("worldOptionsScreen");
const eConfigForm = getElementByIdOrThrow("configForm") as HTMLFormElement;
const eConfigFormExtra = getElementByIdOrThrow("configFormExtra");
const eConfigFormStartButton = getElementByIdOrThrow(
"configFormStartButton"
) as HTMLButtonElement;
const eLoadingScreen = getElementByIdOrThrow("loadingScreen");
const eLoadingScreenMsg = getElementByIdOrThrow("loadingScreenMsg");

const LoadingScreen = {
show: (msg: string) => {
Expand Down
73 changes: 0 additions & 73 deletions apps/web-client/src/cameras/entityCamera.ts

This file was deleted.

Loading
Loading