Skip to content
Merged
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
15 changes: 0 additions & 15 deletions client/src/components/AdminIconButton.tsx

This file was deleted.

62 changes: 0 additions & 62 deletions client/src/components/AdminView.tsx

This file was deleted.

20 changes: 5 additions & 15 deletions client/src/components/PageContainer.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { ReactNode, useContext, useState } from "react";
import { ReactNode, useContext } from "react";

// components
import { AdminView, AdminIconButton, Loading } from "@/components";
import { Loading } from "@/components";

// context
import { GlobalStateContext } from "@context/GlobalContext";
Expand All @@ -15,29 +15,19 @@ export const PageContainer = ({
isLoading: boolean;
headerText?: string;
}) => {
const { error, isAdmin } = useContext(GlobalStateContext);
const [showSettings, setShowSettings] = useState(false);
const { error } = useContext(GlobalStateContext);

if (isLoading) return <Loading />;

return (
<div className="p-4 mb-28">
{isAdmin && (
<AdminIconButton setShowSettings={() => setShowSettings(!showSettings)} showSettings={showSettings} />
)}
{headerText && (
<div className="pb-6">
<h2>{headerText}</h2>
</div>
)}
{showSettings ? (
<AdminView />
) : (
<>
{children}
{error && <p className="p3 pt-10 text-center text-error">{error}</p>}
</>
)}
{children}
{error && <p className="p3 pt-10 text-center text-error">{error}</p>}
</div>
);
};
Expand Down
2 changes: 0 additions & 2 deletions client/src/components/index.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
export * from "./ActionIcon.js";
export * from "./ActionIconsContainer.js";
export * from "./AdminView.js";
export * from "./AdminIconButton.js";
export * from "./ConfirmationModal.js";
export * from "./CreatePet.js";
export * from "./PetColors.js";
Expand Down
1 change: 0 additions & 1 deletion client/src/context/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import { defaultPetStatus } from "@/constants";

