This repository was archived by the owner on Mar 18, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Basic usage
yonicstudios edited this page Feb 26, 2017
·
4 revisions
These are examples of how to use gca-node in different contexts/languages.
var gca_node = require('path/to/gca-node.node');
// Find and open the first adapter in your computer.
// If more than 0 Adapters have been found, continue
if(gca_node.Setup()>0) {
// Claim the interface of the adapter.
// We will assign it to a variable to check if it was
// succesfully claimed later on.
var interface_claimed = gca_node.Load();
}
The next code should be executing every in-game unit of time (frame, logic tick, physics tick, etcetera):
// Check if the interface has been claimed before.
if(interface_claimed===0) {
// Get the status of all ports of the adapter
var gamecube_adapter_status = gca_node.Process();
// If the A button of any controller which is connected in the adapter is pressed,
// do something for each specific port.
var i;
for(i=0;i<gamecube_adapter_status.length;i++) {
if(gamecube_adapter_status[i].buttonA) {
do_something(port);
}
}
}
The next code should execute upon closing the game:
var stop_adapter = function() {
// Release the adapter device.
// We will store the result in a variable for handling possible errors.
var code = gca_node.Unload();
if(code===0) {
// Releasing the adapter was succesful.
// Now the device must be closed so that it can be unplugged.
code = gca_node.Stop();
if(code!==0) {
// Closing the adapter was unsuccesful.
throw new Error("CloseError" + code);
}
} else {
// Releasing the adapter was unsuccesful.
// An error must be thrown in order to stop the application and force it
// to release and close the adapter.
throw new Error("UnloadError " + code);
}
}
gca_node = require 'path/to/gca-node.node'
###
Find and open the first adapter in your computer.
If more than 0 Adapters have been found, continue
###
if gca_node.Setup()>0
###
Claim the interface of the adapter.
We will assign a boolean value to check if it was succesfully claimed later on.
###
interface_claimed = gca_node.Load()
The next code should be executing every in-game unit of time (frame, logic tick, physics tick, etcetera):
# Check if the interface has been claimed before.
if interface_claimed is 0
# Get the status of all ports of the adapter.
gamecube_adapter_status = gca_node.Process()
###
If the A button of any controller which is connected in the adapter is pressed,
do something for each specific port.
###
for port in gamecube_adapter_status \
when gamecube_adapter_status[port].buttonA
do_something port
The next code should execute upon closing the game:
stop_adapter = ->
###
Release the adapter device.
We will store the result in a variable for handling possible errors.
###
code = gca_node.Unload()
if code is 0
###
Releasing the adapter was succesful.
Now the device must be closed so that it can be unplugged.
###
code = gca_node.Stop()
if code isnt 0
# Closing the adapter was unsuccesful.
throw new Error "CloseError #{code}"
else
###
Releasing the adapter was unsuccesful.
An error must be thrown in order to stop the application and force it
to release and close the adapter.
###
throw new Error "UnloadError #{code}"
###
We don't want this Coffeescript function to have
any unexpected return values,
so we explicitely return nothing.
###
return