unified_game_services_gamejolt 0.1.0 copy "unified_game_services_gamejolt: ^0.1.0" to clipboard
unified_game_services_gamejolt: ^0.1.0 copied to clipboard

GameJolt provider for unified_game_services, using the GameJolt Game API v1.2 (pure Dart, REST).

example/unified_game_services_gamejolt_example.dart

import 'dart:typed_data';

import 'package:unified_game_services_gamejolt/unified_game_services_gamejolt.dart';
import 'package:unified_game_services_platform_interface/unified_game_services_platform_interface.dart';

/// Replace the credentials with your game's id/key (GameJolt dashboard) and the
/// player's username + Game Token.
Future<void> main() async {
  GameJoltProvider.registerWith(
    gameId: 'YOUR_GAME_ID',
    privateKey: 'YOUR_PRIVATE_KEY',
    username: 'player_name',
    userToken: 'player_game_token',
  );
  final services = UnifiedGameServicesPlatform.instance;

  final player = await services.signIn();
  print('Signed in as: ${player?.displayName}');

  if (services.supports(GameCapability.achievements)) {
    await services.unlockAchievement('123456'); // trophy id
  }

  if (services.supports(GameCapability.leaderboards)) {
    await services.submitScore(leaderboardId: '654321', score: 1500);
    final board = await services.getLeaderboard('654321');
    for (final e in board.entries) {
      print('#${e.rank} ${e.player.displayName}: ${e.displayScore}');
    }
  }

  if (services.supports(GameCapability.cloudSave)) {
    await services.saveData('profile', Uint8List.fromList([1, 2, 3]));
    final save = await services.loadData('profile');
    print('Loaded ${save?.bytes.length} bytes');
  }

  // Provider-specific extras: reach GameJolt's session API (online presence)
  // through the typed accessor, without holding the instance you registered.
  final gameJolt = UnifiedGameServicesPlatform.getInstance<GameJoltProvider>();
  await gameJolt.startSessionHeartbeat();
  // … play …
  await gameJolt.stopSessionHeartbeat();
}
0
likes
160
points
4
downloads

Documentation

API reference

Publisher

verified publisheraprimo.dev

Weekly Downloads

GameJolt provider for unified_game_services, using the GameJolt Game API v1.2 (pure Dart, REST).

Repository (GitHub)
View/report issues

Topics

#game-services #achievements #leaderboards #gamejolt #gamedev

License

MIT (license)

Dependencies

crypto, http, unified_game_services_platform_interface

More

Packages that depend on unified_game_services_gamejolt