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
48 changes: 32 additions & 16 deletions .github/workflows/aws_dev_release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ on:
branches:
- dev
workflow_dispatch:

env:
REPOSITORY: 'sdk-example'
ECS_Cluster: "topia-dev-sdk-apps"
Expand All @@ -14,7 +14,7 @@ env:
concurrency:
group: ${{ github.event.pull_request.number || github.ref }}
cancel-in-progress: true

permissions:
id-token: write # This is required for requesting the JWT
contents: read # This is required for actions/checkout
Expand All @@ -26,7 +26,7 @@ jobs:
steps:
- name: Checkout
uses: actions/checkout@v4

- name: get servicename
id: sername
run: |
Expand All @@ -42,27 +42,35 @@ jobs:
echo "service=$service_value" >> "$GITHUB_OUTPUT"
echo "Service value: $(echo $service_value | jq -c )"
fi

- uses: actions/setup-node@v4
with:
node-version: 20.10
cache: 'npm'
- run: npm i
- run: CI=false npm run build

- name: Set up QEMU
uses: docker/setup-qemu-action@v3

with:
platforms: arm64,amd64

- name: Configure AWS credentials
uses: aws-actions/configure-aws-credentials@v4
with:
role-to-assume: arn:aws:iam::368076259134:role/github-actions-role
aws-region: us-east-1

- name: Login to Amazon ECR
id: login-ecr
uses: aws-actions/amazon-ecr-login@v2

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
with:
buildkitd-flags: --debug
driver-opts: image=moby/buildkit:latest

- name: Image Metadata
id: metadata
uses: docker/metadata-action@v5
Expand All @@ -71,15 +79,23 @@ jobs:
tags: |
type=raw,value=${{ github.event.repository.name }}

- name: Build and tag
run: |
docker build --build-arg COMMIT_HASH=${{ github.sha }} --build-arg REF=${{ github.ref }} -t ${{ steps.metadata.outputs.tags }} .

- name: push docker image to Amazon ECR
run: |
docker push ${{ steps.metadata.outputs.tags }}



- name: Build and push multi-platform images to ECR
uses: docker/build-push-action@v5
with:
context: .
platforms: linux/amd64,linux/arm64
push: true
tags: ${{ steps.metadata.outputs.tags }}
build-args: |
REF=${{ github.ref }}
COMMIT_HASH=${{ github.sha }}
cache-from: type=gha
cache-to: type=gha,mode=max
provenance: false
sbom: false

deploy_matrix:
runs-on: ubuntu-latest
needs: Build
Expand All @@ -96,4 +112,4 @@ jobs:
- name: deploy
run: |
aws ecs update-service --cluster ${{ env.ECS_Cluster }} --service topia-${{ env.ENV }}-${{ matrix.service }}0 --force-new-deployment

46 changes: 23 additions & 23 deletions .github/workflows/aws_prod_release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ env:
concurrency:
group: ${{ github.event.pull_request.number || github.ref }}
cancel-in-progress: true

permissions:
id-token: write # This is required for requesting the JWT
contents: read # This is required for actions/checkout
Expand All @@ -27,7 +27,7 @@ jobs:
uses: actions/checkout@v4
with:
ref: ${{ github.event.release.tag_name }}

- name: get servicename
id: sername
run: |
Expand All @@ -53,16 +53,18 @@ jobs:
- run: npm version ${{ github.event.release.tag_name }}
- run: npm i
- run: CI=false npm run build

- name: Set up QEMU
uses: docker/setup-qemu-action@v3.0.0

with:
platforms: arm64,amd64

- name: Configure AWS credentials
uses: aws-actions/configure-aws-credentials@v4
with:
role-to-assume: arn:aws:iam::368076259134:role/github-actions-role
aws-region: us-east-1

- name: Login to Amazon ECR
id: login-ecr
uses: aws-actions/amazon-ecr-login@v2
Expand All @@ -71,6 +73,7 @@ jobs:
uses: docker/setup-buildx-action@v3
with:
buildkitd-flags: --debug
driver-opts: image=moby/buildkit:latest

- name: Image Metadata
id: metadata
Expand All @@ -79,26 +82,23 @@ jobs:
images: ${{ steps.login-ecr.outputs.registry }}/${{ env.REPOSITORY }}
tags: |
type=raw,value=${{ github.event.repository.name }}-${{ github.event.release.tag_name }}

- name: Image Metadata
id: metadata-latest
uses: docker/metadata-action@v5
with:
images: ${{ steps.login-ecr.outputs.registry }}/${{ env.REPOSITORY }}
tags: |
type=raw,value=${{ github.event.repository.name }}-latest

- name: Build and version tag
run: |
docker build --build-arg REF=${{ github.ref}} --build-arg COMMIT_HASH=$(git rev-parse --short ${{ github.sha }}) -t ${{ steps.metadata.outputs.tags }} .
docker tag ${{ steps.metadata.outputs.tags }} ${{ steps.metadata-latest.outputs.tags }}

