Skip to content
PsychoGoldfishNG edited this page Aug 18, 2022 · 36 revisions

File: /NGIO.cs
Static Class
A static wrapper for the NewgroundsIO library.

Public Constants

PERIOD_ALL_TIME

string: "A"

PERIOD_CURRENT_MONTH

string: "M"

PERIOD_CURRENT_WEEK

string: "W"

PERIOD_CURRENT_YEAR

string: "Y"

PERIOD_TODAY

string: "D"

STATUS_CHECKING_LOCAL_VERSION

string: "checking-local-version"

STATUS_EXCEEDED_MAX_ATTEMPTS

string: NewgroundsIO.SessionState.EXCEEDED_MAX_ATTEMPTS

STATUS_INITIALIZED

string: "initialized"

STATUS_ITEMS_PRELOADED

string: "items-preloaded"

STATUS_LOCAL_VERSION_CHECKED

string: "local-version-checked"

STATUS_LOGIN_CANCELLED

string: NewgroundsIO.SessionState.LOGIN_CANCELLED

STATUS_LOGIN_FAILED

string: NewgroundsIO.SessionState.LOGIN_FAILED

STATUS_LOGIN_REQUIRED

string: NewgroundsIO.SessionState.LOGIN_REQUIRED

STATUS_LOGIN_SUCCESSFUL

string: NewgroundsIO.SessionState.LOGIN_SUCCESSFUL

STATUS_PRELOADING_ITEMS

string: "preloading-items"

STATUS_READY

string: "ready"

STATUS_SERVER_UNAVAILABLE

string: NewgroundsIO.SessionState.SERVER_UNAVAILABLE

STATUS_SESSION_UNINITIALIZED

string: NewgroundsIO.SessionState.SESSION_UNINITIALIZED

STATUS_USER_LOGGED_OUT

string: NewgroundsIO.SessionState.USER_LOGGED_OUT

STATUS_WAITING_FOR_SERVER

string: NewgroundsIO.SessionState.WAITING_FOR_SERVER

STATUS_WAITING_FOR_USER

string: NewgroundsIO.SessionState.WAITING_FOR_USER

Public Static Properties

gatewayVersion

Type: (string)
The current version of the Newgrounds.io gateway.

hasSession

Type: (bool)
Returns true if we currently have a valid session ID.

hasUser

Type: (bool)
Returns true if we currently have a valid session ID.

isDeprecated

Type: (bool)
Will be set to true if this is an out-of-date copy of the game.

isInitialized

Type: (bool)
Will be true if we've called Init().

isReady

Type: (bool)
Will be true if we've finished logging in and preloading data.

lastBoardPosted

Type: (NewgroundsIO.objects.ScoreBoard)
Stores the last scoreboard that was posted to.

lastConnectionStatus

Type: (string)
Contains the last connection status. Value will be one of the STATUS_XXXXX constants.

lastDateTime

Type: (string)
Stores the last DateTime that was loaded from the API.

lastExecution

Type: (DateTime)
The last time a component or queue was executed

lastGetScoresResult

Type: (NewgroundsIO.results.ScoreBoard.getScores)
Stores the last scores that were loaded.

lastLoggedEvent

Type: (string)
Stores the last event that was logged

lastMedalUnlocked

Type: (NewgroundsIO.objects.Medal)
Stores the last medal that was unlocked.

lastPingSuccess

Type: (bool)
Stores wether the last server ping succeeded.

lastSaveSlotLoaded

Type: (NewgroundsIO.objects.SaveSlot)
Stores the last saveSlot that had data loaded.

lastSaveSlotSaved

Type: (NewgroundsIO.objects.SaveSlot)
Stores the last saveSlot that had data saved.

lastScorePosted

Type: (NewgroundsIO.objects.Score)
Stores the last score that was posted to.

lastTimeStamp

Type: (int)
Stores the last unix timestamp that was loaded API.

legalHost

Type: (bool)
Will be set to false if the local copy of the game is being hosted illegally.

loginPageOpen

Type: (bool)
Will be true if the user opened the login page via OpenLoginPage().

medalScore

Type: (int)
The user's overall Newgrounds medal score

medals

Type: (Dictionary<int, NewgroundsIO.objects.Medal>)
A dictionary of any preloaded medals, keyed on medal ids

newestVersion

Type: (string)
This is the version number(string) of the newest available copy of the game.

ngioCore

Type: (NewgroundsIO.Core)
A reference to the NewgroundsIO.Core instance created in Init().

saveSlots

Type: (Dictionary<int, NewgroundsIO.objects.SaveSlot>)
A dictionary of any preloaded medals, keyed on the save slot number

scoreBoards

Type: (Dictionary<int, NewgroundsIO.objects.ScoreBoard>)
A dictionary of any preloaded medals, keyed on scoreboard ids

session

Type: (NewgroundsIO.objects.Session)
Contains all information about the current user session.

sessionError

Type: (NewgroundsIO.objects.Error)
Will be null unless there was an error in our session.

user

Type: (NewgroundsIO.objects.User)
Contains user information if the user is logged in. Otherwise null.

Public Static Methods

CancelLogin

void CancelLogin()

If the user opened the NG login page, you can call this to cancel the login attempt.

GetMedal

NewgroundsIO.objects.Medal GetMedal(int medalID)

Gets a preloaded Medal object.

Parameters:

  • medalID (int)
    The ID of the medal

Returns NewgroundsIO.objects.Medal

GetSaveSlot

NewgroundsIO.objects.SaveSlot GetSaveSlot(int slotID)

Gets a preloaded SaveSlot object. (Use GetSaveSlotData to get actual save file)

