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

Implement GameFi SDK for Cocos. #5

Merged
merged 3 commits into from
Jul 8, 2024
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
4 changes: 0 additions & 4 deletions .github/workflows/deploy-docs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,6 @@
name: Deploy static content to Pages

on:
# Runs on pushes targeting the default branch
push:
branches: ['main']

# Allows you to run this workflow manually from the Actions tab
workflow_dispatch:

Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/publish-npm.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ jobs:
- id: get-package
run: |
PACKAGE_NAME=$(echo ${GITHUB_REF#refs/tags/} | cut -d- -f1)
ALLOWED_PACKAGES=("phaser") # Add more package names if needed
ALLOWED_PACKAGES=("phaser" "cocos")
if [[ " ${ALLOWED_PACKAGES[@]} " =~ " ${PACKAGE_NAME} " ]]; then
echo "::set-output name=package::${PACKAGE_NAME}"
echo "::set-output name=version::${GITHUB_REF#refs/tags/}"
Expand Down
15 changes: 11 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,13 +1,17 @@
# game-engines-sdk

TON blockchain bindings and utilities for game engines:
* Phaser.io
* Cocos2d (coming soon)
* [Phaser](https://phaser.io)
* [Cocos](https://www.cocos.com/en)

# Getting started
Installation:
```sh
npm install --save @ton/phaser-sdk
# for Phaser
npm install --save @ton/phaser-sdk@beta

# for Cocos
npm install --save @ton/cocos-sdk@beta
```

Creating GameFi instance:
Expand Down Expand Up @@ -79,7 +83,10 @@ This can be used for:
| [merchantJettonAddress](https://ton-org.github.io/game-engines-sdk/classes/GameFi.html#merchantJettonAddress) | in-game shop's jetton used as in-game currency |

# Use cases
To learn complex use cases read [TON GameFi article](https://gist.github.com/barinbritva/b3db1605f2667b7562b53a23877c0e73) and check out the source code of demo [Flappy Bird game](https://github.com/ton-community/flappy-bird).
To learn complex use cases:
- read [TON GameFi article](https://gist.github.com/barinbritva/b3db1605f2667b7562b53a23877c0e73)
- check out the source code of [Flappy Bird](https://github.com/ton-community/flappy-bird) demo for Phaser
- check out the example of [Flappy Bird](https://github.com/CocosTechLabs/flappy-bird) for Cocos

# References
The full [typedoc references](https://ton-org.github.io/game-engines-sdk/index.html).
1,415 changes: 1,414 additions & 1 deletion package-lock.json

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@
"node": ">=18.0.0",
"npm": ">=9.0.0"
},
"workspaces": ["packages/phaser"],
"workspaces": ["packages/phaser", "packages/cocos"],
"scripts": {
"check-types": "tsc --noEmit",
"typedoc": "typedoc --out docs packages/phaser/src/index.ts",
"typedoc": "typedoc --out docs packages/phaser/src/index.ts packages/cocos/src/index.ts",
"lint": "prettier --check \"./**/*.{js,jsx,ts,tsx,json,yml}\""
},
"devDependencies": {
Expand Down
7 changes: 7 additions & 0 deletions packages/cocos/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# cocos-sdk

TON blockchain bindings and utilities for [Cocos](https://www.cocos.com/en) game engine.

# Documentation

Please read the documentation in the official [repository](https://github.com/ton-org/game-engines-sdk).
23 changes: 23 additions & 0 deletions packages/cocos/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
{
"name": "@ton/cocos-sdk",
"version": "0.0.1-beta.1",
"files": ["./dist"],
"main": "dist/index.ts",
"types": "dist/cocos/src/index.d.ts",
"module": "dist/index.ts",
"scripts": {
"dev": "webpack --mode development --watch",
"build": "webpack --mode production"
},
"dependencies": {
"@tonconnect/ui": "^2.0.1-beta.0",
"@ton/ton": "^13.9.0",
"@orbs-network/ton-access": "^2.3.3",
"@ton-community/assets-sdk": "0.0.4-beta.1"
},
"devDependencies": {
"webpack": "^5.92.0",
"webpack-cli": "^5.1.4",
"ts-loader": "^9.5.1"
}
}
11 changes: 11 additions & 0 deletions packages/cocos/src/game-fi.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import {GameFiBase, GameFiInitializationParams} from '../../common/game-fi';

export class GameFi extends GameFiBase {
/**
* Setups and creates GameFi instance.
* The instance provides all the needed functionality via various methods.
*/
public static async create(params: GameFiInitializationParams = {}): Promise<GameFi> {
return new GameFi(await GameFi.createDependencies(params));
}
}
5 changes: 5 additions & 0 deletions packages/cocos/src/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
export * from '../../common/content-resolver';
export * from '../../common/external';
export * from '../../common/game-fi';
export * from '../../common/interfaces';
export * from './game-fi';
3 changes: 3 additions & 0 deletions packages/cocos/tsconfig.dev.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"extends": ["./tsconfig.json", "../../tsconfig.dev.json"]
}
9 changes: 9 additions & 0 deletions packages/cocos/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"extends": "../../tsconfig.json",
"compilerOptions": {
"outDir": "./dist",
"module": "ES2022",
"target": "ES2022"
},
"include": ["./src"]
}
37 changes: 37 additions & 0 deletions packages/cocos/webpack.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
const path = require('path');
const webpack = require('webpack');

module.exports = {
mode: 'production',
entry: './src/index.ts',
module: {
rules: [
{
test: /\.tsx?$/,
use: 'ts-loader',
exclude: /node_modules/
}
]
},
resolve: {
extensions: ['.tsx', '.ts', '.js'],
fallback: {
buffer: require.resolve('buffer/')
}
},
output: {
filename: 'index.ts',
barinbritva marked this conversation as resolved.
Show resolved Hide resolved
path: path.resolve(__dirname, './dist'),
libraryTarget: 'module'
},
experiments: {
outputModule: true
},
target: ['web', 'browserslist:> 0.5%'],
externals: [],
plugins: [
new webpack.ProvidePlugin({
Buffer: ['buffer', 'Buffer']
})
]
};