export const initialState = {
error: "",
isAdmin: false,
isPetOwner: false,
petStatus: defaultPetStatus,
hasInteractiveParams: false,
Expand Down
7 changes: 0 additions & 7 deletions client/src/context/reducer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import {
SET_HAS_SETUP_BACKEND,
SET_INTERACTIVE_PARAMS,
SET_KEY_ASSET_ID,
SET_IS_ADMIN,
SET_SELECTED_PET,
} from "./types";

Expand All @@ -24,12 +23,6 @@ const globalReducer = (state: InitialStateType, action: ActionType) => {
...payload,
hasSetupBackend: true,
};
case SET_IS_ADMIN:
return {
...state,
isAdmin: action.payload.isAdmin,
error: "",
};
case SET_GAME_STATE:
return {
...state,
Expand Down
2 changes: 0 additions & 2 deletions client/src/context/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import { BadgesType, PetStatusType, VisitorInventoryType } from "../../../shared

export const SET_HAS_SETUP_BACKEND = "SET_HAS_SETUP_BACKEND";
export const SET_INTERACTIVE_PARAMS = "SET_INTERACTIVE_PARAMS";
export const SET_IS_ADMIN = "SET_IS_ADMIN";
export const SET_GAME_STATE = "SET_GAME_STATE";
export const SET_ERROR = "SET_ERROR";
export const SET_KEY_ASSET_ID = "SET_KEY_ASSET_ID";
Expand All @@ -24,7 +23,6 @@ export type InteractiveParams = {

export interface InitialStateType {
keyAssetId?: string;
isAdmin?: boolean;
isPetOwner?: boolean;
petStatus?: PetStatusType;
error?: string;
Expand Down
7 changes: 0 additions & 7 deletions client/src/pages/Home.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import { GlobalDispatchContext, GlobalStateContext } from "@/context/GlobalConte

// utils
import { backendAPI, setErrorMessage, setGameState } from "@/utils";
import { SET_IS_ADMIN } from "@/context/types";

const Home = ({ isSpawnedDroppedAsset }: { isSpawnedDroppedAsset: boolean }) => {
const dispatch = useContext(GlobalDispatchContext);
Expand All @@ -31,12 +30,6 @@ const Home = ({ isSpawnedDroppedAsset }: { isSpawnedDroppedAsset: boolean }) =>
response = await backendAPI.get("/pet");
}
setGameState(dispatch, response.data);
dispatch!({
type: SET_IS_ADMIN,
payload: {
isAdmin: response.data.isAdmin,
},
});
} catch (error) {
if (error instanceof Error) {
setErrorMessage(dispatch, error.message);
Expand Down
2 changes: 1 addition & 1 deletion client/src/utils/setGameState.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { PetStatusType } from "../../../shared/types.js";

export const setGameState = (
dispatch: Dispatch<ActionType> | null,
gameState: { isPetOwner: boolean; petStatus: PetStatusType; isAdmin: boolean },
gameState: { isPetOwner: boolean; petStatus: PetStatusType },
) => {
if (!dispatch || !setGameState) return;

Expand Down
15 changes: 7 additions & 8 deletions client/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"skipLibCheck": true,

/* Bundler mode */
"moduleResolution": "node",
"moduleResolution": "bundler",
"allowImportingTsExtensions": true,
"allowSyntheticDefaultImports": true,
"resolveJsonModule": true,
Expand All @@ -21,14 +21,13 @@
"noUnusedParameters": true,
"noFallthroughCasesInSwitch": true,

"baseUrl": ".", // Required for path mapping
"paths": {
"@/*": ["src/*"],
"@assets/*": ["src/assets/*"],
"@components/*": ["src/components/*"],
"@context/*": ["src/context/*"],
"@pages/*": ["src/pages/*"],
"@utils/*": ["src/utils/*"],
"@/*": ["./src/*"],
"@assets/*": ["./src/assets/*"],
"@components/*": ["./src/components/*"],
"@context/*": ["./src/context/*"],
"@pages/*": ["./src/pages/*"],
"@utils/*": ["./src/utils/*"],
"@shared/*": ["../shared/*"]
}
},
Expand Down
10 changes: 1 addition & 9 deletions server/controllers/handleGetGameState.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,5 @@
import { Request, Response } from "express";
import {
errorHandler,
getCachedInventoryItems,
getCredentials,
getVisitorAndPetStatus,
removeDroppedAssets,
} from "../utils/index.js";
import { errorHandler, getCachedInventoryItems, getCredentials, getVisitorAndPetStatus } from "../utils/index.js";
import { BadgesType } from "../../shared/types.js";

export const handleGetGameState = async (req: Request, res: Response) => {
Expand Down Expand Up @@ -34,8 +28,6 @@ export const handleGetGameState = async (req: Request, res: Response) => {
}
}

await removeDroppedAssets(credentials);

return res.json({
isAdmin,
pets,
Expand Down
24 changes: 0 additions & 24 deletions server/controllers/handleGetKeyAsset.ts

This file was deleted.

3 changes: 0 additions & 3 deletions server/controllers/handleGetPet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import {
errorHandler,
getCredentials,
getVisitorAndPetStatus,
removeDroppedAssets,
spawnPetNpc,
User,
} from "../utils/index.js";
Expand Down Expand Up @@ -67,8 +66,6 @@ export const handleGetPet = async (req: Request, res: Response): Promise<Record<
}
}

await removeDroppedAssets(credentials, `petSystem-${credentials.username}`);

return res.json({
petStatus,
isPetOwner,
Expand Down
30 changes: 0 additions & 30 deletions server/controllers/handleRemoveAllPets.ts

This file was deleted.

4 changes: 3 additions & 1 deletion server/controllers/handleTradePet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,9 @@ export const handleTradePet = async (req: Request, res: Response): Promise<Recor
const petStatus = pets ? pets[selectedPetId] : null;
if (!petStatus) throw new Error("No pet status found for visitor");

await visitor.deleteNpc();
// Only despawn the in-world NPC if the pet being traded is the one currently spawned.
// Otherwise we'd kick out an unrelated pet (e.g. trading Pet B while Pet A is in world).
if (petStatus.isPetInWorld) await visitor.deleteNpc();

delete pets[selectedPetId];

Expand Down
2 changes: 0 additions & 2 deletions server/controllers/index.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
export * from "./handleCreatePet.js";
export * from "./handleExecuteAction.js";
export * from "./handleGetGameState.js";
export * from "./handleGetKeyAsset.js";
export * from "./handleGetPet.js";
export * from "./handlePickupPet.js";
export * from "./handleSpawnPet.js";
export * from "./handleTradePet.js";
export * from "./handleUpdatePet.js";
export * from "./handleRemoveAllPets.js";
4 changes: 0 additions & 4 deletions server/routes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,8 @@ import {
handleCreatePet,
handleExecuteAction,
handleGetGameState,
handleGetKeyAsset,
handleGetPet,
handlePickupPet,
handleRemoveAllPets,
handleSpawnPet,
handleTradePet,
handleUpdatePet,
Expand Down Expand Up @@ -34,7 +32,6 @@ router.get("/system/health", (req, res) => {
});
});

router.get("/key-asset", handleGetKeyAsset);
router.get("/game-state", handleGetGameState);
router.get("/pet", handleGetPet);
router.post("/create-pet", handleCreatePet);
Expand All @@ -43,6 +40,5 @@ router.post("/trade-pet", handleTradePet);
router.post("/spawn-pet", handleSpawnPet);
router.post("/pickup-pet", handlePickupPet);
router.post("/execute-action", handleExecuteAction);
router.post("/remove-dropped-assets", handleRemoveAllPets);

export default router;
4 changes: 3 additions & 1 deletion server/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
/* Modules */
"module": "ESNext" /* Specify what module code is generated. */,
// "rootDir": "./", /* Specify the root folder within your source files. */
"moduleResolution": "Node" /* Specify how TypeScript looks up a file from a given module specifier. */,
"moduleResolution": "bundler" /* Specify how TypeScript looks up a file from a given module specifier. */,
// "baseUrl": "./", /* Specify the base directory to resolve non-relative module names. */
// "paths": {}, /* Specify a set of entries that re-map imports to additional lookup locations. */
// "rootDirs": [], /* Allow multiple folders to be treated as one when resolving modules. */
Expand Down Expand Up @@ -56,6 +56,8 @@
// "inlineSourceMap": true, /* Include sourcemap files inside the emitted JavaScript. */
// "outFile": "./", /* Specify a file that bundles all outputs into one JavaScript file. If 'declaration' is true, also designates a file that bundles all .d.ts output. */
"outDir": "./dist" /* Specify an output folder for all emitted files. */,
"rootDir": ".." /* Explicitly set the root directory to resolve common source directory error. */,

// "removeComments": true, /* Disable emitting comments. */
// "noEmit": true, /* Disable emitting files from a compilation. */
// "importHelpers": true, /* Allow importing helper functions from tslib once per project, instead of including them per-file. */
Expand Down
Loading
Loading