Packages

gamend_sdk

1.0.1226
1.1.1311 1.1.1310 1.1.1309 1.1.1308 1.1.1307 1.1.1304 1.1.1302 1.0.1301 1.0.1300 1.0.1299 1.0.1298 1.0.1297 1.0.1296 1.0.1295 1.0.1294 1.0.1290 1.0.1289 1.0.1288 1.0.1287 1.0.1286 1.0.1285 1.0.1283 1.0.1281 1.0.1280 1.0.1279 1.0.1278 1.0.1277 1.0.1276 1.0.1275 1.0.1274 1.0.1273 1.0.1270 1.0.1269 1.0.1267 1.0.1266 1.0.1265 1.0.1263 1.0.1262 1.0.1261 1.0.1260 1.0.1259 1.0.1258 1.0.1257 1.0.1256 1.0.1255 1.0.1254 1.0.1251 1.0.1250 1.0.1249 1.0.1247 1.0.1245 1.0.1240 1.0.1239 1.0.1238 1.0.1236 1.0.1235 1.0.1233 1.0.1230 1.0.1229 1.0.1228 1.0.1227 1.0.1226 1.0.1225 1.0.1224 1.0.1223 1.0.1222 1.0.1221 1.0.1220 1.0.1219 1.0.1217 1.0.1216 1.0.1215 1.0.1214 1.0.1213 1.0.1212 1.0.1211 1.0.1210 1.0.1208 1.0.1206 1.0.1205 1.0.1203 1.0.1202 1.0.1198 1.0.1197 1.0.1196 1.0.1195 1.0.1193 1.0.1192 1.0.1191 1.0.1190 1.0.1189 1.0.1188 1.0.1187 1.0.1186 1.0.1185 1.0.1183 1.0.1182 1.0.1178 1.0.1177 1.0.1176 1.0.1175 1.0.1174 1.0.1173 1.0.1171 1.0.1170 1.0.1169 1.0.1168 1.0.1167 1.0.1164 1.0.1163 1.0.1162 1.0.1161 1.0.1160 1.0.1159 1.0.1158 1.0.1157 1.0.1156 1.0.1155 1.0.1154 1.0.1153 1.0.1152 1.0.1151 1.0.1150 1.0.1149 1.0.1148 1.0.1147 1.0.1145 1.0.1144 1.0.1143 1.0.1142 1.0.1141 1.0.1140 1.0.1139 1.0.1138 1.0.1137 1.0.1136 1.0.1135 1.0.1133 1.0.1132 1.0.1131 1.0.1130 1.0.1129 1.0.1128 1.0.1127 1.0.1126 1.0.1125 1.0.1124 1.0.1123 1.0.1122 1.0.1121 1.0.1120 1.0.1119 1.0.1118 1.0.1117 1.0.1116 1.0.1114 1.0.1113 1.0.1112 1.0.1111 1.0.1110 1.0.1109 1.0.1108 1.0.1107 1.0.1106 1.0.1105 1.0.1104 1.0.1103 1.0.1102 1.0.1101 1.0.1100 1.0.1099 1.0.1098 1.0.1097 1.0.1096 1.0.1095 1.0.1093 1.0.1092 1.0.1091 1.0.1090 1.0.1089 1.0.1088

SDK for Gamend hooks development. Provides type specs, documentation, and IDE autocomplete for Gamend modules without requiring the full server.

Current section

Files

Jump to
gamend_sdk README.md
Raw

README.md

# Gamend SDK

SDK for Gamend hooks development. This package provides type specs, documentation,
and IDE autocomplete for Gamend modules without requiring the full server.

## Installation

Add `gamend_sdk` to your list of dependencies in `mix.exs`:

```elixir
def deps do
  [
    {:gamend_sdk, "~> 0.1.0", runtime: false, optional: true}
  ]
end
```

## Usage

This SDK provides stub modules that match the Gamend API:

### Core Modules

- `Gamend.Accounts` - User account management (registration, login, profile updates, metadata)
- `Gamend.Lobbies` - Lobby management (create, join, leave, kick, host transfer)
- `Gamend.Groups` - Group management (create, join, leave, invite, promote/demote, join requests)
- `Gamend.Parties` - Ephemeral party management (create, invite, lobby integration)
- `Gamend.Leaderboards` - Leaderboard operations (submit scores, rankings, seasonal resets)
- `Gamend.Friends` - Friend relationships and blocking (send/accept/decline requests, block/unblock)
- `Gamend.Notifications` - In-app notification delivery (friend requests, group invites, system alerts)
- `Gamend.KV` - Generic key/value storage (server-side persistent storage for game data)
- `Gamend.Schedule` - Dynamic cron-like job scheduling for hooks

### Behaviour & Types

- `Gamend.Hooks` - Hook behaviour for custom game logic (lifecycle callbacks, RPC functions)
- `Gamend.Types` - Shared types used across Gamend contexts

### Implementing Hooks

Create your hooks module using `use Gamend.Hooks` to get default implementations
for all callbacks, then override only the ones you need:

```elixir
defmodule MyGame.Hooks do
  use Gamend.Hooks

  @impl true
  def after_user_register(user) do
    # Give new users starting coins
    Gamend.Accounts.update_user(user, %{
      metadata: Map.put(user.metadata || %{}, "coins", 100)
    })
  end

  @impl true
  def before_group_create(user, attrs) do
    # Check if user has enough coins to create a group
    coins = get_in(user.metadata, ["coins"]) || 0
    if coins >= 50, do: {:ok, attrs}, else: {:error, :not_enough_coins}
  end

  @impl true
  def before_lobby_join(user, lobby, opts) do
    # Check level requirements
    {:ok, {user, lobby, opts}}
  end

  # Custom RPC - callable from game clients
  def give_coins(amount, _opts) do
    caller = Gamend.Hooks.caller_user()
    coins = get_in(caller.metadata, ["coins"]) || 0
    Gamend.Accounts.update_user(caller, %{
      metadata: Map.put(caller.metadata, "coins", coins + amount)
    })
  end
end
```

### Module APIs

The SDK modules provide the same API as the real Gamend:

```elixir
# Get user by ID (returns nil if not found)
user = Gamend.Accounts.get_user(user_id)

# Update user metadata
{:ok, user} = Gamend.Accounts.update_user(user, %{metadata: %{level: 5}})

# Submit leaderboard score
{:ok, record} = Gamend.Leaderboards.submit_score(leaderboard_id, user_id, 1000)

# Get lobby members
members = Gamend.Lobbies.get_lobby_members(lobby)
```

## Note

This SDK only provides type specifications and documentation for IDE support.
The actual implementations run on the Gamend - these stubs will raise
`RuntimeError` if called directly.