npm package: @skyatnpm/steamworks-js
Description: Modern Steamworks SDK for Node.js and Electron
Author: skyatgit
Latest version: 0.1.0

# steamworks-js

现代化的 Steamworks SDK for Node.js 和 Electron。

[![npm version](https://badge.fury.io/js/steamworks-js.svg)](https://badge.fury.io/js/steamworks-js)
[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)

## ✨ 特性

- 🎮 **完整的 Steamworks API** - 覆盖 Steam SDK 所有 21 个模块，327 个方法
- 📦 **预编译二进制** - 无需编译环境，开箱即用
- 💡 **TypeScript 支持** - 完整的类型定义
- 🖥️ **跨平台** - 支持 Windows、Linux、macOS
- ⚡ **多运行环境** - 支持 Node.js 18+ 和 Electron
- 🔌 **模块化架构** - 按需使用各个模块

## 📦 安装

```bash
npm install steamworks-js
```

## 🚀 快速开始

```typescript
import { SteamClient } from 'steamworks-js';

const steam = new SteamClient();

// 初始化 Steam API (480 是 Spacewar 测试 AppID)
const success = await steam.init(480);

if (success) {
    console.log('Steam ID:', steam.user.getSteamId());
    console.log('用户名:', steam.friends.getPersonaName());
    console.log('等级:', steam.user.getPlayerSteamLevel());
}

// 退出时关闭
process.on('exit', () => steam.shutdown());
```

## 📚 模块列表

### 核心模块

| 模块 | 说明 | 示例 |
|------|------|------|
| `client` | Steam API 初始化/关闭 | `steam.init()` |
| `user` | 用户信息 | `steam.user.getSteamId()` |
| `friends` | 好友系统 | `steam.friends.getPersonaName()` |
| `userStats` | 成就/统计/排行榜 | `steam.userStats.setAchievement()` |
| `utils` | 工具函数 | `steam.utils.getAppId()` |
| `apps` | 应用/DLC 信息 | `steam.apps.isDlcInstalled()` |
| `remoteStorage` | 云存储 | `steam.remoteStorage.fileWrite()` |

### 扩展模块

| 模块 | 说明 | 示例 |
|------|------|------|
| `input` | 手柄/控制器 | `steam.input.getConnectedControllers()` |
| `matchmaking` | 大厅/匹配 | `steam.matchmaking.createLobby()` |
| `ugc` | 创意工坊 | `steam.ugc.getSubscribedItems()` |
| `screenshots` | 截图管理 | `steam.screenshots.triggerScreenshot()` |
| `inventory` | 物品系统 | `steam.inventory.getAllItems()` |
| `music` | Steam 音乐 | `steam.music.play()` |
| `video` | 视频/直播 | `steam.video.isBroadcasting()` |
| `remotePlay` | 远程同乐 | `steam.remotePlay.sendInvite()` |
| `parentalSettings` | 家长控制 | `steam.parentalSettings.isAppBlocked()` |
| `http` | HTTP 请求 | `steam.http.createHTTPRequest()` |
| `timeline` | 时间线 | `steam.timeline.addEvent()` |
| `networking` | P2P 网络 | `steam.networking.sendP2PPacket()` |
| `gameServer` | 游戏服务器 | `steam.gameServer.logOnAnonymous()` |
| `htmlSurface` | HTML 渲染 | `steam.htmlSurface.loadURL()` |

## 📖 使用示例

### 成就系统

```typescript
// 请求当前用户的统计数据
steam.userStats.requestCurrentStats();

// 解锁成就
steam.userStats.setAchievement('ACH_WIN_100_GAMES');

// 更新成就进度
steam.userStats.indicateAchievementProgress('ACH_TRAVEL', 50, 100);

// 保存到 Steam 服务器
steam.userStats.storeStats();
```

### 云存储

```typescript
// 写入文件
steam.remoteStorage.fileWrite('save.dat', Buffer.from('game data'));

// 读取文件
const data = steam.remoteStorage.fileRead('save.dat');

// 检查云存储配额
const quota = steam.remoteStorage.getQuota();
console.log(`已用: ${quota.used} / ${quota.total}`);
```

### 创意工坊

```typescript
// 获取已订阅的 Mod
const items = steam.ugc.getSubscribedItems();

for (const itemId of items) {
    const info = steam.ugc.getItemInstallInfo(itemId);
    if (info) {
        console.log(`Mod 路径: ${info.folder}`);
    }
}
```

### 游戏大厅

```typescript
import { LobbyType } from 'steamworks-js';

// 创建大厅
const callHandle = steam.matchmaking.createLobby(LobbyType.Public, 8);

// 加入大厅
steam.matchmaking.joinLobby(lobbyId);

// 设置大厅数据
steam.matchmaking.setLobbyData(lobbyId, 'gameMode', 'deathmatch');

// 邀请好友
steam.matchmaking.inviteUserToLobby(lobbyId, friendSteamId);
```

### 好友系统

```typescript
// 获取好友列表
const friendCount = steam.friends.getFriendCount();
for (let i = 0; i < friendCount; i++) {
    const friendId = steam.friends.getFriendByIndex(i);
    const name = steam.friends.getFriendPersonaName(friendId);
    console.log(`好友: ${name}`);
}

// 设置富存在
steam.friends.setRichPresence('status', '在主菜单');
steam.friends.setRichPresence('steam_player_group', lobbyId.toString());

// 打开 Steam 覆盖层
steam.friends.activateGameOverlay('friends');
```

## ⚙️ 配置

### steam_appid.txt

在项目根目录创建 `steam_appid.txt` 文件，写入你的 App ID：

```
480
```

> 480 是 Spacewar 测试游戏的 App ID，开发时可以使用。

### Electron 配置

```javascript
// main.js
const { app } = require('electron');
const { SteamClient } = require('steamworks-js');

const steam = new SteamClient();

app.on('ready', async () => {
    await steam.init();
    // ...
});

app.on('quit', () => {
    steam.shutdown();
});
```

## 🔧 开发

### 从源码构建

```bash
# 克隆仓库
git clone https://github.com/skyatgit/steamworks-js.git
cd steamworks-js

# 安装依赖
npm install

# 构建原生模块
npm run build:native

# 构建 TypeScript
npm run build
```

### 运行测试

```bash
npm test
```

## 📄 许可证

MIT License

**注意**: `sdk/` 目录包含 Valve 的 Steamworks SDK 文件，其使用受 [Steamworks SDK 许可协议](https://partner.steamgames.com/doc/sdk/uploading) 约束。

## 🔗 相关链接

- [Steam 开发者文档](https://partner.steamgames.com/doc/home)
- [Steamworks SDK 下载](https://partner.steamgames.com/downloads/list)
- [问题反馈](https://github.com/skyatgit/steamworks-js/issues)