You can choose to build Greenworks with either node-gyp
or electron-rebuild
. If you are unsure, use electron-rebuild
.
First, follow these instructions on getting the Steamworks SDK.
Electron's guide to
using native Node modules
explains that you can use node-gyp
directly with custom settings to build a
native module for a given Electron version.
cd <greenworks_src_dir>
# 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
The --target
is the Electron version you're using (e.g. 1.2.3
), the --arch
may be either ia32
or x64
. (If you want to use 32-bit Electron, we recommend
installing it with the 32-bit version of node.)
After the node-gyp
command is finished, you can find the
greenworks-(linux/win/osx).node
binary (depending on your OS) in
build/Release
.
Greenworks builds a native addon for Node. Addons are very sensitive to which
version of Node you use. For this reason, Electron provides an
electron-rebuild
tool for rebuilding all of the addons in a node_modules
folder. This means
that building and installing Greenworks is a multi-step process.
- For demonstration purposes, we will be using the Electron Quick Start application (You can skip to step 4 if you are following along directly with your own application). Clone it:
git clone https://github.com/electron/electron-quick-start.git
cd electron-quick-start
- Install all of the modules needed for the Electron Quick Start application:
npm install
- Verify that the application works:
npm start
- Now, we can install Greenworks. However, we can't build it yet, because it does not have Steamworks SDK yet:
npm install --save --ignore-scripts git+https://github.com/greenheartgames/greenworks.git
-
Provide the Steamworks SDK dependency to Greenworks by following these steps. (Essentially, You need to create and populate the
node_modules/greenworks/deps/steamworks_sdk
folder.) -
Now, installing Greenworks should succeed:
npm install
- We need to rebuild the module, so install
electron-rebuild
:
npm install --save-dev electron-rebuild
- Then, run it:
node_modules/.bin/electron-rebuild
Or, if you are on Windows:
node_modules\.bin\electron-rebuild
- Finally, create a
steam_appid.txt
in the root of the application with the Steam AppID you want to use. For testing purposes, we can use480
, the AppID for Spacewar, which is the example game included in the Steamworks SDK (Everyone on Steam automatically owns this game by default).
echo 480 > steam_appid.txt
Note the following things about the AppID that you specify in this file:
- The current user logged into Steam must own this AppID, or else the Greenworks initialization will fail.
- Once Greenworks is initialized, Steam will show the current user logged into Steam as "playing" this AppID.
- If you specify the AppID of a different/existing game, after Greenworks is initialized, Steam will prevent the user from opening that game, saying that "that game is already open".
- Overwrite the Electron Quick Start renderer.js with one that does some "Hello World"-style Greenworks code:
mv renderer.js renderer.original.js
cp node_modules/greenworks/samples/electron/main.js renderer.js
Or, if you are on Windows:
move renderer.js renderer.original.js
copy node_modules\greenworks\samples\electron\main.js renderer.js
- Test it:
npm start