AI2 Component
(Version nb184)
|
Public Member Functions | |
GameClient (ComponentContainer container) | |
String | GameId () |
void | GameId (String id) |
String | InstanceId () |
List< String > | InvitedInstances () |
List< String > | JoinedInstances () |
String | Leader () |
List< String > | Players () |
List< String > | PublicInstances () |
String | ServiceUrl () |
void | ServiceURL (String url) |
String | UserEmailAddress () |
void | UserEmailAddress (String emailAddress) |
void | FunctionCompleted (final String functionName) |
void | Initialize () |
void | GotMessage (final String type, final String sender, final List< Object > contents) |
void | InstanceIdChanged (final String instanceId) |
void | Invited (final String instanceId) |
void | NewLeader (final String playerId) |
void | NewInstanceMade (final String instanceId) |
void | PlayerJoined (final String playerId) |
void | PlayerLeft (final String playerId) |
void | ServerCommandFailure (final String command, final YailList arguments) |
void | ServerCommandSuccess (final String command, final List< Object > response) |
void | UserEmailAddressSet (final String emailAddress) |
void | Info (final String message) |
void | WebServiceError (final String functionName, final String message) |
void | GetInstanceLists () |
void | GetMessages (final String type, final int count) |
void | Invite (final String playerEmail) |
void | LeaveInstance () |
void | MakeNewInstance (final String instanceId, final boolean makePublic) |
void | SendMessage (final String type, final YailList recipients, final YailList contents) |
void | ServerCommand (final String command, final YailList arguments) |
void | SetInstance (final String instanceId) |
void | SetLeader (final String playerEmail) |
void | onResume () |
void | onStop () |
Public Member Functions inherited from com.google.appinventor.components.runtime.AndroidNonvisibleComponent | |
HandlesEventDispatching | getDispatchDelegate () |
Additional Inherited Members | |
Static Public Attributes inherited from com.google.appinventor.components.runtime.Component | |
static final String | ASSET_DIRECTORY = "component" |
static final int | ALIGNMENT_NORMAL = 0 |
static final int | ALIGNMENT_CENTER = 1 |
static final int | ALIGNMENT_OPPOSITE = 2 |
static final int | ACCELEROMETER_SENSITIVITY_WEAK = 1 |
static final int | ACCELEROMETER_SENSITIVITY_MODERATE = 2 |
static final int | ACCELEROMETER_SENSITIVITY_STRONG = 3 |
static final int | BUTTON_SHAPE_DEFAULT = 0 |
static final int | BUTTON_SHAPE_ROUNDED = 1 |
static final int | BUTTON_SHAPE_RECT = 2 |
static final int | BUTTON_SHAPE_OVAL = 3 |
static final int | COLOR_NONE = 0x00FFFFFF |
static final int | COLOR_BLACK = 0xFF000000 |
static final int | COLOR_BLUE = 0xFF0000FF |
static final int | COLOR_CYAN = 0xFF00FFFF |
static final int | COLOR_DKGRAY = 0xFF444444 |
static final int | COLOR_GRAY = 0xFF888888 |
static final int | COLOR_GREEN = 0xFF00FF00 |
static final int | COLOR_LTGRAY = 0xFFCCCCCC |
static final int | COLOR_MAGENTA = 0xFFFF00FF |
static final int | COLOR_ORANGE = 0xFFFFC800 |
static final int | COLOR_PINK = 0xFFFFAFAF |
static final int | COLOR_RED = 0xFFFF0000 |
static final int | COLOR_WHITE = 0xFFFFFFFF |
static final int | COLOR_YELLOW = 0xFFFFFF00 |
static final int | COLOR_DEFAULT = 0x00000000 |
static final String | DEFAULT_VALUE_COLOR_NONE = "&H00FFFFFF" |
static final String | DEFAULT_VALUE_COLOR_BLACK = "&HFF000000" |
static final String | DEFAULT_VALUE_COLOR_BLUE = "&HFF0000FF" |
static final String | DEFAULT_VALUE_COLOR_CYAN = "&HFF00FFFF" |
static final String | DEFAULT_VALUE_COLOR_DKGRAY = "&HFF444444" |
static final String | DEFAULT_VALUE_COLOR_GRAY = "&HFF888888" |
static final String | DEFAULT_VALUE_COLOR_GREEN = "&HFF00FF00" |
static final String | DEFAULT_VALUE_COLOR_LTGRAY = "&HFFCCCCCC" |
static final String | DEFAULT_VALUE_COLOR_MAGENTA = "&HFFFF00FF" |
static final String | DEFAULT_VALUE_COLOR_ORANGE = "&HFFFFC800" |
static final String | DEFAULT_VALUE_COLOR_PINK = "&HFFFFAFAF" |
static final String | DEFAULT_VALUE_COLOR_RED = "&HFFFF0000" |
static final String | DEFAULT_VALUE_COLOR_WHITE = "&HFFFFFFFF" |
static final String | DEFAULT_VALUE_COLOR_YELLOW = "&HFFFFFF00" |
static final String | DEFAULT_VALUE_COLOR_DEFAULT = "&H00000000" |
static final float | FONT_DEFAULT_SIZE = 14 |
static final int | LAYOUT_ORIENTATION_HORIZONTAL = ComponentConstants.LAYOUT_ORIENTATION_HORIZONTAL |
static final int | LAYOUT_ORIENTATION_VERTICAL = ComponentConstants.LAYOUT_ORIENTATION_VERTICAL |
static final int | SCALING_SCALE_PROPORTIONALLY = 0 |
static final int | SCALING_SCALE_TO_FIT = 1 |
static final int | TYPEFACE_DEFAULT = 0 |
static final int | TYPEFACE_SANSSERIF = 1 |
static final int | TYPEFACE_SERIF = 2 |
static final int | TYPEFACE_MONOSPACE = 3 |
static final int | LENGTH_PREFERRED = -1 |
static final int | LENGTH_FILL_PARENT = -2 |
static final int | LENGTH_UNKNOWN = -3 |
static final int | LENGTH_PERCENT_TAG = -1000 |
static final int | TOAST_LENGTH_SHORT = 0 |
static final int | TOAST_LENGTH_LONG = 1 |
static final int | DIRECTION_NORTH = 1 |
static final int | DIRECTION_NORTHEAST = 2 |
static final int | DIRECTION_EAST = 3 |
static final int | DIRECTION_SOUTHEAST = 4 |
static final int | DIRECTION_SOUTH = -1 |
static final int | DIRECTION_SOUTHWEST = -2 |
static final int | DIRECTION_WEST = -3 |
static final int | DIRECTION_NORTHWEST = -4 |
static final int | DIRECTION_NONE = 0 |
static final int | DIRECTION_MIN = -4 |
static final int | DIRECTION_MAX = 4 |
static float | SLIDER_MIN_VALUE = 10 |
static float | SLIDER_MAX_VALUE = 50 |
static float | SLIDER_THUMB_VALUE = (SLIDER_MIN_VALUE + SLIDER_MAX_VALUE) / 2.0f |
static final String | DEFAULT_VALUE_TEXT_TO_SPEECH_COUNTRY = "" |
static final String | DEFAULT_VALUE_TEXT_TO_SPEECH_LANGUAGE = "" |
Protected Member Functions inherited from com.google.appinventor.components.runtime.AndroidNonvisibleComponent | |
AndroidNonvisibleComponent (Form form) | |
Protected Attributes inherited from com.google.appinventor.components.runtime.AndroidNonvisibleComponent | |
final Form | form |
GameClient provides a way for AppInventor applications to communicate with online game servers. This allows users to create games that are coordinated and managed in the cloud.
Most communication is done by sending keyed messages back and forth between the client and the server in the form of YailLists. The server and game client can then switch on the keys and perform more complex operations on the data. In addition, game servers can implement a library of server commands that can perform complex functions on the server and send back responses that are converted into YailLists and sent back to the component. For more information about server commands, consult the game server code at http://code.google.com/p/app-inventor-for-android/
Games instances are uniquely determined by a game id and an instance id. In general, each App Inventor program should have its own game id. Then, when running different instances of that program, new instance ides should be used. Players are represented uniquely by the email address registered to their phones.
All call functions perform POSTs to a web server. Upon successful completion of these POST requests, FunctionCompleted will be triggered with the function name as an argument. If the post fails, WebServiceError will trigger with the function name and the error message as arguments. These calls allow for application creators to deal with web service failures and keep track of the success or failure of their operations. The only exception to this is when the return value from the server has the incorrect game id or instance id. In this case, the response is completely ignored and neither of these events will trigger.
Definition at line 87 of file GameClient.java.
com.google.appinventor.components.runtime.GameClient.GameClient | ( | ComponentContainer | container | ) |
Creates a new GameClient component.
container | the Form that this component is contained in. |
Definition at line 147 of file GameClient.java.
void com.google.appinventor.components.runtime.GameClient.FunctionCompleted | ( | final String | functionName | ) |
Indicates that a server request from a function call has completed. This can be used to control a polling loop or otherwise respond to server request completions.
functionName | The name of the App Inventor function that finished. |
Definition at line 375 of file GameClient.java.
String com.google.appinventor.components.runtime.GameClient.GameId | ( | ) |
Returns a string indicating the game name for this application. The same game ID can have one or more game instances.
Definition at line 193 of file GameClient.java.
void com.google.appinventor.components.runtime.GameClient.GameId | ( | String | id | ) |
Specifies a string indicating the family of the current game instance. The same game ID can have one or more game instance IDs.
Definition at line 207 of file GameClient.java.
void com.google.appinventor.components.runtime.GameClient.GetInstanceLists | ( | ) |
Updates the current InstancesJoined and InstancesInvited lists.
If the player has been invited to new instances an Invited event will be raised for each new instance.
Definition at line 623 of file GameClient.java.
void com.google.appinventor.components.runtime.GameClient.GetMessages | ( | final String | type, |
final int | count | ||
) |
Retrieves messages of the specified type.
Requests that only messages which have not been seen during the current session are returned. Messages will be processed in chronological order with the oldest first, however, only the count newest messages will be retrieved. This means that one could "miss out" on some messages if they request less than the number of messages created since the last request for that message type.
Setting type to the empty string will fetch all message types. Even though those message types were not specifically requested, their most recent message time will be updated. This keeps players from receiving the same message again if they later request the specific message type.
Note that the message receive times are not updated until after the messages are actually received. Thus, if multiple message requests are made before the previous ones return, they could send stale time values and thus receive the same messages more than once. To avoid this, application creators should wait for the get messages function to return before calling it again.
type | The type of message to retrieve. If the empty string is used as the message type then all message types will be requested. |
count | The maximum number of messages to retrieve. This should be an integer from 1 to 1000. |
Definition at line 707 of file GameClient.java.
void com.google.appinventor.components.runtime.GameClient.GotMessage | ( | final String | type, |
final String | sender, | ||
final List< Object > | contents | ||
) |
Indicates that a GetMessages call received a message. This could be invoked multiple times for a single call to GetMessages.
type | The type of the message received. |
contents | The message's contents. Consists of a list nested to arbitrary depth that includes string, boolean and number values. |
Definition at line 404 of file GameClient.java.
void com.google.appinventor.components.runtime.GameClient.Info | ( | final String | message | ) |
Indicates that something has occurred which the player should be somehow informed of.
message | the message. |
Definition at line 584 of file GameClient.java.
void com.google.appinventor.components.runtime.GameClient.Initialize | ( | ) |
Ensures that the GameId was set by the game creator.
Definition at line 386 of file GameClient.java.
String com.google.appinventor.components.runtime.GameClient.InstanceId | ( | ) |
Returns the game instance id. Taken together, the game ID and the instance ID uniquely identify the game.
Definition at line 219 of file GameClient.java.
void com.google.appinventor.components.runtime.GameClient.InstanceIdChanged | ( | final String | instanceId | ) |
Indicates that InstanceId has changed due to the creation of a new instance or setting the InstanceId.
instanceId | The id of the instance the player is now in. |
Definition at line 421 of file GameClient.java.
void com.google.appinventor.components.runtime.GameClient.Invite | ( | final String | playerEmail | ) |
Invites a player to this game instance.
Players implicitly accept invitations when they join games by setting the instance id in their GameClient.
Invitations remain active as long as the game instance exists.
playerEmail | a string containing the email address of the player to become leader. The email should be in one of the following formats: "Name O. Person <name.o.person@gmail.com>" "name.o.person@gmail.com". |
Definition at line 776 of file GameClient.java.
void com.google.appinventor.components.runtime.GameClient.Invited | ( | final String | instanceId | ) |
Indicates a user has been invited to this game instance by another player.
instanceId | The id of the new game instance. |
Definition at line 438 of file GameClient.java.
List<String> com.google.appinventor.components.runtime.GameClient.InvitedInstances | ( | ) |
Returns the set of game instances to which this player has been invited but has not yet joined. To ensure current values are returned, first invoke GetInstanceLists.
Definition at line 233 of file GameClient.java.
List<String> com.google.appinventor.components.runtime.GameClient.JoinedInstances | ( | ) |
Returns the set of game instances in which this player is participating. To ensure current values are returned, first invoke GetInstanceLists.
Definition at line 247 of file GameClient.java.
String com.google.appinventor.components.runtime.GameClient.Leader | ( | ) |
Returns the game's leader. At any time, each game instance has only one leader, but the leader may change with time. Initially, the leader is the game instance creator. Application writers determine special properties of the leader. The leader value is updated each time a successful communication is made with the server.
Definition at line 267 of file GameClient.java.
void com.google.appinventor.components.runtime.GameClient.LeaveInstance | ( | ) |
Requests to leave the current instance. If the player is the current leader, the lead will be passed to another player.
If there are no other players left in the instance after the current player leaves, the instance will become unjoinable.
Upon successful completion of this command, the instance lists will be updated and InstanceId will be set back to the empty string.
Note that while this call does clear the leader and player lists, no NewLeader or PlayerLeft events are raised.
Definition at line 832 of file GameClient.java.
void com.google.appinventor.components.runtime.GameClient.MakeNewInstance | ( | final String | instanceId, |
final boolean | makePublic | ||
) |
Creates a new game instance. The instance has a unique instanceId, and the leader is the player who created it. The player that creates the game automatically joins it without being sent an invitation.
The actual instance id could differ from the instanceId specified because the game server will enforce uniqueness. The actual instanceId will be provided to AppInventor when a NewInstanceMade event triggers upon successful completion of this server request.
instanceId | A string to use as for the instance id. If no other instance exists with this id, the new instance will have this id. However, since the id must be unique, if another instance exists with the same one, then a number will be appended to the end of this prefix. |
makePublic | A boolean indicating whether or not the instance should be publicly viewable and able to be joined by anyone. |
Definition at line 883 of file GameClient.java.
void com.google.appinventor.components.runtime.GameClient.NewInstanceMade | ( | final String | instanceId | ) |
Indicates this game instance was created as specified via MakeNewInstance. The creating player is automatically the leader of the instance and the InstanceId property has already been set to this new instance.
instanceId | The id of the newly created game instance. |
Definition at line 476 of file GameClient.java.
void com.google.appinventor.components.runtime.GameClient.NewLeader | ( | final String | playerId | ) |
Indicates this game instance has a new leader. This could happen in response to a call to SetLeader or by the side effects of a server command performed by any player in the game.
Since the current leader is sent back with every server response, NewLeader can trigger after making any server call.
playerId | The email address of the new leader. |
Definition at line 458 of file GameClient.java.
void com.google.appinventor.components.runtime.GameClient.onResume | ( | ) |
Called automatically by the operating system.
Currently does nothing.
Implements com.google.appinventor.components.runtime.OnResumeListener.
Definition at line 1111 of file GameClient.java.
void com.google.appinventor.components.runtime.GameClient.onStop | ( | ) |
Called automatically by the operating system.
Currently does nothing.
Implements com.google.appinventor.components.runtime.OnStopListener.
Definition at line 1120 of file GameClient.java.
void com.google.appinventor.components.runtime.GameClient.PlayerJoined | ( | final String | playerId | ) |
Indicates that a player has joined this game instance.
playerId | The email address of the new player. |
Definition at line 491 of file GameClient.java.
void com.google.appinventor.components.runtime.GameClient.PlayerLeft | ( | final String | playerId | ) |
Indicates that a player has left this game instance.
playerId | The email address of the player that left. |
Definition at line 508 of file GameClient.java.
List<String> com.google.appinventor.components.runtime.GameClient.Players | ( | ) |
Returns the current set of players for this game instance. Each player is designated by an email address, which is a string. The list of players is updated each time a successful communication is made with the game server.
Definition at line 283 of file GameClient.java.
List<String> com.google.appinventor.components.runtime.GameClient.PublicInstances | ( | ) |
Returns the set of game instances that have been marked public. To ensure current values are returned, first invoke GetInstanceLists.
Definition at line 297 of file GameClient.java.
void com.google.appinventor.components.runtime.GameClient.SendMessage | ( | final String | type, |
final YailList | recipients, | ||
final YailList | contents | ||
) |
Creates a new message and sends it to the stated recipients.
type | A "key" for the message. This identifies the type of message so that when other players receive the message they know how to properly handle it. |
recipients | If set to an empty list, the server will send this message with a blank set of recipients, meaning that all players in the instance are able to retrieve it. To limit the message receipt to a single person or a group of people, recipients should be a list of the email addresses of the people meant to receive the message. Each email should be in one of the following formats: "Name O. Person <name.o.person@gmail.com>" "name.o.person@gmail.com" |
contents | the contents of the message. This can be any AppInventor data value. |
Definition at line 930 of file GameClient.java.
void com.google.appinventor.components.runtime.GameClient.ServerCommand | ( | final String | command, |
final YailList | arguments | ||
) |
Submits a command to the game server. Server commands are custom actions that are performed on the server. The arguments required and return value of a server command depend on its implementation.
For more information about server commands, consult the game server code at: http://code.google.com/p/app-inventor-for-android/
command | The name of the server command. |
arguments | The arguments to pass to the server to specify how to execute the command. |
Definition at line 978 of file GameClient.java.
void com.google.appinventor.components.runtime.GameClient.ServerCommandFailure | ( | final String | command, |
final YailList | arguments | ||
) |
Indicates that an attempt to complete a server command failed on the server.
command | The command requested. |
arguments | The arguments sent to the command. |
Definition at line 524 of file GameClient.java.
void com.google.appinventor.components.runtime.GameClient.ServerCommandSuccess | ( | final String | command, |
final List< Object > | response | ||
) |
Indicates that a ServerCommand completed.
command | The key for the command that resulted in this response. |
response | The server response. This consists of a list nested to arbitrary depth that includes string, boolean and number values. |
Definition at line 543 of file GameClient.java.
String com.google.appinventor.components.runtime.GameClient.ServiceUrl | ( | ) |
The URL of the game server.
Definition at line 307 of file GameClient.java.
void com.google.appinventor.components.runtime.GameClient.ServiceURL | ( | String | url | ) |
Set the URL of the game server.
url | The URL (include initial http://). |
Definition at line 320 of file GameClient.java.
void com.google.appinventor.components.runtime.GameClient.SetInstance | ( | final String | instanceId | ) |
Specifies the game instance id. Taken together, the game ID and the instance ID uniquely identify the game.
instanceId | the name of the game instance to join. |
Definition at line 1021 of file GameClient.java.
void com.google.appinventor.components.runtime.GameClient.SetLeader | ( | final String | playerEmail | ) |
Specifies the game's leader. At any time, each game instance has only one leader, but the leader may change over time. Initially, the leader is the game instance creator. Application inventors determine special properties of the leader.
The leader can only be set by the current leader of the game.
playerEmail | a string containing the email address of the player to become leader. The email should be in one of the following formats: "Name O. Person <name.o.person@gmail.com>" "name.o.person@gmail.com". |
Definition at line 1074 of file GameClient.java.
String com.google.appinventor.components.runtime.GameClient.UserEmailAddress | ( | ) |
Returns the registered email address that is being used as the player id for this game client.
Definition at line 340 of file GameClient.java.
void com.google.appinventor.components.runtime.GameClient.UserEmailAddress | ( | String | emailAddress | ) |
Changes the player of this game by changing the email address used to communicate with the server.
This should only be used during development. Games should not allow players to set their own email address.
emailAddress | The email address to set the current player id to. |
Definition at line 358 of file GameClient.java.
void com.google.appinventor.components.runtime.GameClient.UserEmailAddressSet | ( | final String | emailAddress | ) |
Indicates that the user email address property has been successfully set. This event should be used to initialize any web service functions.
This separate event was required because the email address was unable to be first fetched from the the UI thread without causing programs to hang. GameClient will now start fetching the user email address in its constructor and trigger this event when it finishes.
Definition at line 565 of file GameClient.java.
void com.google.appinventor.components.runtime.GameClient.WebServiceError | ( | final String | functionName, |
final String | message | ||
) |
Indicates that the attempt to communicate with the web service resulted in an error.
functionName | The name of the function call that caused this error. |
message | the error message |
Definition at line 603 of file GameClient.java.