<commit_before>/*
 Copyright (C) 2013-2015 by <NAME> and Contributors

 Licensed under the Apache License, Version 2.0 (the "License");
 you may not use this file except in compliance with the License.
 You may obtain a copy of the License at

 http://www.apache.org/licenses/LICENSE-2.0

 Unless required by applicable law or agreed to in writing, software
 distributed under the License is distributed on an "AS IS" BASIS,
 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 See the License for the specific language governing permissions and
 limitations under the License.
 */

/// <reference path="../index.ts"/>
/// <reference path="../states/dorkaponMapState.ts"/>
/// <reference path="../dorkaponGameWorld.ts"/>

module dorkapon.services {
   export class DorkaponService {
      loader:pow2.ResourceLoader;
      world:DorkaponGameWorld;
      machine:DorkaponAppStateMachine;

      constructor(public compile:ng.ICompileService,
                  public scope:ng.IRootScopeService) {
         this.loader = pow2.ResourceLoader.get();
         this.world = new DorkaponGameWorld({
            scene: new pow2.Scene({
               autoStart: true,
               debugRender: false
            })
         });
         pow2.registerWorld(dorkapon.NAME, this.world);
         this.machine = <DorkaponAppStateMachine>this.world.setService('state', new DorkaponAppStateMachine());
         // Tell the world time manager to start ticking.
         this.world.time.start();
      }

      /**
       * Start a new game.
       * @param then
       */
      newGame(then?:()=>any) {
         this.machine.setCurrentState(dorkapon.states.AppMapState.NAME);
         then && then();
      }
   }
   app.factory('$dorkapon', [
      '$compile',
      '$rootScope',
      ($compile:ng.ICompileService, $rootScope:ng.IRootScopeService) => {
         return new DorkaponService($compile, $rootScope);
      }
   ]);
}<commit_msg>feat(dorkapon): clear game data cache when ?dev is on the url<commit_after>/*
 Copyright (C) 2013-2015 by <NAME> and Contributors

 Licensed under the Apache License, Version 2.0 (the "License");
 you may not use this file except in compliance with the License.
 You may obtain a copy of the License at

 http://www.apache.org/licenses/LICENSE-2.0

 Unless required by applicable law or agreed to in writing, software
 distributed under the License is distributed on an "AS IS" BASIS,
 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 See the License for the specific language governing permissions and
 limitations under the License.
 */

/// <reference path="../index.ts"/>
/// <reference path="../states/dorkaponMapState.ts"/>
/// <reference path="../dorkaponGameWorld.ts"/>

module dorkapon.services {
   export class DorkaponService {
      loader:pow2.ResourceLoader;
      world:DorkaponGameWorld;
      machine:DorkaponAppStateMachine;

      constructor(public compile:ng.ICompileService,
                  public scope:ng.IRootScopeService) {

         if(this.qs().hasOwnProperty('dev')){
            console.log("Clearing gameData cache and loading live from Google Spreadsheets");
            pow2.GameDataResource.clearCache(SPREADSHEET_ID);
         }

         this.loader = pow2.ResourceLoader.get();
         this.world = new DorkaponGameWorld({
            scene: new pow2.Scene({
               autoStart: true,
               debugRender: false
            })
         });
         pow2.registerWorld(dorkapon.NAME, this.world);
         this.machine = <DorkaponAppStateMachine>this.world.setService('state', new DorkaponAppStateMachine());
         // Tell the world time manager to start ticking.
         this.world.time.start();

      }

      /**
       * Start a new game.
       * @param then
       */
      newGame(then?:()=>any) {
         this.machine.setCurrentState(dorkapon.states.AppMapState.NAME);
         then && then();
      }

      /**
       * Extract the browser location query params
       * http://stackoverflow.com/questions/9241789/how-to-get-url-params-with-javascript
       */
      qs():any {
         if(window.location.search){
            var query_string = {};
            (function () {
               var e,
                  a = /\+/g,  // Regex for replacing addition symbol with a space
                  r = /([^&=]+)=?([^&]*)/g,
                  d = function (s) { return decodeURIComponent(s.replace(a, " ")); },
                  q = window.location.search.substring(1);

               while ((e = r.exec(q))){
                  query_string[d(e[1])] = d(e[2]);
               }
            })();
            return query_string;
         }
         return {};
      }
   }
   app.factory('$dorkapon', [
      '$compile',
      '$rootScope',
      ($compile:ng.ICompileService, $rootScope:ng.IRootScopeService) => {
         return new DorkaponService($compile, $rootScope);
      }
   ]);
}
{'fraction_non_alphanumeric': 0.11887403807209397, 'fraction_numerical': 0.008707978938841636, 'mean_word_length': 2.3214525891055815, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 17, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4927740', 'n_tokens_mistral': 1386, 'n_tokens_neox': 1338, 'n_words': 362}