Skip to content

Commit

Permalink
v2.1a (update 4): Implemented cumulative version update system via ne…
Browse files Browse the repository at this point in the history
…w update manifest XML file (#22).
  • Loading branch information
monicanagent committed May 21, 2017
1 parent 223e87a commit 78aa778
Show file tree
Hide file tree
Showing 10 changed files with 1,383 additions and 17 deletions.
6 changes: 3 additions & 3 deletions GameEngines/BaseCardGame/src/org/cg/BaseCardGame.as
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ package org.cg {
public static const SMO_SHIFTSELFTOEND:int = 1; //Shift self to end of SMO list.
public static const SMO_SHIFTSELFTOSTART:int = 2; //Shift self to start of SMO list.
public static const SMO_REMOVESELF:int = 3; //Remove self from SMO list.
public static const SMO_SHIFTNEXTPLAYERTOEND:int = 4; //Move next player after self to end. List is unchanged if self is not in list.
public static const SMO_SHIFTNEXTPLAYERTOEND:int = 4; //Move next player after self to end. List is unchanged if self is not in list.
protected var _initialized:Boolean = false; //Is game fully initialized?
protected var _running:Boolean = false; //Is game running?
protected var _UIEnabled:Boolean = false; //Is game UI enabled?
Expand Down Expand Up @@ -195,7 +195,7 @@ package org.cg {
try {
this._table = args[3] as Table;
} catch (err:*) {
}
}
loadSettings(settingsXMLPath, resetToDefault);
}

Expand Down Expand Up @@ -414,7 +414,7 @@ package org.cg {
DebugView.addText ("BaseCardGame.loadSettings: " + xmlFilePath);
GameSettings.dispatcher.addEventListener(SettingsEvent.LOAD, onLoadSettings);
GameSettings.dispatcher.addEventListener(SettingsEvent.LOADERROR, onLoadSettingsError);
GameSettings.loadSettings(xmlFilePath, reset);
GameSettings.loadSettings(xmlFilePath, reset, _lounge.version);
}

/**
Expand Down
2 changes: 1 addition & 1 deletion GameEngines/PokerCardGame/src/PokerCardGame.as
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ package {
private var _txSigningEnabled:Boolean = true; //is Ethereum transaction signing/verification enabled?
private var _resetAlert:Alert = null;

public function PokerCardGame():void {
public function PokerCardGame():void {
if (GlobalSettings.systemSettings.isWeb) {
super.settingsFilePath = "./PokerCardGame/xml/settings.xml";
} else {
Expand Down
36 changes: 33 additions & 3 deletions Lounge/common/org/cg/GameSettings.as
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ package org.cg {

import flash.events.EventDispatcher;
import org.cg.events.SettingsEvent;
import org.cg.SettingsUpdater;
import org.cg.events.SettingsUpdaterEvent;
import flash.net.SharedObject;
import flash.net.URLLoader;
import flash.net.URLLoaderDataFormat;
Expand All @@ -25,6 +27,7 @@ package org.cg {
private static var _settingsLoader:URLLoader; //loader for the settings data
private static var _settingsFilePath:String = "xml/settings.xml"; //file path of the settings data on disk
private static var _settingsData:XML; //the loaded settings data
private static var _updater:SettingsUpdater; //updater for the game settings data
private static const _lsoName:String = "PokerGameSettings"; //name of the Local Shared Object under which updated settings data is stored
private static var _isDynamic:Boolean = true; //has settings data been dunamically generated (true) or loaded (false)?
private static var _dispatcher:EventDispatcher = new EventDispatcher(); //event dispatcher for the class (since most methods are static)
Expand Down Expand Up @@ -111,8 +114,9 @@ package org.cg {
* @param reset If true the default settings data will be loaded and will replace any saved settings data.
* If false saved settings data will be loaded unless it doesn't exist in which case default data will be
* loaded.
* @param version Settings version to update to if not currently up-to-date.
*/
public static function loadSettings(filePath:String = null, reset:Boolean = false):void {
public static function loadSettings(filePath:String = null, reset:Boolean = false, version:String = "2.1a"):void {
if ((filePath == null) || (filePath == "")) {
filePath = _settingsFilePath;
}
Expand All @@ -129,8 +133,12 @@ package org.cg {
if ((_settingsData == null) || (_settingsData.toString == "")) {
reset = true;
} else {
_settingsData.@reset = "false";
dispatchLoadComplete();
_settingsData.@reset = "false";
var updateManifestURL:String = null;
_updater = new SettingsUpdater(updateManifestURL, _lsoName);
_updater.addEventListener (SettingsUpdaterEvent.COMPLETE, onUpdaterComplete);
_updater.addEventListener (SettingsUpdaterEvent.FAIL, onUpdaterFail);
_updater.update(version)
return;
}
} catch (err:*) {
Expand Down Expand Up @@ -302,6 +310,28 @@ package org.cg {
_settingsData = null;
}

/**
* Event dispatcher invoked when the SettingsUpdater instance dispatches a SettingsUpdaterEvent.COMPLETE event.
*
* @param eventObj A SettingsUpdaterEvent object.
*/
private static function onUpdaterComplete(eventObj:SettingsUpdaterEvent):void {
_updater.removeEventListener (SettingsUpdaterEvent.COMPLETE, onUpdaterComplete);
_updater.removeEventListener (SettingsUpdaterEvent.FAIL, onUpdaterFail);
dispatchLoadComplete();
}

/**
* Event dispatcher invoked when the SettingsUpdater instance dispatches a SettingsUpdaterEvent.FAIL event.
*
* @param eventObj A SettingsUpdaterEvent object.
*/
private static function onUpdaterFail(eventObj:SettingsUpdaterEvent):void {
_updater.removeEventListener (SettingsUpdaterEvent.COMPLETE, onUpdaterComplete);
_updater.removeEventListener (SettingsUpdaterEvent.FAIL, onUpdaterFail);
dispatchLoadComplete();
}

/**
* Dispatches a SettingsEvent.LOAD event upon successful completion of
* settings data loading and parsing.
Expand Down
41 changes: 36 additions & 5 deletions Lounge/common/org/cg/GlobalSettings.as
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,9 @@
package org.cg {

import flash.events.EventDispatcher;
import org.cg.events.SettingsEvent;
import org.cg.events.SettingsEvent;
import org.cg.SettingsUpdater;
import org.cg.events.SettingsUpdaterEvent;
import flash.net.SharedObject;
import flash.net.URLLoader;
import flash.net.URLLoaderDataFormat;
Expand All @@ -29,6 +31,7 @@ package org.cg {
private static var _settingsLoader:URLLoader; //loader used to load global settings data
private static var _settingsFilePath:String = "xml/settings.xml"; //relative location of default settings file
private static var _settingsData:XML; //loaded global settings data
private static var _updater:SettingsUpdater; //updater for the global settings data
private static const _SOName:String = "CypherPoker"; //Local Shared Object name
private static var _isDynamic:Boolean = true; //is settings data dynamically created (true) or loaded (false)
private static var _dispatcher:EventDispatcher = new EventDispatcher(); //So that the singleton can dispatch events
Expand Down Expand Up @@ -150,9 +153,9 @@ package org.cg {
* @param reset If true the default settings data will be loaded and will replace any saved settings data.
* If false saved settings data will be loaded unless it doesn't exist in which case default data will be
* loaded.
* @param version Settings version to update to if not currently up-to-date.
*/
public static function loadSettings(filePath:String = null, reset:Boolean = false):void {
DebugView.addText("loadSettings");
public static function loadSettings(filePath:String = null, reset:Boolean = false, version:String = "2.1a"):void {
if ((filePath == null) || (filePath == "")) {
filePath = _settingsFilePath;
}
Expand All @@ -169,12 +172,18 @@ package org.cg {
if ((_settingsData == null) || (_settingsData.toString() == "")) {
reset = true;
} else {
_settingsData.@reset = "false";
dispatchLoadComplete();
_settingsData.@reset = "false";
var updateManifestURL:String = null;
_updater = new SettingsUpdater(updateManifestURL, _SOName);
_updater.addEventListener (SettingsUpdaterEvent.COMPLETE, onUpdaterComplete);
_updater.addEventListener (SettingsUpdaterEvent.FAIL, onUpdaterFail);
_updater.update(version);
return;
}
} catch (err:*) {
trace (err);
reset = true;
return;
}
}
if (reset) {
Expand Down Expand Up @@ -406,6 +415,28 @@ package org.cg {
return (toBoolean(optData));
}

/**
* Event dispatcher invoked when the SettingsUpdater instance dispatches a SettingsUpdaterEvent.COMPLETE event.
*
* @param eventObj A SettingsUpdaterEvent object.
*/
private static function onUpdaterComplete(eventObj:SettingsUpdaterEvent):void {
_updater.removeEventListener (SettingsUpdaterEvent.COMPLETE, onUpdaterComplete);
_updater.removeEventListener (SettingsUpdaterEvent.FAIL, onUpdaterFail);
dispatchLoadComplete();
}

/**
* Event dispatcher invoked when the SettingsUpdater instance dispatches a SettingsUpdaterEvent.FAIL event.
*
* @param eventObj A SettingsUpdaterEvent object.
*/
private static function onUpdaterFail(eventObj:SettingsUpdaterEvent):void {
_updater.removeEventListener (SettingsUpdaterEvent.COMPLETE, onUpdaterComplete);
_updater.removeEventListener (SettingsUpdaterEvent.FAIL, onUpdaterFail);
dispatchLoadComplete();
}

/**
* Finds the nearest matching CBL from available <pregen> entries in the settings data.
*
Expand Down
14 changes: 11 additions & 3 deletions Lounge/common/org/cg/Lounge.as
Original file line number Diff line number Diff line change
Expand Up @@ -89,10 +89,11 @@ package org.cg {
NewWindowWidget;
ConnectedPeersWidget;
PlayerProfileWidget;
EtherTransferWidget;

dynamic public class Lounge extends MovieClip implements ILounge {

public static const version:String = "2.0a"; //Lounge version
public static const _version:String = "2.1a"; //Lounge version
public static const resetConfig:Boolean = false; //Load default global settings data at startup?
public static var xmlConfigFilePath:String = "./xml/settings.xml"; //Default settings file
private var _starling:Starling; //main instance used to render Starling/Feathers elements
Expand All @@ -114,7 +115,7 @@ package org.cg {
private var _ethereumEnabled:Boolean = false; //Is Ethereum integration enabled? This value overrides loaded settings if updated after load.
private var _tableManager:TableManager = null; //manages tables for the lounge, public getter is available (tableManager).

public function Lounge():void {
public function Lounge():void {
DebugView.addText ("---");
DebugView.addText ("Lounge v" + version);
DebugView.addText ("Starling v" + Starling.VERSION);
Expand Down Expand Up @@ -153,6 +154,13 @@ package org.cg {
}
}

/**
* @return The current implementation version, used for settings updates and other functionality.
*/
public function get version():String {
return (_version);
}

/**
* @return True if the current Lounge instance is a child of a parent application instance, false if this is the parent or sole
* instance. This value will always be false for non-desktop runtimes.
Expand Down Expand Up @@ -1078,7 +1086,7 @@ package org.cg {
GlobalDispatcher.addEventListener(GameEngineEvent.CREATED, onGameEngineCreated);
GlobalDispatcher.addEventListener(GameEngineEvent.READY, onGameEngineReady);
GlobalSettings.dispatcher.addEventListener(SettingsEvent.LOAD, onLoadSettings);
GlobalSettings.loadSettings(xmlConfigFilePath, resetConfig);
GlobalSettings.loadSettings(xmlConfigFilePath, resetConfig, version);
}
}
}
Loading

0 comments on commit 78aa778

Please sign in to comment.