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
11 changes: 3 additions & 8 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ jobs:
uses: actions/setup-java@v4
with:
distribution: "temurin"
java-version: "21"
java-version: "25"

- name: Build 🔧
env:
Expand All @@ -31,11 +31,6 @@ jobs:

mkdir -p build/bundle/public

# This demo doesn't implement Service Worker and Native Cache, so remove them from the settings:
sed -i 's/service_worker_url = .*//' game.project
sed -i 's/manifest_url = .*//' game.project
rm -rf example/bundle/web

BOB_SHA1=${DEFOLD_BOB_SHA1:-$(curl -s 'https://d.defold.com/stable/info.json' | jq -r .sha1)}
BOB_LOCAL_SHA1=$((java -jar build/bundle/bob.jar --version | cut -d' ' -f6) || true)
if [ "${BOB_LOCAL_SHA1}" != "${BOB_SHA1}" ]; then wget --progress=dot:mega -O build/bundle/bob.jar "https://d.defold.com/archive/${BOB_SHA1}/bob/bob.jar"; fi
Expand All @@ -44,13 +39,13 @@ jobs:
TITLE=$(awk -F "=" '/^title/ {gsub(/[ \r\n\t]/, "", $2); print $2}' game.project)

java -jar build/bundle/bob.jar --email [email protected] --auth 12345 --texture-compression true --bundle-output build/bundle/js-web --platform js-web --architectures wasm-web --archive --variant release resolve build bundle
(cd build/bundle/js-web/${TITLE} && zip -r ../../public/demo_no-sw_no-native-cache.zip .)
(cd build/bundle/js-web/${TITLE} && zip -r ../../public/demo.zip .)

- name: Upload Result
uses: actions/upload-artifact@v4
with:
name: bundle
path: build/bundle/public/demo_no-sw_no-native-cache.zip
path: build/bundle/public/demo.zip