Parameters:

  • slotID (int)
    The desired slot number

Returns NewgroundsIO.objects.SaveSlot

GetScoreBoard

NewgroundsIO.objects.ScoreBoard GetScoreBoard(int boardID)

Gets a preloaded ScoreBoard object.

Parameters:

  • boardID (int)
    The ID of the score board

Returns NewgroundsIO.objects.ScoreBoard

GetTotalSaveSlots

short GetTotalSaveSlots()

Gets the number of non-empty save slots.

Returns short

Init

void Init(string appID, string aesKey, Dictionary<string, object> options = null)

Initializes the NGIO wrapper. You must call this BEFORE using any other methods!

Parameters:

  • appID (string)
    The App ID from your Newgrounds Project's "API Tools" page.

  • aesKey (string)
    The AES-128 encryption key from your Newgrounds Project's "API Tools" page.

  • options (Dictionary<string, object>)
    A dictionary of option names and values. Options are:

    • "debugMode" - Set to true to run in debug mode.
    • "version" - A string in "X.X.X" format indicating the current version of this game.
    • "checkHostLicense" - Set to true to check if the site hosting your game has been blocked.
    • "preloadMedals" - Set to true to preload medals (will show if the player has any unlocked, and get their current medal score).
    • "preloadeScoreBoards" - Set to true to preload Score Board information.
    • "preloadeSaveSlots" - Set to true to preload Save Slot information.
    • "autoLogNewView" - Set to true to automatcally log a new view to your stats.

LoadAuthorUrl

void LoadAuthorUrl()

Loads "Your Website URL", as defined on your App Settings page, in a new browser tab.

LoadMoreGames

void LoadMoreGames()

Loads the Games page on Newgrounds in a new browser tab.

LoadNewgrounds

void LoadNewgrounds()

Loads the Newgrounds frontpage in a new browser tab.

LoadOfficialUrl

void LoadOfficialUrl()

Loads our "Official Version URL", as defined on your App Settings page, in a new browser tab.

LoadReferral

void LoadReferral(string referralName)

Parameters:

  • referralName (string)

OpenLoginPage

void OpenLoginPage()

Opens the Newgrounds login page in a new browser tab.

SkipLogin

void SkipLogin()

Call this if you want to skip logging the user in.

Public Static Coroutines

GetConnectionStatus

IEnumerator GetConnectionStatus(Action handler)

Parameters:

  • handler (Action)

LogOut

IEnumerator LogOut()

Logs the current use out of the game (locally and on the server) and resets the connection status.

KeepSessionAlive

IEnumerator KeepSessionAlive()

GetSaveSlotData

IEnumerator GetSaveSlotData(int slotID, Action callback)

Loads the actual save file from a save slot, and passes the string result to a callback function.

Parameters:

  • slotID (int)
    The slot number to load from

  • callback (Action)
    A function to run when the file has been loaded

SetSaveSlotData

IEnumerator SetSaveSlotData(int slotID, string data, Action<NewgroundsIO.objects.SaveSlot> callback = null)

Loads the actual save file from a save slot and returns the save slot to an optional callback function when complete.

Parameters:

  • slotID (int)
    The slot number to save to.

  • data (string)
    The (serialized) data you want to save.

  • callback (Action<NewgroundsIO.objects.SaveSlot>)
    A function to run when the file finished saving.

LogEvent

IEnumerator LogEvent(string eventName, Action callback = null)

Logs a custom event and returns the eventName to an optional callback function when complete.

Parameters:

  • eventName (string)
    The name of the event to log.

  • callback (Action)
    A function to run when the event has logged.

GetDateTime

IEnumerator GetDateTime(Action<string, int> callback = null)

Loads the current DateTime from the server and returns it to an optional callback function.

Parameters:

  • callback (Action<string, int>)
    A function to run when the medal has unlocked.

UnlockMedal

IEnumerator UnlockMedal(int medalID, Action<NewgroundsIO.objects.Medal> callback = null)

Attempts to unlock a medal and returns the medal to an optional callback function when complete.

Parameters:

  • medalID (int)
    The id of the medal you are unlocking.

  • callback (Action<NewgroundsIO.objects.Medal>)
    A function to run when the medal has unlocked.

PostScore

IEnumerator PostScore(int boardID, int value, string tag = null, Action<NewgroundsIO.objects.ScoreBoard, NewgroundsIO.objects.Score> callback = null)

Posts a score and returns the score and scoreboard to an optional callback function when complete.

Parameters:

  • boardID (int)
    The id of the scoreboard you are posting to.

  • value (int)
    The integer value of your score.

  • tag (string)
    An optional tag to attach to the score (use null for no tag).

  • callback (Action<NewgroundsIO.objects.ScoreBoard, NewgroundsIO.objects.Score>)
    A function to run when the score has posted.

GetScores

IEnumerator GetScores(int boardID, string period = "D", string tag = null, bool social = false, Action<NewgroundsIO.objects.ScoreBoard, List<NewgroundsIO.objects.Score>, string, string, bool> callback = null)

Gets the best scores for a board and returns the board, score list, period, tag and social bool to an optional callback.

Parameters:

  • boardID (int)
    The id of the scoreboard you loading from.

  • period (string)
    The time period to get scores from. Will match one of the PERIOD_XXXX constants.

  • tag (string)
    An optional tag to filter results by (use null for no tag).

  • social (bool)
    Set to true to only get scores from the user's friends.

  • callback (Action<NewgroundsIO.objects.ScoreBoard, List<NewgroundsIO.objects.Score>, string, string, bool>)
    A function to run when the scores have been loaded.

Clone this wiki locally