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
30 changes: 15 additions & 15 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,27 +18,27 @@ The plugin is designed to simplify the development of HTML5 games and applicatio

## Short list of features

| Feature | Crazy Games | Yandex Games | Poki | VK |
|--------------------|:-----------:|:------------:|:-------:|:------:|
| Fullscreen Advertisement | ✅ | ✅ | ✅ | ✅ |
| Rewarded Advertisement | ✅ | ✅ | ✅ | ✅ |
| Banner Advertisement | ✅ | ✅ | ❌ | ✅ |
| User Info | ✅ | ✅ | ❌ | ✅ |
| Authentication | ✅ | ✅ | ❌ | ✍️ |
| User Data | ✅ | ✅ | ❌ | ✍️ |
| Leaderboards | ❌ | ✅ | ❌ | ✍️ |
| Payments | ❌ | ✅ | ❌ | ✍️ |
| Invite Links | ✅ | ❌ | ✅ | ❌ |
| Invite Button | ✅ | ❌ | ❌ | ❌ |
| Server time | ❌ | ✅ | ❌ | ❌ |
| Desktop shortcut | ❌ | ✅ | ❌ | ✍️ |
| Feature | Crazy Games | Yandex Games | Poki | VK |
|------------------------------|:-----------:|:------------:|:-------:|:---------:|
| Fullscreen Advertisement | ✅ | ✅ | ✅ | ✅ |
| Rewarded Advertisement | ✅ | ✅ | ✅ | ✅ |
| Banner Advertisement | ✅ | ✅ | ❌ | ✅ |
| User Info | ✅ | ✅ | ❌ | ✅ |
| Authentication | ✅ | ✅ | ❌ | ✍️ |
| User Data | ✅ | ✅ | ❌ | ✅ |
| Leaderboards | ❌ | ✅ | ❌ | ✍️ |
| Payments | ❌ | ✅ | ❌ | ✍️ |
| Invite Links | ✅ | ❌ | ✅ | ❌ |
| Invite Button | ✅ | ❌ | ❌ | ❌ |
| Server time | ❌ | ✅ | ❌ | ❌ |
| Desktop shortcut | ❌ | ✅ | ❌ | ✍️ |

## Installation

1. Download the plugin as a ZIP archive.
2. Extract the ZIP archive and move the `addons/` folder it contains into your project folder.