- name: push docker image to Amazon ECR
run: |
docker push ${{ steps.metadata.outputs.tags }}
docker push ${{ steps.metadata-latest.outputs.tags }}
- name: Build and push multi-platform images to ECR
uses: docker/build-push-action@v5
with:
context: .
platforms: linux/amd64,linux/arm64
push: true
tags: ${{ steps.metadata.outputs.tags }}
build-args: |
REF=${{ github.ref }}
COMMIT_HASH=${{ github.sha }}
cache-from: type=gha
cache-to: type=gha,mode=max
provenance: false
sbom: false


deploy_matrix:
runs-on: ubuntu-latest
needs: Build
Expand All @@ -115,4 +115,4 @@ jobs:
- name: deploy
run: |
aws ecs update-service --cluster ${{ env.ECS_Cluster }} --service topia-${{ env.ENV }}-${{ matrix.service }}0 --force-new-deployment

17 changes: 17 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,23 @@ Connect 4 is a completely on-canvas game where two players take turns dropping p

- Reset Button: Clicking on the Reset Button as an admin will remove all assets and rebuild the board completely. This is especially helpful if an interactive asset has accidentally been deleted.

### Required Assets with Unique Names

The app dynamically generates assets using the following unique names:

| Unique Name | Description |
| -------------- | -------------------------------------------------- |
| `reset` | Key asset reset button |
| `board` | The board background image |
| `gameText` | Main game status message |
| `player1Text` | Player 1 name display |
| `player2Text` | Player 2 name display |
| `player1` | Player 1 selection button (red piece) |
| `player2` | Player 2 selection button (yellow piece) |
| `selector` | Column drop arrows (7 total, one per column) |
| `claimedSpace` | Player pieces placed on the board during gameplay |
| `crown` | Victory crown for the winner |

### Data objects

- Key Asset: the data object attached to the Reset Button key asset can stores all of the game play information including current players, player turn status, and game status.
Expand Down
8 changes: 4 additions & 4 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"main": "src/index.ts",
"dependencies": {
"@googleapis/sheets": "^7.0.0",
"@rtsdk/topia": "^0.15.9",
"@rtsdk/topia": "^0.19.9",
"@types/cors": "^2.8.13",
"axios": "^1.5.0",
"body-parser": "^1.20.2",
Expand Down
18 changes: 9 additions & 9 deletions src/controllers/handleDropPiece.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,6 @@ export const handleDropPiece = async (req: Request, res: Response) => {
const { displayName, identityId, sceneDropId, urlSlug, visitorId } = credentials;
const { username } = req.body;

let text = "",
shouldUpdateGame = false,
analytics = [];

const column = parseInt(req.params.column);
if (isNaN(column)) throw "Column id is required.";

Expand All @@ -40,6 +36,10 @@ export const handleDropPiece = async (req: Request, res: Response) => {
turnCount,
} = keyAsset.dataObject as GameDataType;

let text = `It's ${lastPlayerTurn === player1.visitorId ? player1.username : player2.username}'s turn`,
shouldUpdateGame = false,
analytics = [];

if (isResetInProgress) throw "Reset in progress.";

const columnStart =
Expand Down Expand Up @@ -72,16 +72,16 @@ export const handleDropPiece = async (req: Request, res: Response) => {
}

if (isGameOver) {
text = "Game over! Press Reset to play again.";
text = "Game over! Press Reset to play again";
} else if (!player1.visitorId || !player2.visitorId) {
text = "Two players are needed to get started.";
text = "Two players are needed to get started";
} else if (player1.visitorId !== visitorId && player2.visitorId !== visitorId) {
text = "Game in progress.";
text = "Game in progress";
} else if (columns[column].length === 6) {
text = "Cannot place your move here.";
text = "Cannot place your move here";
} else if (lastPlayerTurn === visitorId) {
const username = player2.visitorId === visitorId ? player1.username : player2.username;
text = `It's ${username}'s turn.`;
text = `It's ${username}'s turn`;
} else {
updatedData.lastPlayerTurn = visitorId;
updatedData.columns[column]?.push(visitorId);
Expand Down
1 change: 1 addition & 0 deletions src/utils/droppedAssets/dropTextAsset.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ export const dropTextAsset = async ({
position,
sceneDropId,
text,
textWidth: 500,
uniqueName,
urlSlug,
yOrderAdjust: 500,
Expand Down
4 changes: 2 additions & 2 deletions src/utils/generateBoard.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ export const generateBoard = async (credentials: Credentials) => {
y: boardCenter.y - 130,
},
style: { textSize: 20, textWidth: 150 },
text: "",
text: "Player One",
uniqueName: `player1Text`,
}),
dropTextAsset({
Expand All @@ -55,7 +55,7 @@ export const generateBoard = async (credentials: Credentials) => {
y: boardCenter.y - 130,
},
style: { textSize: 20, textWidth: 150 },
text: "",
text: "Player Two",
uniqueName: `player2Text`,
}),
]);
Expand Down
Loading