Skip to content

Latest commit

 

History

27 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Platform SDK

Installation

To use this library in your Defold project, add the needed version URL to your game.project dependencies from Release add to path github credentials.
For example: https://username:your_token@github.com/OCRV-RRW/PlatformSDK/archive/refs/tags/v0.3.zip

Open game.project and make sure to reference /platform-sdk/template/engine_template.html in the .html Shell field in the HTML5 section.

Usage

Sdk Initialization.

platform_sdk = require("platform-sdk.platform-sdk")

function init(self)
	platform_sdk.init()
	platform_sdk.LoadingComplete()
end

You can subscribe to the complete initialization.

platform_sdk = require("platform-sdk.platform-sdk")

function init(self)
	platform_sdk.subscribeToComplete(
		function ()
			platform_sdk.getUser(function (user)
				if(user == nil) then 
					print("Couldn't load user")
				 end
				print(user["name"] .. " " .. user["id"])
			end)
		end
	)
	platform_sdk.init()
	platform_sdk.loadingComplete()
end

API

platform_sdk.init - start platform-sdk initialization.
platform_sdk.loadingComplete - send an html message to the parent about the completion of the game loading.
platform_sdk.getUser - get user.
platform_sdk.subscribeToComplete - subscribe to the end of initialization.
platform_sdk.addScoreToSkill (callback, skillName, score) - add score to user skill

Usage for frontend developer

Sending message to Platform SDK

function sendMessageToIframe(message: object){
	const frame = document.getElementById("game_iframe") as HTMLIFrameElement | null
	if (frame && frame.contentWindow){
		frame.contentWindow.postMessage(message, "https://example.ru")
	}
}

Example

sendMessageToIframe({type: "start-game"})

Listening Platform SDK message

window.addEventListener("event_name", _ => {
	// ... your code
})

Example

window.addEventListener("is-loaded", _ =>{
	console.log("game is loaded")
})

Listen event

is-loaded - invoked on game is loaded.

Send event type

start-game - send to initialize the sdk for the platform.

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Used by

Contributors

Languages