• entries
    707
  • comments
    1173
  • views
    432938

Game Jolt C# API and News Service

Sign in to follow this  
Programmer16

1062 views

One of the things I've been wanting is an easy way to handle users, store saves in the cloud, and handle achievements...enter Game Jolt. There was already a C# API partially written, but I wasn't a big fan of the design and it doesn't seem to have gotten very far; so I'm currently working on implementing a 2 tier library - a core Game Jolt C# API (all functionality documented on Game Jolt's API page is implemented and testing) and a "services" tier.

The upper tier is going to be the core once I figure out some meat to add. There have been a few ideas - in-game messaging, in-game mailing, in-game trading, etc, but I'm having issues with implementing some of them due to limitations; I can't send a data item from one person to another for instance. Current layouts include using a global data store, but that can be dangerous and inefficient; I'll continue working on it though. The entire library will be open source shortly; I've created the CodePlex page, I just haven't published it yet (need to verify that I've removed all pertinent info from the source code, pick a decent license, and get some more meat in it.)

Currently the only service working is the news service. This is a simple game-news service; the typical "A new update is available" whatnot. I've created a tool that allows you to log in and the library provides what facilities to access the news (note that it isn't designed for a large number of items, but it works off of a single data store so you could theoretically store up to 16MB of news entries.)

Here are some screenshots:
[The News Manager]
LogIn.pngNewsItems.PNG
Items are managed via a context menu on the tree view on the left.

[In Game Example]
ItemsLoading.pngNewsMarquee.png
A loading message is displayed while the items are retrieved asynchronously (though all request have synchronous versions) and then they display on screen marquee-style.

[Android]
AndroidBuild.pngAndroidLoggedIn.png
All libraries involved are dual built against Android.

Here is the necessary source code for the example:// How to instantiate the services manager var GameJoltServicesManager = new GameJoltServices.ServicesManager("GAMEID", "PRIVATEKEY"); // The news item control used in Young Minds Memory Gamenamespace Mnemosyne{ public sealed class NewsItemControl : Control { private enum FeedState { Active = 0, Paused = 1, Finished = 2, }; #region Variables private bool itemsAreLoading = false; private List newsItems = null; private System.Collections.IEnumerator currentItem = null; private float marqueeX = 0.0f; private float minMarqueeX = 0.0f; private FeedState state = FeedState.Active; #endregion #region Properties public NewsItem[] NewsItems { get { return newsItems.ToArray(); } set { newsItems.Clear(); newsItems.AddRange(value); currentItem = newsItems.GetEnumerator(); MoveToNextItem(); } } #endregion #region Constructors public NewsItemControl() { newsItems = new List(); currentItem = newsItems.GetEnumerator(); } #endregion #region Methods private void MoveToNextItem() { if(!currentItem.MoveNext()) { currentItem.Reset(); state = FeedState.Finished; return; } var itemText = string.Format("{0} - {1}", ((NewsItem)currentItem.Current).Title, ((NewsItem)currentItem.Current).Content); var textSize = Font.MeasureString(itemText); minMarqueeX = -textSize.X; this.Width = (int)Math.Ceiling(textSize.X); marqueeX = this.Width; } protected override void OnDrawText(Lust.Renderer renderer, string overrideText = null) { if(state == FeedState.Finished) overrideText = string.Empty; else if(itemsAreLoading) { overrideText = "Loading news items..."; marqueeX = 0.0f; } else if(currentItem.Current != null) overrideText = string.Format("{0} - {1}", ((NewsItem)currentItem.Current).Title, ((NewsItem)currentItem.Current).Content); FlatStyle style = null; if(Styles.TryGetValue(this.State, out style)) FlatControlRenderer.DrawText(renderer, Font, overrideText, new Microsoft.Xna.Framework.Rectangle((int)marqueeX, Y, Width, Height), style, this.TextFormatFlags, null); } protected override void OnClick(Microsoft.Xna.Framework.Point position) { if(state == FeedState.Paused) state = FeedState.Active; else if(state == FeedState.Active) state = FeedState.Paused; base.OnClick(position); } public override void Update(float delta) { if(IsEnabled && !itemsAreLoading && state == FeedState.Active) { marqueeX -= 128.0f * delta; if(marqueeX < minMarqueeX) MoveToNextItem(); } base.Update(delta); } public void LoadItems(ServicesManager servicesManager) { newsItems.Clear(); itemsAreLoading = true; var newsService = new NewsService(servicesManager); newsService.GetNews((storedNewsItems) => { this.NewsItems = storedNewsItems; itemsAreLoading = false; }); } #endregion } public enum NewsItemDisplayStyle { Marquee, }} // You would then simply call newsItemControlInstance.LoadItems(GameJoltServicesManager)

Alrighty, that's enough work for tonight; I'm off to bed.

[edit]
Some (planned) key features:

  • Multi-user login tracking (up to 4 characters)
  • Guest log in
  • Simple UI elements (notification, user login pop up, etc)

    There are others, but I'm drawing a blank at the moment; not enough sleep I guess lol.
Sign in to follow this  


4 Comments


Recommended Comments

This seems like it would be a lot of fun to play with and I bet there are a few people out there that have been hunting for something just like this.

Share this comment


Link to comment

This seems like it would be a lot of fun to play with and I bet there are a few people out there that have been hunting for something just like this.

Indeed, I know I was. Their API is still somewhat limited, but it is brand new so that is to be expected. I'm probably going to be requesting some features in the near future, but I need to determine the good/bad ones and whether or not they are attainable.

 

I'm hoping to have my CodePlex project published with in the next few days.

 

Thanks for the comment!

Share this comment


Link to comment

There is currently a huge shift to cloud storage and operation that being near the front of the pack should give you a fair amount of attention.

Please post a link to the CodePlex page when you publish it.

Share this comment


Link to comment

There is currently a huge shift to cloud storage and operation that being near the front of the pack should give you a fair amount of attention.

Please post a link to the CodePlex page when you publish it.

The project has been published now: http://gamejolt.codeplex.com/

 

I just want to clarify that the Game Jolt website and the service are not mine; my library is just a C# implementation of their web API and then a library encapsulating some of the more complex or common mechanisms and such.

Share this comment


Link to comment

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now