Sha256: af6403777b5b97d56214a299aa5a748bb6456ee5cd8acb70fdd3b51010623b3e

Contents?: true

Size: 1.27 KB

Versions: 1

Compression:

Stored size: 1.27 KB

Contents

var Gamefic = (function() {
	var startCallbacks = [];
	var updateCallbacks = [];
	return {
		enableLogging: function() {

		},

		logAlias: function() {

		},

		canLog: function() {
			return false;
		},

		start: function() {
			var that = this;
      $.post('/start', function(response) {
				startCallbacks.forEach(function(callback) {
					callback();
				});
				that.update(response);
      });
		},

		update: function(response) {
			updateCallbacks.forEach(function(callback) {
				callback(response);
			});
		},

		receive: function(input) {
			var that = this;
			$.post('/update', {command: input}, function(response) {
				that.update(response);
			}).fail(function(response) {
				console.log('An error occurred');
			});
		},

		onUpdate: function(callback) {
			updateCallbacks.push(callback);
		},

		onStart: function(callback) {
			updateCallbacks.push(callback);
		},

		save: function(filename, data) {
			console.log('Saving ' + data);
			localStorage.setItem(filename, data);
		},

		restore: function(filename) {
			var json = localStorage.getItem(filename);
			var data = JSON.parse(json);
			var that = this;
			$.post('/restore', {snapshot: JSON.stringify(data)}, function(response) {
				console.log('Restored a snapshot.');
				that.update(response);
			});
		}
	}
})();

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
gamefic-sdk-1.7.0 html/sinatra/engine.js