- name: Deploy to Pages 🚀
if: github.ref == 'refs/heads/master'
Expand Down
26 changes: 14 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,23 +29,25 @@ You can use it in your own project by adding this project as a [Defold library d
- Icon 512 x 512 px.
- Cover 800 x 470 px.
- Screenshots.
4. Add [the extension](https://github.com/indiesoftby/defold-yagames/archive/master.zip) as a Defold library dependency to your project.
5. Enable monetization and earn revenue from placing ad blocks in your game. Ad blocks are available in the following formats:
4. Add [the extension](https://github.com/indiesoftby/defold-yagames/archive/master.zip) as a Defold library dependency to your project.
5. Initialize the SDK in your game - see [Initialization](#-initialization-docs) section below for the API details.
6. Implement advertisement in your game - see [Advertisement](#-advertisement-docs) section below for the API details.
7. Enable monetization and earn revenue from placing ad blocks in your game. Ad blocks are available in the following formats:
- **Interstitial blocks**: ad blocks that completely cover the app background and show up at certain points (for example, when accessing the next game level). *Important: Mute sounds before showing the ad!*
- **Rewarded videos**: blocks with video ads that the user can choose to view and earn a reward or in-game currency. *Important: Mute sounds before showing the ad!*
- **Sticky banners**: banner ads, super easy to setup.
- **In-game purchases**: earn revenue by providing paid services to your users.
5. You can [publish your game on Yandex.Games](https://games.yandex.ru/console/) from this moment.
8. You can [publish your game on Yandex.Games](https://games.yandex.ru/console/) from this moment.

### Best Practices & Tips

1. The YaGames extension imitates a real API on *non-HTML5* platforms. The idea is to allow to you quickly implement API on your favourite platform (macOS, Windows, Linux) and don't spend time on slowly rebuilding/uploading the game to the Yandex.
2. The code from `yagames/manifests/web/engine_template.html` is always added to your HTML5 template. This behaviour can't be disabled. Tip: use Git-branching for every HTML5 platform and do not mix platform-specific code between them.
2. The code from `yagames/manifests/web/engine_template.html` is always added to your HTML5 template. **This behaviour can't be disabled.** Tip: use Git-branching for every HTML5 platform and do not mix platform-specific code between them.
3. You don't need to set up any cache-busting techniques, since Yandex.Games hosts each version of your game in separate paths.

## Code Examples

Take a look at the demo project inside `example` directory. It has quite a few buttons to test all APIs. You can use it in your game as a debug screen or simply [download/upload a pre-built .zip archive](https://github.com/indiesoftby/defold-yagames/blob/gh-pages/demo_no-sw_no-native-cache.zip?raw=true) to make sure that you implemented SDK in the right way.
Take a look at the demo project inside `example` directory. It has quite a few buttons to test all APIs. You can use it in your game as a debug screen or simply [download/upload a pre-built .zip archive](https://github.com/indiesoftby/defold-yagames/blob/gh-pages/demo.zip?raw=true) to make sure that you implemented SDK in the right way.

![YaGames Demo](screenshot.png)

Expand Down Expand Up @@ -3212,28 +3214,28 @@ end
```ini
[yagames]
sdk_url = /sdk.js
sdk_init_options = {}
sdk_init_snippet = console.log("Yandex Games SDK is ready!");
sdk_init_options = { signed: false }
sdk_init_snippet = console.log("Yandex Games SDK is ready!", ysdk);
service_worker_url = sw.js
```

* `sdk_url` - Sets the URL of the Yandex.Games SDK. In July 2024 the platform changed the URL of its SDK and now it can be of two kinds. First is the local `/sdk.js` for games you upload as an archive (default, **suitable for 99% of games**). The second is for iFrame games - `https://sdk.games.s3.yandex.net/sdk.js`.
* `sdk_init_options` - JavaScript Object that is passed as-is into the Yandex Games SDK initialization options for [the JS `YaGames.init` function](https://yandex.ru/dev/games/doc/dg/sdk/sdk-about.html?lang=en). Example: `{ orientation: { value: "landscape", lock: true } }`.
* `sdk_init_options` - JavaScript Object that is passed as-is into the Yandex Games SDK initialization options for [the JS `YaGames.init` function](https://yandex.ru/dev/games/doc/dg/sdk/sdk-about.html?lang=en). Example: `{ signed: true }`.
* `sdk_init_snippet` - JavaScript code that is passed as-is and called when the `ysdk` variable becomes available. Example: `console.log(ysdk);`. **Use with care, and don't forget to put a semicolon `;` at the end.**
* `service_worker_url` - Relative URL to the Service Worker file. Usually it's `sw.js`. Set the URL to enable Service Worker.
* `service_worker_url` - (deprecated) Relative URL to the Service Worker file. Usually it's `sw.js`. Set the URL to enable Service Worker.

### Misc

> [!TIP]
> We don't use these features in our games as we don't see any improvements in our games metrics, and the complexity of its integration and support is quite high.

#### Service Worker How-To
#### Service Worker

Yandex dropped the Service Worker description page in their docs, but it still allows to integrate Service Worker into your game to be able to run both offline and online.
Yandex dropped the Service Worker description page in their docs, but it still allows to integrate Service Worker into your game to be able to run both offline and online. This feature is deprecated and will be removed in the future.

1. Set the path to the file `sw.js` in the `game.project` settings.
2. Copy the `yagames/manifests/web/sw.js` file to the root directory of your release build.
3. Edit the list of all game files inside your `sw.js`. Omit `sw.js` and `yandex-manifest.json`.
3. Edit the list of all game files inside your `sw.js`. Omit `sw.js`.
4. You should increment the version inside `sw.js` on every update of your game on Yandex.Games.

## Credits
Expand Down
5 changes: 0 additions & 5 deletions build_example.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,6 @@
# Immediately exit if any command has a non-zero exit status:
set -e

# This demo doesn't implement Service Worker and Native Cache, so remove them from the settings:
sed -i 's/service_worker_url = .*//' game.project
sed -i 's/manifest_url = .*//' game.project

mkdir -p build/bundle

BOB_SHA1=${BOB_SHA1:-$(curl -s 'https://d.defold.com/stable/info.json' | jq -r .sha1)}
Expand All @@ -20,7 +16,6 @@ SETTINGS="--build-server https://build.defold.com --variant debug --email foo@ba
PLATFORM=js-web
ARCHITECTURES=wasm-web
java -jar build/bob.jar ${SETTINGS} --bundle-output build/bundle/${PLATFORM} --platform ${PLATFORM} --architectures ${ARCHITECTURES} --archive resolve build bundle
perl -pi -e "s/cachePrefix \+ \"-v1\"/cachePrefix + \"-v$(date +%s)\"/g" "build/bundle/${PLATFORM}/${TITLE}/sw.js"

if [ $# -eq 1 ]; then
PORT=$1
Expand Down
Binary file removed example/bundle/web/icon/splash.png
Binary file not shown.
66 changes: 0 additions & 66 deletions example/bundle/web/sw.js

This file was deleted.

27 changes: 0 additions & 27 deletions example/bundle/web/yandex-manifest.json

This file was deleted.

1 change: 0 additions & 1 deletion game.project
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ high_dpi = 1
title = yagames
version = 0.18.0
developer = Indiesoft LLC
bundle_resources = example/bundle/
dependencies#0 = https://github.com/subsoap/defos/archive/v2.8.3.zip
dependencies#1 = https://github.com/Insality/druid/archive/0.6.0.zip
dependencies#2 = https://github.com/britzl/ludobits/archive/7.1.0.zip
Expand Down
18 changes: 18 additions & 0 deletions yagames/ext.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
[yagames]
title = YaGames
group = Distribution
help = Settings for the YaGames extension

sdk_url.type = string
sdk_url.label = SDK URL
sdk_url.default = /sdk.js

sdk_init_options.type = string
sdk_init_options.label = SDK Init Options

sdk_init_snippet.type = string
sdk_init_snippet.label = SDK Init Snippet

service_worker_url.type = string
service_worker_url.label = Service Worker URL (Deprecated)

5 changes: 5 additions & 0 deletions yagames/manifests/web/sw.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
// Service Worker was officially supported and recommended for implementation
// on Yandex Games until 2024, but then became optional and was even removed
// from the documentation. This example and connection options are left for
// legacy projects.

// 1. Put here the name of your game:
const cachePrefix = "your-game-name";

Expand Down
27 changes: 0 additions & 27 deletions yagames/manifests/web/yandex-manifest.json

This file was deleted.