Skip to content

Instantly share code, notes, and snippets.

@jamesyoung
Created December 1, 2013 02:08
Show Gist options
  • Save jamesyoung/7727718 to your computer and use it in GitHub Desktop.
Save jamesyoung/7727718 to your computer and use it in GitHub Desktop.
package com.wincity.lib.air.slots.gamewrapper
{
import com.wincity.lib.air.facebook.FacebookWrapper;
import com.wincity.lib.air.slots.SlotsConfigData;
import com.wincity.lib.air.slots.consts.GameTypeConstants;
import com.wincity.lib.air.slots.gamewrapper.BADAGameWrapper;
import com.wincity.lib.air.slots.gamewrapper.CozyGameWrapper;
import com.wincity.lib.air.slots.gamewrapper.IGameWrapper;
import com.wincity.lib.air.slots.manager.CLobbyManager;
import com.wincity.lib.air.slots.manager.CSlotController;
import com.wincity.lib.air.slots.manager.CStatsManager;
import com.wincity.lib.air.slots.manager.GameUnitsManager;
import com.wincity.lib.air.utils.CKBWrapper;
import flash.display.Stage;
import flash.events.Event;
import mx.controls.SWFLoader;
public class CGameWrapper
{
private static var _instance:CGameWrapper;
private var _slotGameWrapper:IGameWrapper;
private var _scratcherGameWrapper:IGameWrapper;
private var targetWrapper:IGameWrapper;
private static var _shouldStopGame:Boolean;
public function CGameWrapper(caller:Function = null)
{
if (caller != preventCreation) {
throw new Error ("CKBWrapper is a singleton class, use getInstance() instead");
return;
}
if(SlotsConfigData.getInstance().partner == SlotsConfigData.PARTNER_BADA){
_slotGameWrapper = new BADAGameWrapper();
}else if(SlotsConfigData.getInstance().partner == SlotsConfigData.PARTNER_COZY){
_slotGameWrapper = new CozyGameWrapper();
}else if(SlotsConfigData.getInstance().partner == SlotsConfigData.PARTNER_KB_WEB){
_slotGameWrapper = new KBWebWrapper();
}else if (SlotsConfigData.getInstance().partner == SlotsConfigData.PARTNER_MAG7){
_slotGameWrapper = new Mag7GameWrapper(this);
}
_scratcherGameWrapper = new ScratcherGameWrapper();
targetWrapper = _slotGameWrapper;
GameUnitsManager.instance.init(SlotsConfigData.FILE_DATA_URL);
}
public function onHome():void {
_slotGameWrapper = new Mag7GameWrapper(this);
}
public static function get instance():CGameWrapper
{
if(_instance == null){
_instance = new CGameWrapper(preventCreation);
}
return _instance;
}
protected static function preventCreation():void {
}
public function init(gameStage:Stage, hudHeight:Number):void
{
_slotGameWrapper.init(gameStage, hudHeight, CSlotController.getInstance().isSoundEnabled);
_scratcherGameWrapper.init(gameStage, hudHeight, CSlotController.getInstance().isSoundEnabled);
}
public function pauseGame():void
{
targetWrapper.pauseGame();
setDeviceSleepMode(true);
}
public function mute(isMute:Boolean=true):void
{
targetWrapper.mute(isMute);
}
public function resumeGame():void
{
targetWrapper.resumeGame()
setDeviceSleepMode(false);
}
public function destruct():void
{
if(CStatsManager.getInstance().getGameRunning())
CSlotController.getInstance().updateGameInfo();
targetWrapper.destruct();
setDeviceSleepMode(true);
}
//////////////////////
public function setAssetPath(assetpath:String):void
{
targetWrapper.setAssetPath(assetpath);
}
public function sendCreditDeltaToGame():void
{
targetWrapper.sendCreditDeltaToGame();
}
public function sendBonusOddInformation(level:Number):void
{
targetWrapper.sendBonusOddInformation(level);
}
public function placeBet():void
{
setStopGame(false);
targetWrapper.placeBet();
}
public function stopAutoSpin():void
{
targetWrapper.stopAutoSpin();
}
public function loadGameUnit(gameName:String, url:String=null, index:Number=0):Boolean
{
if(CLobbyManager.getInstance().getGameUnitByName(gameName) == null){
targetWrapper = _slotGameWrapper;
}else{
var isScratcher:Boolean = CLobbyManager.getInstance().getGameUnitByName(gameName).type == GameTypeConstants.SCRATCHER;
targetWrapper = isScratcher ? _scratcherGameWrapper : _slotGameWrapper;
}
if(!targetWrapper.loadGameUnit(gameName, url, index))
{
return false
}
// prevent device to go to sleep
setDeviceSleepMode(false);
//Send facebook story
if(!SlotsConfigData.isEmulator)
FacebookWrapper.instance.postPlaySlotMachine(gameName);
return true;
}
public function setStageForGame(swfLoader:SWFLoader):void
{
_slotGameWrapper.setStageForGame(swfLoader);
_scratcherGameWrapper.setStageForGame(swfLoader);
}
private function setDeviceSleepMode(preventSleep:Boolean):void
{
if(!SlotsConfigData.isEmulator)
CKBWrapper.instance.setDeviceSleepMode(preventSleep)
}
public function get shouldStopGame():Boolean
{
return _shouldStopGame;
}
public function setStopGame(stop:Boolean):void
{
if(!stop){
// resumeGame();
}
_shouldStopGame = stop;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment