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
21 changes: 10 additions & 11 deletions src/controllers/handleDropPiece.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import { Request, Response } from "express";
import {
dropWebImageAsset,
errorHandler,
getCredentials,
getDroppedAssetDataObject,
getGameStatus,
lockDataObject,
Expand Down Expand Up @@ -47,16 +46,16 @@ export const handleDropPiece = async (req: Request, res: Response) => {
column === 0
? 0
: column === 1
? 6
: column === 2
? 12
: column === 3
? 18
: column === 4
? 24
: column === 5
? 30
: 36;
? 6
: column === 2
? 12
: column === 3
? 18
: column === 4
? 24
: column === 5
? 30
: 36;
const claimedSpace = columnStart + columns[column].length;

const updatedData = {
Expand Down
2 changes: 1 addition & 1 deletion src/controllers/handlePlayerSelection.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Request, Response } from "express";
import { errorHandler, getDroppedAssetDataObject, getCredentials, lockDataObject, World } from "../utils/index.js";
import { errorHandler, getDroppedAssetDataObject, lockDataObject, World } from "../utils/index.js";
import { GameDataType } from "../types/gameDataType.js";
import { DroppedAssetInterface, WorldActivityType } from "@rtsdk/topia";

Expand Down
2 changes: 1 addition & 1 deletion src/controllers/handleResetBoard.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ export const handleResetBoard = async (req: Request, res: Response) => {
const visitor: VisitorInterface = await Visitor.get(visitorId, urlSlug, { credentials });
const isAdmin = visitor.isAdmin;

const { keyAsset, wasDataObjectInitialized } = await getDroppedAssetDataObject(credentials, false);
const { keyAsset, wasDataObjectInitialized } = await getDroppedAssetDataObject(credentials, true);
const { lastInteraction, player1, player2, resetCount } = keyAsset.dataObject as GameDataType;

if (wasDataObjectInitialized) {
Expand Down
8 changes: 4 additions & 4 deletions src/utils/droppedAssets/getDroppedAssetDataObject.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ export const getDroppedAssetDataObject = async (credentials: Credentials, isKeyA
let keyAsset,
keyAssetId = assetId;

if (!sceneDropId) throw "sceneDropId is required.";

const world = World.create(urlSlug, { credentials });
await world.fetchDataObject();
const dataObject = world.dataObject as WorldDataObjectType;
Expand All @@ -17,16 +19,14 @@ export const getDroppedAssetDataObject = async (credentials: Credentials, isKeyA
keyAssetId = dataObject[sceneDropId].keyAssetId;
} else {
// find key asset by sceneDropId and unique name
keyAsset = await DroppedAsset.getWithUniqueName("reset", urlSlug, process.env.INTERACTIVE_SECRET!, credentials);
const droppedAssets = await world.fetchDroppedAssetsBySceneDropId({ sceneDropId, uniqueName: "reset" });
keyAsset = droppedAssets[0];
if (!keyAsset) throw "No key asset with the unique name 'reset' found.";
keyAssetId = keyAsset?.id;
}
}

if (!sceneDropId) sceneDropId = keyAssetId;

// store keyAssetId by sceneDropId in World data object so that it can be accessed by any clickable asset
// this supports a scene being dropped with the board already created instead of just the Reset button
if (!dataObject || Object.keys(dataObject).length === 0) {
await world.setDataObject({ [sceneDropId]: { keyAssetId } });
} else if (!dataObject[sceneDropId]) {
Expand Down