### Install Electron Quick Start dependencies
Source: https://github.com/greenheartgames/greenworks/blob/master/docs/build-instructions-electron.md
Install the necessary npm modules for the Electron Quick Start application.
```shell
npm install
```
--------------------------------
### Start Electron Quick Start
Source: https://github.com/greenheartgames/greenworks/blob/master/docs/build-instructions-electron.md
Verify that the Electron Quick Start application works before proceeding with Greenworks installation.
```shell
npm start
```
--------------------------------
### Cloning Electron Quick Start
Source: https://github.com/greenheartgames/greenworks/blob/master/docs/build-instructions-electron.md
Clone the Electron Quick Start repository to follow along with the build instructions.
```shell
git clone https://github.com/electron/electron-quick-start.git
cd electron-quick-start
```
--------------------------------
### Install electron-rebuild
Source: https://github.com/greenheartgames/greenworks/blob/master/docs/build-instructions-electron.md
Install electron-rebuild as a development dependency to rebuild native modules.
```shell
npm install --save-dev electron-rebuild
```
--------------------------------
### Install Greenworks (initial)
Source: https://github.com/greenheartgames/greenworks/blob/master/docs/build-instructions-electron.md
Install Greenworks from its GitHub repository. This step is for demonstration and requires Steamworks SDK later.
```shell
npm install --save --ignore-scripts git+https://github.com/greenheartgames/greenworks.git
```
--------------------------------
### Minimal App - index.html
Source: https://github.com/greenheartgames/greenworks/blob/master/docs/quick-start-nwjs.md
The HTML file for a minimal 'hello-world' application using Greenworks in NW.js.
```html
Hello Greenworks
Greenworks Test
SteamAPI Init:
```
--------------------------------
### Minimal App - package.json
Source: https://github.com/greenheartgames/greenworks/blob/master/docs/quick-start-nwjs.md
The package.json file for a minimal 'hello-world' application using Greenworks in NW.js.
```json
{
"name": "greenworks-nw-demo",
"main": "index.html"
}
```
--------------------------------
### Get Encrypted App Ticket and Decrypt
Source: https://github.com/greenheartgames/greenworks/blob/master/docs/authentication.md
Example of obtaining an encrypted app ticket, decrypting it with a secret key, and verifying its contents.
```javascript
var greenworks = require('./greenworks');
greenworks.init();
greenworks.getEncryptedAppTicket('test_content', function(ticket) {
console.log("ticket: " + ticket.toString('hex'));
// Specify the secret key.
var key = new Buffer(32);
// TODO: you must initialize Buffer key with the secret key of your game here,
// e.g. key = new Buffer([0x0a, ..., 0x0b]).
assert(key.length == greenworks.EncryptedAppTicketSymmetricKeyLength)
var decrypted_app_ticket = greenworks.decryptAppTicket(ticket, key);
if (decrypted_app_ticket) {
console.log(greenworks.isTicketForApp(decrypted_app_ticket,
greenworks.getAppId()));
console.log(greenworks.getTicketAppId(decrypted_app_ticket));
console.log(greenworks.getTicketSteamId(decrypted_app_ticket));
console.log(greenworks.getTicketIssueTime(decrypted_app_ticket));
}
}, function(err) { throw err; });
```
--------------------------------
### Building with node-gyp
Source: https://github.com/greenheartgames/greenworks/blob/master/docs/build-instructions-electron.md
Install dependencies and build Greenworks using node-gyp for a specific Electron version.
```shell
cd
# install dependencies of Greenworks, "nan" module.
npm install
HOME=~/.electron-gyp node-gyp rebuild --target=<1.2.3 or other versions> --arch=x64 --dist-url=https://atom.io/download/atom-shell
```
--------------------------------
### Initialize Steam API
Source: https://github.com/greenheartgames/greenworks/blob/master/docs/readme.md
Example of how to initialize the Steam API using the greenworks module.
```javascript
var greenworks = require('./greenworks');
if (greenworks.init())
console.log('Steam API has been initialized.');
```
--------------------------------
### Example Usage
Source: https://github.com/greenheartgames/greenworks/blob/master/docs/events.md
Demonstrates how to initialize greenworks and listen for various Steam events like game overlay activation, server connections/disconnections, and Steam shutdown.
```javascript
var greenworks = require('greenworks');
// Required to do initialized stuff before using greenworks' APIs.
greenworks.init();
function log(msg) {
console.log(msg);
}
greenworks.on('game-overlay-activated', function(is_active) {
if (is_active)
log('game overlay is activated');
else
log('game overlay is deactivated');
});
greenworks.on('steam-servers-connected', function() { log('connected')});
greenworks.on('steam-servers-disconnected', function() { log('disconnected')});
greenworks.on('steam-server-connect-failure', function() { log('connected failure')});
greenworks.on('steam-shutdown', function() { log('shutdown')});
```
--------------------------------
### NW.js Window Configuration
Source: https://github.com/greenheartgames/greenworks/blob/master/docs/troubleshooting.md
Example package.json configuration for NW.js window properties.
```json
"window": {
"toolbar": false,
"fullscreen": true,
"frame": false,
// "transparent": true, // now should work correctly
"no-edit-menu" : true
},
```
--------------------------------
### Saving friend avatar to PNG
Source: https://github.com/greenheartgames/greenworks/blob/master/docs/setting.md
An example of how to retrieve a friend's small avatar, get its RGBA image data and dimensions, and save it as a PNG file using the 'jimp' module.
```javascript
var greeenworks = require('./greenworks');
// Relies on 'jimp' module. Install it via 'npm install jimp'.
var Jimp = require('jimp');
var friends = greenworks.getFriends(greenworks.FriendFlags.Immediate);
if (friends.length > 0) {
var handle = greenworks.getSmallFriendAvatar(friends[0].getRawSteamID());
if (!handle) {
console.log("The user don't set small avartar");
return;
}
var image_buffer = greenworks.getImageRGBA(handle);
var size = greenworks.getImageSize(handle);
if (!size.height || !size.width) {
console.log("Image corrupted. Please try again");
return;
}
console.log(size);
var image = new Jimp(size.height, size.width, function (err, image) {
for (var i = 0; i < size.height; ++i) {
for (var j = 0; j < size.width; ++j) {
var idx = 4 * (i * size.height + j);
var hex = Jimp.rgbaToInt(image_buffer[idx], image_buffer[idx+1],
image_buffer[idx+2], image_buffer[idx+3]);
image.setPixelColor(hex, j, i);
}
}
});
image.write("/tmp/test.png");
}
```
--------------------------------
### Friends API Example
Source: https://github.com/greenheartgames/greenworks/blob/master/docs/friends.md
This example demonstrates how to initialize Greenworks, listen for persona state changes and chat messages, and retrieve friend information.
```javascript
var greenworks = require('./greenworks');
if (greenworks.init()) {
greenworks.on('persona-state-change',
function(steam_id, persona_change_flag) {
if (persona_change_flag == greenworks.PersonaChange.Name)
console.log("Change to new name: " + steam_id.getPersonaName());
});
greenworks.on('game-connected-friend-chat-message',
function(steam_id, message_id) {
var info = greenworks.getFriendMessage(steam_id.getRawSteamID(), message_id,
2048);
if (info.chatEntryType == greenworks.ChatEntryType.ChatMsg) {
var message = info.message;
console.log("Receive a message from " + steam_id.getPersonaName() + ": " +
message);
greenworks.replyToFriendMessage(steam_id.getRawSteamID(),
"Hello, I received your message.");
}
});
// Listen to messages from friends.
greenworks.setListenForFriendsMessage(true);
// Get the number of regular friends.
console.log(greenworks.getFriendCount(greenworks.FriendFlags.Immediate));
var friends = greenworks.getFriends(greenworks.FriendFlags.Immediate);
for (var i = 0; i < friends.length; ++i) {
console.log(friends[i].getPersonaName());
greenworks.requestUserInformation(friends[i].getRawSteamID(), true);
}
}
```
--------------------------------
### Force Refresh Canvas for Steam Overlay
Source: https://github.com/greenheartgames/greenworks/blob/master/docs/troubleshooting.md
Example HTML and JavaScript to force redraws for the Steam Overlay.
```html
```
--------------------------------
### Create steam_appid.txt
Source: https://github.com/greenheartgames/greenworks/blob/master/docs/build-instructions-electron.md
Create a steam_appid.txt file with the Steam AppID for testing purposes (e.g., 480 for Spacewar).
```shell
echo 480 > steam_appid.txt
```
--------------------------------
### Replace renderer.js (Windows)
Source: https://github.com/greenheartgames/greenworks/blob/master/docs/build-instructions-electron.md
Replace the default renderer.js with the Greenworks main.js sample for testing on Windows.
```shell
move renderer.js renderer.original.js
copy node_modules\greenworks\samples\electron\main.js renderer.js
```
--------------------------------
### Replace renderer.js (Linux/macOS)
Source: https://github.com/greenheartgames/greenworks/blob/master/docs/build-instructions-electron.md
Replace the default renderer.js with the Greenworks main.js sample for testing.
```shell
mv renderer.js renderer.original.js
cp node_modules/greenworks/samples/electron/main.js renderer.js
```
--------------------------------
### Run electron-rebuild (Linux/macOS)
Source: https://github.com/greenheartgames/greenworks/blob/master/docs/build-instructions-electron.md
Execute electron-rebuild to rebuild the native module.
```shell
node_modules/.bin/electron-rebuild
```
--------------------------------
### Run electron-rebuild (Windows)
Source: https://github.com/greenheartgames/greenworks/blob/master/docs/build-instructions-electron.md
Execute electron-rebuild on Windows to rebuild the native module.
```shell
node_modules\.bin\electron-rebuild
```
--------------------------------
### package.json Configuration for Game-Overlay
Source: https://github.com/greenheartgames/greenworks/blob/master/samples/nw.js/readme.md
This snippet shows the required configuration in package.json to enable the game-overlay feature on Windows by customizing chromium-args.
```json
"chromium-args": "--in-process-gpu --disable-transparency"
```
--------------------------------
### Initialization and Status APIs
Source: https://github.com/greenheartgames/greenworks/blob/master/CHANGELOG.md
APIs for initializing Greenworks and checking Steam status.
```javascript
greeworks.init
greenworks.restartAppIfNecessary
greenworks.isSubscribedApp
greenworks.isSteamRunning
```
--------------------------------
### Publish Workshop File API
Source: https://github.com/greenheartgames/greenworks/wiki/WorkShop-APIs
Publishes a workshop item to Steam, requiring the file and image to be on Steam Cloud and shared.
```javascript
greenworks.publishWorkshopFile(file_path, image_path, title, description, success_callback, [error_callback])
```
--------------------------------
### Run Mocha Tests
Source: https://github.com/greenheartgames/greenworks/blob/master/docs/mocha-test.md
Command to navigate to the Greenworks source directory and run the Mocha tests.
```shell
cd
./test/run-test
```
--------------------------------
### File Share API
Source: https://github.com/greenheartgames/greenworks/wiki/WorkShop-APIs
Shares a file on Steam, returning a file handle for sharing with users and features.
```javascript
greenworks.fileShare(file_path, success_callback, [error_callback])
```
--------------------------------
### Activate Game Overlay to Store API
Source: https://github.com/greenheartgames/greenworks/blob/master/CHANGELOG.md
API added in v0.16.0 to activate the game overlay to the store page.
```javascript
greenworks.activateGameOverlayToStore
```
--------------------------------
### New APIs in v0.15.0
Source: https://github.com/greenheartgames/greenworks/blob/master/CHANGELOG.md
Various new APIs added in version 0.15.0.
```javascript
greenworks.isSteamRunningOnSteamDeck()
greenworks.indicateAchievementProgress(achievement, current, max)
greenworks.getFriendGamePlayed(steamIDFriend)
greenworks.getLaunchCommandLine()
greenworks.getFriendPersonaName(raw_steam_id)
greenworks.setRichPresence(pchKey, pchValue)
greenworks.ClearRichPresence()
greenworks.getFriendRichPresence(steamIDFriend, pchKey)
greenworks.setPlayedWith(steamIDUserPlayedWith)
greenworks.activateGameOverlayInviteDialog(steamIDLobby)
greenworks.activateGameOverlayToUser(pchDialog, CSteamID steamID)
greenworks.createLobby(lobbyType, maxMembers)
greenworks.deleteLobbyData(steamIDLobby, pchKey)
greenworks.getLobbyByIndex(iLobby)
greenworks.getLobbyData(steamIDLobby, pchKey)
greenworks.getLobbyMemberByIndex(steamIDLobby, iMember)
greenworks.getNumLobbyMembers(steamIDLobby)
greenworks.getLobbyOwner(steamIDLobby)
greenworks.inviteUserToLobby(steamIDLobby, steamIDInvitee)
greenworks.joinLobby(steamIDLobby)
greenworks.leaveLobby(steamIDLobby)
greenworks.setLobbyData(steamIDLobby, pchKey, pchValue)
greenworks.setLobbyJoinable(steamIDLobby, bLobbyJoinable)
greenworks.setLobbyOwner(steamIDLobby, steamIDNewOwner)
greenworks.setLobbyType(steamIDLobby, eLobbyType)
greenworks.ugcGetItemState(published_file_id)
greenworks.ugcGetItemInstallInfo(published_file_id)
greenworks.getIPCountry()
greenworks.isSteamInBigPictureMode()
greenworks.getDLCDataByIndex(index)
greenworks.getAppBuildId()
greenworks.isAppInstalled(appId)
greenworks.getAppInstallDir(app_id, buffer, buffer_size)
```
--------------------------------
### Update Published Workshop File API
Source: https://github.com/greenheartgames/greenworks/wiki/WorkShop-APIs
Updates an existing published workshop file. Empty strings for fields mean no update.
```javascript
greenworks.updatePublishedWorkshopFile(published_file_handle, file_path, image_path, title, description, success_callback, [error_callback])
```
--------------------------------
### New Authentication APIs
Source: https://github.com/greenheartgames/greenworks/blob/master/CHANGELOG.md
APIs added in v0.22.0 for managing authentication sessions.
```javascript
greenworks.beginAuthSessionAsUser(ticket, steam_id)
greenworks.endAuthSessionAsUser(steam_id)
greenworks.getAuthSessionTicketForWebAPI(identity, success_callback, [error_callback])
```
--------------------------------
### Show Floating Gamepad Text Input API
Source: https://github.com/greenheartgames/greenworks/blob/master/CHANGELOG.md
API added in v0.17.0 to show a floating gamepad text input.
```javascript
greenworks.showFloatingGamepadTextInput
```