> Also you can install the plugin from [Asset Library](https://godotengine.org/asset-library/asset/2841).
> You can also install the plugin from the [Asset Library](https://godotengine.org/asset-library/asset/2841).

3. Enable the plugin in **Project > Project Settings > Plugins**.

Expand Down
10 changes: 5 additions & 5 deletions addons/webbus/tools/tools.gd
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ func get_language_by_code(code:String) -> String:

class VKRequest:
var callback:Callable
var configs:Dictionary
var params:Dictionary
var event:String

var tools := WebBusTools.new()
Expand All @@ -67,18 +67,18 @@ class VKRequest:

var send_callback := JavaScriptBridge.create_callback(func(args):
if args[0]:
if configs:
var _conf := tools.to_js(configs)
if params:
var _conf := tools.to_js(params)
WebBus.vkBridge.send(event, _conf).then(result_callback)
else:
WebBus.vkBridge.send(event).then(result_callback)
else:
push_error("Error vk request")
)

func send(_event:String, _configs:Dictionary={}, _callback:Callable=_callback_pass):
func send(_event:String, _params:Dictionary={}, _callback:Callable=_callback_pass):
if OS.get_name() == "Web" and WebBus.platform == WebBus.Platform.VK:
configs = _configs
params = _params
callback = _callback
event = _event
WebBus.vkBridge.supportsAsync(event).then(send_callback)
Expand Down
105 changes: 71 additions & 34 deletions addons/webbus/webbus.gd
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
extends Node
## Singlton class[br]
## [br]
## Docs: [url]https://github.com/talkafk/WebBus[/url]
## Docs: [url]https://talkafk.github.io/WebBus[/url]


signal inited
Expand Down Expand Up @@ -165,6 +165,7 @@ func _ready() -> void:
is_init = true
inited.emit()

signal _getted_info(data)

func _get_info() -> void:
var lang:String
Expand All @@ -181,6 +182,16 @@ func _get_info() -> void:
var c_code :String = CrazySDK.user.systemInfo.countryCode
lang = tools.get_language_by_code(c_code)
type = CrazySDK.user.systemInfo.device.type
Platform.VK:
while not vkBridge:
await _SDK_inited
var _callback := JavaScriptBridge.create_callback(func(args):
_getted_info.emit(args[0])
)
vkBridge.send("VKWebAppGetLaunchParams").then(_callback)
var res = await _getted_info
lang = res.vk_language
type = res.vk_platform.split("_")[0]
_:
lang = "unknown"
type = "unknown"
Expand Down Expand Up @@ -451,9 +462,9 @@ func hide_banner() -> void:
push_warning("Platform not supported")
return
#endregion
#region game


#region Game

func start_gameplay():
match platform:
Platform.YANDEX:
Expand Down Expand Up @@ -527,6 +538,7 @@ func ready():
#endregion

#region Data

signal _auth(success:bool)

var _callback_auth_dialog := JavaScriptBridge.create_callback(func(args):
Expand Down Expand Up @@ -576,35 +588,59 @@ func set_data(data:Dictionary) -> void:
Platform.CRAZY:
for k in data:
CrazySDK.data.setItem(k, data[k])
Platform.VK:
var _data := JavaScriptBridge.create_object("Object")
for k in data:
_data.key = k
_data.value = data[k]
vkBridge.send("VKWebAppStorageSet", _data)
_:
push_warning("Platform not supported")


signal _getted_data
signal data_received

var _callback_getting_data := JavaScriptBridge.create_callback(func(args):
_getted_data.emit(tools.js_to_dict(args[0], false))
data_received.emit(tools.js_to_dict(args[0], false))
)

var _callback_getting_data_error := JavaScriptBridge.create_callback(func(args):
push_error("WebBus error:", tools.js_to_dict(args[0]))
_getted_data.emit({})
data_received.emit({})
)

func get_data(keys:Array) -> Dictionary:
func get_data(keys:Variant) -> Dictionary:
var keys_array:Array
if keys is Array:
keys_array = keys
else:
keys_array = [keys]

var result := {}
if OS.get_name() == "Web":
match platform:
Platform.YANDEX:
var _data:JavaScriptObject = tools.to_js(keys)
var _data:JavaScriptObject = tools.to_js(keys_array)
js_player.getData(_data).then(_callback_getting_data).catch(_callback_getting_data_error)
result = await _getted_data
result = await data_received
return result
Platform.CRAZY:
for k in keys:
for k in keys_array:
result[k] = CrazySDK.data.getItem(k)
data_received.emit(result)
return result
Platform.VK:
var req := tools.VKRequest.new()
var conf := {}
var _result:Dictionary
conf["keys"] = keys_array
req.send("VKWebAppStorageGet", conf, func(args): data_received.emit(args))
_result = await data_received
for key_value in _result["keys"]:
result[key_value.key] = key_value.value
return result
_:
data_received.emit(result)
push_warning("Platform not supported")
return result

Expand All @@ -618,35 +654,47 @@ func set_stats(data:Dictionary) -> void:
Platform.CRAZY:
for k in data:
CrazySDK.data.setItem(k, data[k])
Platform.VK:
set_data(data)
_:
push_warning("Platform not supported")


signal _getted_stats
signal stats_received

var _callback_getting_stats := JavaScriptBridge.create_callback(func(args):
_getted_stats.emit(tools.js_to_dict(args[0], false))
stats_received.emit(tools.js_to_dict(args[0], false))
)

var _callback_getting_stats_error := JavaScriptBridge.create_callback(func(args):
push_error("WebBus error:", tools.js_to_dict(args[0]))
_getted_stats.emit({})
stats_received.emit({})
)

func get_stats(keys:Array) -> Dictionary:
func get_stats(keys:Variant) -> Dictionary:
var keys_array:Array
if keys is Array:
keys_array = keys
else:
keys_array = [keys]

var result := {}
if OS.get_name() == "Web":
match platform:
Platform.YANDEX:
var _data:JavaScriptObject = tools.to_js(keys)
var _data:JavaScriptObject = tools.to_js(keys_array)
js_player.getStats(_data).then(_callback_getting_stats).catch(_callback_getting_stats_error)
result = await _getted_stats
result = await stats_received
return result
Platform.CRAZY:
for k in keys:
for k in keys_array:
result[k] = CrazySDK.data.getItem(k)
stats_received.emit(result)
return result
_:
Platform.VK:
return await get_data(keys_array)
_:
stats_received.emit(result)
push_warning("Platform not supported")
return result
#endregion
Expand Down Expand Up @@ -830,42 +878,31 @@ func start_loading() -> void:
push_warning("Platform not supported")

#endregion
#region getting data
#region System info

func get_platform() -> String:
if OS.get_name() == "Web":
match platform:
Platform.YANDEX:
return "yandex"
Platform.CRAZY:
return "crazy_games"
Platform.GAMEDISTRIBUTION:
return "game_distribution"
Platform.POKI:
return "poki"
_:
return "unknown"
if !system_info.is_empty():
return system_info.get("platform", "unknown")
return "unknown"


func get_language() -> String:
if OS.get_name() == "Web":
if !system_info.is_empty():
return system_info.get("language", "unknown")
return "unknown"
return "unknown"


func get_type_device() -> String:
if OS.get_name() == "Web":
if !system_info.is_empty():
return system_info.get("device_type", "unknown")
return "unknown"
return "unknown"

#endregion

#region invite
#region Invite

signal invite_link_getted(result:String)

Expand Down Expand Up @@ -929,7 +966,7 @@ func hide_invite_button() -> void:

#endregion

#region purchases
#region Purchases
var payments:JavaScriptObject

var _init_payments_callback := JavaScriptBridge.create_callback(func(args):
Expand Down
28 changes: 14 additions & 14 deletions mkdocs/docs/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,17 +21,17 @@ It allows you to build your project once and use the same build across multiple

## List of features

| Feature | Crazy Games | Yandex Games | Poki | VK |
|--------------------|:-----------:|:------------:|:-------:|:------:|
| [User Info](usage/user_info.md) | ✅ | ✅ | ❌ | ✅ |
| [Fullscreen Advertisement](usage/advertisement.md/#fullscreen-advertisement) | ✅ | ✅ | ✅ | ✅ |
| [Rewarded Advertisement](usage/advertisement.md/#rewarded-advertisement) | ✅ | ✅ | ✅ | ✅ |
| [Banner Advertisement](usage/advertisement.md/#banner-advertisement) | ✅ | ✅ | ❌ | ✅ |
| [Authentication](usage/authentication.md) | ✅ | ✅ | ❌ | ✍️ |
| [User Data](usage/user_data.md) | ✅ | ✅ | ❌ | ✍️ |
| [Leaderboards](usage/leaderboards.md) | ❌ | ✅ | ❌ | ✍️ |
| [Payments](usage/payments.md) | ❌ | ✅ | ❌ | ✍️ |
| [Invite Links](usage/invite.md/#invite-links) | ✅ | ❌ | ✅ | ❌ |
| [Invite Button](usage/invite.md/#invite-button) | ✅ | ❌ | ❌ | ❌ |
| [Server time](usage/server_time.md) | ❌ | ✅ | ❌ | ❌ |
| [Desktop shortcut](usage/desktop_shortcuts.md) | ❌ | ✅ | ❌ | ✍️ |
| Feature | Crazy Games | Yandex Games | Poki | VK |
|----------------------------------------------------------------------------------|:-----------:|:------------:|:--------:|:-------:|
| [User Info](usage/user_info.md) | ✅ | ✅ | ❌ | ✅ |
| [Fullscreen Advertisement](usage/advertisement.md/#fullscreen-advertisement) | ✅ | ✅ | ✅ | ✅ |
| [Rewarded Advertisement](usage/advertisement.md/#rewarded-advertisement) | ✅ | ✅ | ✅ | ✅ |
| [Banner Advertisement](usage/advertisement.md/#banner-advertisement) | ✅ | ✅ | ❌ | ✅ |
| [Authentication](usage/authentication.md) | ✅ | ✅ | ❌ | ✍️ |
| [User Data](usage/user_data.md) | ✅ | ✅ | ❌ | ✅ |
| [Leaderboards](usage/leaderboards.md) | ❌ | ✅ | ❌ | ✍️ |
| [Payments](usage/payments.md) | ❌ | ✅ | ❌ | ✍️ |
| [Invite Links](usage/invite.md/#invite-links) | ✅ | ❌ | ✅ | ❌ |
| [Invite Button](usage/invite.md/#invite-button) | ✅ | ❌ | ❌ | ❌ |
| [Server time](usage/server_time.md) | ❌ | ✅ | ❌ | ❌ |
| [Desktop shortcut](usage/desktop_shortcuts.md) | ❌ | ✅ | ❌ | ✍️ |
6 changes: 5 additions & 1 deletion mkdocs/docs/quick_start.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@

1. Download the plugin as a ZIP archive.
2. Extract the ZIP archive and move the `addons/` folder it contains into your project folder.

!!! Note
You can also install the plugin from the [Asset Library](https://godotengine.org/asset-library/asset/2841).

3. Enable the plugin in **Project > Project Settings > Plugins**.

## Initialization
Expand All @@ -22,7 +26,7 @@ func _ready() -> void:
```
## Call methods

Call any WebBus method
Call any methods through the `WebBus` singleton.

```gdscript
WebBus.show_ad()
Expand Down
8 changes: 4 additions & 4 deletions mkdocs/docs/usage/system_info.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
## Platform
Getting name of platform:

The function returns a `String`. Possible values are: "yandex", "crazy_games", "poki"
The function returns a `String`. Possible values are: `yandex`, `crazy_games`, `poki`, `vk`.

| Platform | Supported |
|-------------------|-----------|
Expand All @@ -18,14 +18,14 @@ var platform_name = WebBus.get_platform()

Getting type of device:

The function returns a `String`, possible values: "desktop", "tablet", "mobile".
The function returns a `String`, possible values: `desktop`, `tablet`, `mobile`.

| Platform | Supported |
|-------------------|-----------|
| Crazy Games | ![✔️](https://img.shields.io/badge/Supported-green) |
| Yandex Games | ![✔️](https://img.shields.io/badge/Supported-green) |
| Poki | ![❌](https://img.shields.io/badge/Not_Supported-red) |
| VK | ![️](https://img.shields.io/badge/In_Progress-yellow) |
| VK | ![️](https://img.shields.io/badge/Supported-green) |


```gdscript
Expand All @@ -42,7 +42,7 @@ The function returns 2-letter language code.
| Crazy Games | ![✔️](https://img.shields.io/badge/Supported-green) |
| Yandex Games | ![✔️](https://img.shields.io/badge/Supported-green) |
| Poki | ![❌](https://img.shields.io/badge/Not_Supported-red) |
| VK | ![️](https://img.shields.io/badge/In_Progress-yellow) |
| VK | ![️](https://img.shields.io/badge/Supported-green) |

```gdscript
var language = WebBus.get_language()
Expand Down
Loading
Loading