One of the nicest features in the PlayXPert in-game browser is the ability to store settings, widgets and applications globally so no matter where you are, what computer you’re using, PXP always looks and feels the way it should. Find out how the PlayXPert team accomplishes this in the latest WarCry exclusive developer diary.
If you’ve been following this series of articles, you already know that PlayXpert is an open-architecture platform that allows developers to write applications (called widgets) that interact with the user while inside a game. Last month we discussed how to put together a basic widget. This month we start a series of articles examining specific features that the PlayXpert platform makes available to widget developers, starting with the SettingsStore.
When building any application, one of the first things a developer must decide is how they will store the user’s preferences, and how those preferences will be imported and exported to other PCs. We wanted PlayXpert to be player-centric, so we wanted the user to be able to easily move from PC to PC, without having to setting up each PC. At the same time, we want PlayXpert to be developer-friendly.
So, PlayXpert allows users to carry their application preferences with them through our global persistent identify – for example if a user installs a widget on their Desktop machine, and then logs on to PXP on his or her laptop, the same widget will be automatically downloaded and installed on the laptop because it’s associated to that users identity. For developers, PlayXpert makes this functionality available through the ISettingsStore interface. All settings names are isolated to a specific widget, so you don’t have to worry about setting name clashes with other widgets. The SettingsStore handles all caching and retrieval of settings for you – you don’t need to worry about initializing it or shutting it down, or giving it time to write settings to the server. It’s all handled for you!
To use the SettingsStore, call GetSettingsStore() from the ICore interface (remember that your widget is given a reference to an ICore interface when it is first loaded). This will return a reference to an object that implements ISettingsStore.
You can read and write string values with the ReadSettingsValue() and WriteSettingsValue() methods.
Local vs. Global
The SettingsStore also allows you to store information that will be different for each machine on which PlayXpert is used. So, one of the things that you will have to decide when using the SettingsStore is whether the information you’re storing:
1. should be stored globally, and follow the user onto any PC on which the user logs in to PlayXpert; or,
2. should be stored local to this rig, and should not follow the user to any PC on which they play.
For example, a history of viewed pages in a browser should be stored globally, because the information is not related to a specific PC – so the user probably wouldn’t need different histories on different PCs. On the other hand, a Volume Control widget would probably store its volume settings locally, because they are related to the hardware on which the user is playing. We wouldn’t want the user’s laptop volume settings (probably turned up loud), to be propagated to his or her desktop machine, and blow their eardrums out ). You may even want to let the user decide whether they want settings stored locally or globally – just make sure you store their local vs. global choice, globally.
So, the SettingsStore makes it possible to deal with both of these situations. Any given setting value can be stored Locally or Globally, independent of all the other settings.
Serializing Whole Objects
The SettingsStore also allows widget developers to store whole objects with one call. For example, consider a simple class that contains contact information:
public class Contact
{
public string Name;
public string PlayerName;
public string FavoriteServer;
}
Normally we would have to store each field in this object with a series of calls. But, by adding some attributes to the fields, it makes your job a lot easier:
public class Contact
{
[PXPSetting(SettingName = “Contact.Name”)]
public string Name;
[PXPSetting(SettingName = “Contact.PlayerName”)]
public string PlayerName;
[PXPSetting(SettingName = “Contact.FavoriteServer”)]
public string FavoriteServer;
}
You can then use the ReadSettingsIntoObject() and WriteSettingsFromObject() calls to load and save.
PlayXpert makes it easy to store user settings and other information for your widget to follow the user to whatever PC on which they’re playing. For more detailed documentation on the SettingsStore and all of the services that PlayXpert offers widget developers, please visit our website at http://www.playxpert.com