Added some tests

This commit is contained in:
2016-02-24 17:12:08 +08:00
parent b3a4e8ca4f
commit a82d04af1a
21 changed files with 926 additions and 339 deletions
+78
View File
@@ -0,0 +1,78 @@
{
"rules": {
# "indent": [
# 2,
# 4
# ],
# "linebreak-style": [
# 2,
# "unix"
# ],
"semi": [
2,
"always"
],
"angular/angularelement": 1,
"angular/controller-as": 2,
"angular/controller-as-route": 2,
"angular/controller-as-vm": [2, "vm"],
"angular/controller-name": [2, "/[A-Z].*Controller$/"],
"angular/deferred": 0,
"angular/definedundefined": 0,
"angular/di": [2, "function"],
"angular/di-order": [0, true],
"angular/directive-name": 0,
"angular/directive-restrict": [0, {"restrict": "AE", "explicit": "never"}],
"angular/component-limit": [0, 1],
"angular/document-service": 2,
"angular/empty-controller": 0,
"angular/file-name": 0,
"angular/filter-name": 0,
"angular/foreach": 0,
"angular/function-type": 0,
"angular/interval-service": 2,
"angular/json-functions": 2,
"angular/log": 0,
"angular/module-dependency-order": [0, {"grouped": true, "prefix": null}],
"angular/module-getter": 0,
"angular/module-name": 0,
"angular/module-setter": 2,
"angular/no-angular-mock": 0,
"angular/no-controller": 0,
"angular/no-cookiestore": 2,
"angular/no-digest": 2,
"angular/no-http-callback": 2,
"angular/no-inline-template": [0, {"allowSimple": true}],
"angular/no-jquery-angularelement": 2,
"angular/no-private-call": 2,
"angular/no-run-logic": [0, {"allowParams": true}],
"angular/no-service-method": 2,
"angular/no-services": [2, ["$http", "$resource", "Restangular"]],
"angular/on-watch": 2,
"angular/one-dependency-per-line": 0,
"angular/rest-service": 0,
"angular/service-name": 2,
"angular/timeout-service": 2,
"angular/typecheck-array": 2,
"angular/typecheck-date": 2,
"angular/typecheck-function": 2,
"angular/typecheck-number": 2,
"angular/typecheck-object": 2,
"angular/typecheck-regexp": 2,
"angular/typecheck-string": 2,
"angular/watchers-execution": [0, "$digest"],
"angular/window-service": 2
},
"env": {
"browser": true,
"jquery": true,
"jasmine": true,
"protractor": true,
"node": true,
},
"globals": {
"window": true,
},
"extends": "angular"
}
+3
View File
@@ -372,6 +372,9 @@ h1 br {
.Paired .q10-12{color:rgb(255,255,153)}
.Paired .q11-12{color:rgb(177,89,40)}
.Red {color:red;}
.Black {color:black;}
/* ui grid */
.observations-grid {
+2 -2
View File
@@ -579,8 +579,8 @@ input[type="text"].ui-grid-filter-input:hover {
}
@font-face {
font-family: 'ui-grid';
src: url('ui-grid.eot');
src: url('ui-grid.eot#iefix') format('embedded-opentype'), url('ui-grid.woff') format('woff'), url('ui-grid.ttf?') format('truetype'), url('ui-grid.svg?#ui-grid') format('svg');
src: url('../fonts/ui-grid.eot');
src: url('../fonts/ui-grid.eot#iefix') format('embedded-opentype'), url('../fonts/ui-grid.woff') format('woff'), url('../fonts/ui-grid.ttf?') format('truetype'), url('../fonts/ui-grid.svg?#ui-grid') format('svg');
font-weight: normal;
font-style: normal;
}
BIN
View File
Binary file not shown.
+34
View File
@@ -0,0 +1,34 @@
<?xml version="1.0" standalone="no"?>
<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">
<svg xmlns="http://www.w3.org/2000/svg">
<metadata>Copyright (C) 2016 by original authors @ fontello.com</metadata>
<defs>
<font id="ui-grid" horiz-adv-x="1000" >
<font-face font-family="ui-grid" font-weight="400" font-stretch="normal" units-per-em="1000" ascent="850" descent="-150" />
<missing-glyph horiz-adv-x="1000" />
<glyph glyph-name="plus-squared" unicode="&#xc350;" d="m714 314v72q0 14-10 25t-25 10h-179v179q0 15-11 25t-25 11h-71q-15 0-25-11t-11-25v-179h-178q-15 0-26-10t-10-25v-72q0-14 10-25t26-10h178v-179q0-14 11-25t25-11h71q15 0 25 11t11 25v179h179q14 0 25 10t10 25z m143 304v-536q0-66-47-113t-114-48h-535q-67 0-114 48t-47 113v536q0 66 47 113t114 48h535q67 0 114-48t47-113z" horiz-adv-x="857.1" />
<glyph glyph-name="minus-squared" unicode="&#xc351;" d="m714 314v72q0 14-10 25t-25 10h-500q-15 0-26-10t-10-25v-72q0-14 10-25t26-10h500q14 0 25 10t10 25z m143 304v-536q0-66-47-113t-114-48h-535q-67 0-114 48t-47 113v536q0 66 47 113t114 48h535q67 0 114-48t47-113z" horiz-adv-x="857.1" />
<glyph glyph-name="search" unicode="&#xc352;" d="m643 386q0 103-74 176t-176 74-177-74-73-176 73-177 177-73 176 73 74 177z m286-465q0-29-22-50t-50-21q-30 0-50 21l-191 191q-100-69-223-69-80 0-153 31t-125 84-84 125-31 153 31 152 84 126 125 84 153 31 152-31 126-84 84-126 31-152q0-123-69-223l191-191q21-21 21-51z" horiz-adv-x="928.6" />
<glyph glyph-name="cancel" unicode="&#xc353;" d="m724 112q0-22-15-38l-76-76q-16-15-38-15t-38 15l-164 165-164-165q-16-15-38-15t-38 15l-76 76q-16 16-16 38t16 38l164 164-164 164q-16 16-16 38t16 38l76 76q16 16 38 16t38-16l164-164 164 164q16 16 38 16t38-16l76-76q15-15 15-38t-15-38l-164-164 164-164q15-15 15-38z" horiz-adv-x="785.7" />
<glyph glyph-name="info-circled" unicode="&#xc354;" d="m571 82v89q0 8-5 13t-12 5h-54v286q0 8-5 13t-13 5h-178q-8 0-13-5t-5-13v-89q0-8 5-13t13-5h53v-179h-53q-8 0-13-5t-5-13v-89q0-8 5-13t13-5h250q7 0 12 5t5 13z m-71 500v89q0 8-5 13t-13 5h-107q-8 0-13-5t-5-13v-89q0-8 5-13t13-5h107q8 0 13 5t5 13z m357-232q0-117-57-215t-156-156-215-58-216 58-155 156-58 215 58 215 155 156 216 58 215-58 156-156 57-215z" horiz-adv-x="857.1" />
<glyph glyph-name="lock" unicode="&#xc355;" d="m179 421h285v108q0 59-42 101t-101 41-101-41-41-101v-108z m464-53v-322q0-22-16-37t-38-16h-535q-23 0-38 16t-16 37v322q0 22 16 38t38 15h17v108q0 102 74 176t176 74 177-74 73-176v-108h18q23 0 38-15t16-38z" horiz-adv-x="642.9" />
<glyph glyph-name="lock-open" unicode="&#xc356;" d="m929 529v-143q0-15-11-25t-25-11h-36q-14 0-25 11t-11 25v143q0 59-41 101t-101 41-101-41-42-101v-108h53q23 0 38-15t16-38v-322q0-22-16-37t-38-16h-535q-23 0-38 16t-16 37v322q0 22 16 38t38 15h375v108q0 103 73 176t177 74 176-74 74-176z" horiz-adv-x="928.6" />
<glyph glyph-name="pencil" unicode="&#xc357;" d="m203-7l50 51-131 131-51-51v-60h72v-71h60z m291 518q0 12-12 12-5 0-9-4l-303-302q-4-4-4-10 0-12 13-12 5 0 9 4l303 302q3 4 3 10z m-30 107l232-232-464-465h-232v233z m381-54q0-29-20-50l-93-93-232 233 93 92q20 21 50 21 29 0 51-21l131-131q20-22 20-51z" horiz-adv-x="857.1" />
<glyph glyph-name="down-dir" unicode="&#xc358;" d="m571 457q0-14-10-25l-250-250q-11-11-25-11t-25 11l-250 250q-11 11-11 25t11 25 25 11h500q14 0 25-11t10-25z" horiz-adv-x="571.4" />
<glyph glyph-name="up-dir" unicode="&#xc359;" d="m571 171q0-14-10-25t-25-10h-500q-15 0-25 10t-11 25 11 26l250 250q10 10 25 10t25-10l250-250q10-11 10-26z" horiz-adv-x="571.4" />
<glyph glyph-name="left-dir" unicode="&#xc35a;" d="m357 600v-500q0-14-10-25t-26-11-25 11l-250 250q-10 11-10 25t10 25l250 250q11 11 25 11t26-11 10-25z" horiz-adv-x="357.1" />
<glyph glyph-name="right-dir" unicode="&#xc35b;" d="m321 350q0-14-10-25l-250-250q-11-11-25-11t-25 11-11 25v500q0 15 11 25t25 11 25-11l250-250q10-10 10-25z" horiz-adv-x="357.1" />
<glyph glyph-name="left-open" unicode="&#xc35c;" d="m653 682l-296-296 296-297q11-10 11-25t-11-25l-92-93q-11-10-25-10t-25 10l-414 415q-11 10-11 25t11 25l414 414q10 10 25 10t25-10l92-93q11-10 11-25t-11-25z" horiz-adv-x="714.3" />
<glyph glyph-name="right-open" unicode="&#xc35d;" d="m618 361l-414-415q-11-10-25-10t-26 10l-92 93q-11 11-11 25t11 25l296 297-296 296q-11 11-11 25t11 25l92 93q11 10 26 10t25-10l414-414q10-11 10-25t-10-25z" horiz-adv-x="714.3" />
<glyph glyph-name="angle-down" unicode="&#xc35e;" d="m600 439q0-7-6-13l-260-260q-5-5-13-5t-12 5l-260 260q-6 6-6 13t6 13l27 28q6 6 13 6t13-6l219-219 220 219q5 6 13 6t12-6l28-28q6-5 6-13z" horiz-adv-x="642.9" />
<glyph glyph-name="filter" unicode="&#xc35f;" d="m783 685q9-23-8-39l-275-275v-414q0-23-22-33-7-3-14-3-15 0-25 11l-143 143q-10 10-10 25v271l-275 275q-18 16-8 39 9 22 33 22h714q23 0 33-22z" horiz-adv-x="785.7" />
<glyph glyph-name="sort-alt-up" unicode="&#xc360;" d="m411 46q0-6-6-13l-178-178q-5-5-13-5-6 0-13 5l-178 179q-8 9-4 19 4 11 17 11h107v768q0 8 5 13t13 5h107q8 0 13-5t5-13v-768h107q8 0 13-5t5-13z m589-71v-107q0-8-5-13t-13-5h-464q-8 0-13 5t-5 13v107q0 8 5 13t13 5h464q8 0 13-5t5-13z m-107 286v-107q0-8-5-13t-13-5h-357q-8 0-13 5t-5 13v107q0 8 5 13t13 5h357q8 0 13-5t5-13z m-107 285v-107q0-8-5-13t-13-5h-250q-8 0-13 5t-5 13v107q0 8 5 13t13 5h250q8 0 13-5t5-13z m-107 286v-107q0-8-5-13t-13-5h-143q-8 0-13 5t-5 13v107q0 8 5 13t13 5h143q8 0 13-5t5-13z" horiz-adv-x="1000" />
<glyph glyph-name="sort-alt-down" unicode="&#xc361;" d="m679-25v-107q0-8-5-13t-13-5h-143q-8 0-13 5t-5 13v107q0 8 5 13t13 5h143q8 0 13-5t5-13z m-268 71q0-6-6-13l-178-178q-5-5-13-5-6 0-13 5l-178 179q-8 9-4 19 4 11 17 11h107v768q0 8 5 13t13 5h107q8 0 13-5t5-13v-768h107q8 0 13-5t5-13z m375 215v-107q0-8-5-13t-13-5h-250q-8 0-13 5t-5 13v107q0 8 5 13t13 5h250q8 0 13-5t5-13z m107 285v-107q0-8-5-13t-13-5h-357q-8 0-13 5t-5 13v107q0 8 5 13t13 5h357q8 0 13-5t5-13z m107 286v-107q0-8-5-13t-13-5h-464q-8 0-13 5t-5 13v107q0 8 5 13t13 5h464q8 0 13-5t5-13z" horiz-adv-x="1000" />
<glyph glyph-name="ok" unicode="&#xc362;" d="m932 534q0-22-15-38l-404-404-76-76q-16-15-38-15t-38 15l-76 76-202 202q-15 16-15 38t15 38l76 76q16 16 38 16t38-16l164-165 366 367q16 16 38 16t38-16l76-76q15-16 15-38z" horiz-adv-x="1000" />
<glyph glyph-name="menu" unicode="&#xc363;" d="m857 100v-71q0-15-10-25t-26-11h-785q-15 0-25 11t-11 25v71q0 15 11 25t25 11h785q15 0 26-11t10-25z m0 286v-72q0-14-10-25t-26-10h-785q-15 0-25 10t-11 25v72q0 14 11 25t25 10h785q15 0 26-10t10-25z m0 285v-71q0-15-10-25t-26-11h-785q-15 0-25 11t-11 25v71q0 15 11 26t25 10h785q15 0 26-10t10-26z" horiz-adv-x="857.1" />
<glyph glyph-name="indent-left" unicode="&#xe800;" d="m214 546v-321q0-7-5-13t-13-5q-7 0-12 5l-161 161q-5 5-5 13t5 13l161 160q5 5 12 5 8 0 13-5t5-13z m786-428v-107q0-7-5-13t-13-5h-964q-7 0-13 5t-5 13v107q0 7 5 12t13 6h964q7 0 13-6t5-12z m0 214v-107q0-7-5-13t-13-5h-607q-7 0-13 5t-5 13v107q0 7 5 13t13 5h607q7 0 13-5t5-13z m0 214v-107q0-7-5-12t-13-6h-607q-7 0-13 6t-5 12v107q0 8 5 13t13 5h607q7 0 13-5t5-13z m0 215v-107q0-8-5-13t-13-5h-964q-7 0-13 5t-5 13v107q0 7 5 12t13 6h964q7 0 13-6t5-12z" horiz-adv-x="1000" />
<glyph glyph-name="indent-right" unicode="&#xe801;" d="m196 386q0-8-5-13l-160-161q-5-5-13-5-7 0-13 5t-5 13v321q0 8 5 13t13 5q8 0 13-5l160-160q5-5 5-13z m804-268v-107q0-7-5-13t-13-5h-964q-7 0-13 5t-5 13v107q0 7 5 12t13 6h964q7 0 13-6t5-12z m0 214v-107q0-7-5-13t-13-5h-607q-7 0-13 5t-5 13v107q0 7 5 13t13 5h607q7 0 13-5t5-13z m0 214v-107q0-7-5-12t-13-6h-607q-7 0-13 6t-5 12v107q0 8 5 13t13 5h607q7 0 13-5t5-13z m0 215v-107q0-8-5-13t-13-5h-964q-7 0-13 5t-5 13v107q0 7 5 12t13 6h964q7 0 13-6t5-12z" horiz-adv-x="1000" />
<glyph glyph-name="spin5" unicode="&#xea61;" d="m462 850c-6 0-11-5-11-11l0-183 0 0c0-6 5-11 11-11l69 0c1 0 1 0 1 0 7 0 12 5 12 11l0 183 0 0c0 6-5 11-12 11l-69 0c0 0 0 0-1 0z m250-47c-4 1-8-2-10-5l-91-158 0 0c-4-6-2-13 4-16l60-35c0 0 0 0 0 0 6-3 13-1 16 4l91 158c3 6 2 13-4 16l-61 35c-1 1-3 1-5 1z m-428-2c-2 0-4-1-6-2l-61-35c-5-3-7-10-4-16l91-157c0 0 0 0 0 0 3-6 10-8 16-5l61 35c5 4 7 11 4 16l-91 157c0 1 0 1 0 1-2 4-6 6-10 6z m620-163c-2 0-4 0-6-1l-157-91c0 0 0 0 0 0-6-3-8-10-5-16l35-61c4-5 11-7 16-4l157 91c1 0 1 0 1 0 6 3 7 10 4 16l-35 61c-2 3-6 5-10 5z m-810-4c-5 0-9-2-11-6l-35-61c-3-5-1-12 4-15l158-92 0 0c6-3 13-1 16 5l35 60c0 0 0 0 0 0 3 6 1 13-4 16l-158 91c-2 1-4 2-5 2z m712-235l0 0c-6 0-11-5-11-11l0-69c0-1 0-1 0-1 0-7 5-12 11-12l183 0 0 0c6 0 11 5 11 12l0 69c0 0 0 0 0 1 0 6-5 11-11 11l-183 0z m-794-5l0 0c-7 0-12-5-12-12l0-69c0 0 0 0 0-1 0-6 5-11 12-11l182 0 0 0c6 0 11 5 11 11l0 69c0 1 0 1 0 1 0 7-5 12-11 12l-182 0z m772-153c-4 0-8-2-10-6l-34-60c-1 0-1 0-1 0-3-6-1-13 4-16l158-91c6-3 13-2 16 4l35 61c3 5 1 12-4 15l-158 91 0 0c-2 1-4 2-6 2z m-566-5c-1 0-3 0-5-1l-157-91c0 0-1 0-1 0-5-3-7-11-4-16l35-61c3-5 10-7 16-4l157 91c0 0 0 0 0 0 6 3 8 10 5 16l-35 61c-3 3-7 5-11 5z m468-121c-2 0-4 0-6-1l-61-35c-5-4-7-11-4-16l91-157c0-1 0-1 0-1 3-6 11-7 16-4l61 35c5 3 7 10 4 16l-91 157c0 0 0 0 0 0-2 4-6 6-10 6z m-367-3c-4 1-8-2-10-5l-91-158c-3-6-1-13 4-16l61-35c5-3 12-1 15 4l92 158 0 0c3 6 1 13-5 16l-60 34c0 1 0 1 0 1-2 1-4 1-6 1z m149-57c-7 0-12-5-12-11l0-183 0 0c0-6 5-11 12-11l69 0c0 0 0 0 1 0 6 0 11 5 11 11l0 183 0 0c0 6-5 11-11 11l-69 0c-1 0-1 0-1 0z" horiz-adv-x="1000" />
</font>
</defs>
</svg>

After

Width:  |  Height:  |  Size: 8.9 KiB

BIN
View File
Binary file not shown.
Binary file not shown.
+2 -2
View File
@@ -94,7 +94,7 @@
<div class="col-md-4" ng-repeat="r in rc.elements">
<span ng-show="rc.isVisible(r)"
id="{{r.key}}"
class="{{r.key}} element element-store {{ r.state.interesting ? 'blink' : '' }} {{'q'+r.state.color+'-12'}} {{r.state.amount>0 ? ' ui-draggable': 'empty'}}"
class="{{r.key}} element element-store {{ r.state.interesting ? 'blink' : '' }} {{r.color}} {{r.state.amount>0 ? ' ui-draggable': 'empty'}}"
data-element="{{r.key}}"
data-drag="true"
jqyoui-draggable="{containment:'offset'}"
@@ -123,7 +123,7 @@
<div id="detector-element-container" ng-cloak>
<div ng-repeat="r in dc.elements">
<span
class="{{r.key}} element q{{r.state.color}}-12 ui-draggable"
class="{{r.key}} element {{r.color}} ui-draggable"
data-element="{{r.key}}"
data-drag="true"
jqyoui-draggable="{containment:'offset'}"
+147 -109
View File
@@ -5,24 +5,10 @@
var app = (function () {
Helpers.validateSaveVersion();
// init game
// var game = new Game();
//
//
// var lab = game.lab;
// var elements = game.elements;
// var workers = game.workers;
// var upgrades = game.upgrades;
// var achievements = game.achievements;
// var allObjects = game.allObjects;
// var lastSaved;
var app = angular.module('scienceAlchemy', ['ngDragDrop', 'ui.grid']);
// directives
// factories to provide services. They serve shared game objects
// app.factory('elements', function () {
// var elements = Helpers.loadFile('json/elements.json');
@@ -36,84 +22,101 @@ var app = (function () {
// return elementStore;
// });
app.factory('game', function () {
var game = new Game();
game.load();
return game;
});
app.factory('detector', function () {
function game($http, $q, lab) {
var game = new Game();
game.lab=lab;
var promise = game.load($http, $q);
// return promise;
return game;
};
game.$inject = ['$http', '$q'];
app.factory('game', game);
function lab() {
if (!this.lab) this.lab = new GameObjects.Lab();
return this.lab;
};
app.factory('lab', lab);
function detector() {
var detector = new Detector();
detector.init(400);
return detector;
});
}
app.factory('detector', detector);
// add helpers as filters
app.filter('niceNumber', ['$filter', function ($filter) {
function niceNumber($filter) {
return Helpers.formatNumberPostfix;
}]);
};
niceNumber.$inject = ['$filter'];
app.filter('niceNumber', niceNumber);
app.filter('niceTime', ['$filter', function ($filter) {
function niceTime($filter) {
return Helpers.formatTime;
}]);
};
niceTime.$inject = ['$filter'];
app.filter('niceTime', niceTime);
app.filter('currency', ['$filter', function ($filter) {
function currency($filter) {
return function (input) {
return 'JTN ' + $filter('niceNumber')(input);
};
}]);
};
currency.$inject = ['$filter'];
app.filter('currency', currency);
app.filter('reverse', ['$filter', function ($filter) {
function reverse($filter) {
return function (items) {
return items.slice().reverse();
if (items instanceof Array)
return items.slice().reverse();
else
return items;
};
}]);
};
reverse.$inject = ['$filter'];
app.filter('reverse', reverse);
// controllers
app.controller('ElementController', ['$scope', '$compile', 'game', 'detector', function ($scope, $compile, game, detector) {
var vs = this;
vs.dragOptions = {
app.controller('ElementController', ElementController);
ElementController.$inject = ['$scope', '$compile', 'game', 'detector', 'lab'];
function ElementController($scope, $compile, game, detector, lab) {
var vm = this;
vm.dragOptions = {
revert: true, //"invalid",
zIndex: 100,
// helper: "clone", // drags a clone
// opacity: 0.75,
// start: vs.onRuneDrop.bind(vs),
// stop: vs.onRuneDrop.bind(vs),
// start: vm.onRuneDrop.bind(vs),
// stop: vm.onRuneDrop.bind(vs),
cancel: false,
// containment:false
};
vs.elements = game.elements;
vs.isVisible = function (item) {
return item.isVisible(game.lab);
vm.elements = game.elements;
vm.isVisible = function (item) {
return item.isVisible(lab);
};
vs.isAvailable = function (item) {
return item.isAvailable(game.lab);
vm.isAvailable = function (item) {
return item.isAvailable(lab);
};
vs.onDrop = function (event, ui) {
vm.onDrop = function (event, ui) {
// store the dropped element
var draggable = angular.element(ui.draggable);
var key = draggable.data('element');
if (!draggable.hasClass('element-store')) {
var elementStore = vs.elements.get(key);
var i = findIndexByHashKey(draggable.data('hashkey'));
var elementStore = vm.elements.get(key);
var i = _.findIndex(vm.elements,{$$hashKey:draggable.data('hashkey')});
detector.elements.splice(i, 1);
elementStore.state.amount += 1;
}
};
vs.doElement = function (item) {
var cost = item.element(game.lab);
if (cost > 0) {
UI.showUpdateValue("#update-data", -cost);
UI.showUpdateValue("#update-reputation", item.state.reputation);
}
};
vs.showInfo = function (r) {
UI.showModal(r.name, r.getInfo());
UI.showLevels(r.state.level);
};
}]);
};
app.controller('DetectorController', ['$scope', 'game', 'detector', function ($scope, game, detector) {
function DetectorController($scope, game, detector, lab) {
var vm = this;
vm.elements = detector.elements;
vm.dropOptions = {
@@ -137,12 +140,12 @@ var app = (function () {
vm.onDrop = function (event, ui) {
var result = detector.onDrop(event, ui, game);
if (result)
game.lab.observe(result);
lab.observe(result);
};
vm.click = function () {
game.lab.clickDetector();
lab.clickDetector();
detector.addEvent();
UI.showUpdateValue("#update-data", game.lab.state.detector);
UI.showUpdateValue("#update-data", lab.state.detector);
game.elements.addKnownToStore();
return false;
};
@@ -152,100 +155,135 @@ var app = (function () {
};
vm.clearAll = function () {
detector.clearAll(game);
}
}]);
};
};
DetectorController.$inject = ['$scope', 'game', 'detector', 'lab'];
app.controller('DetectorController', DetectorController);
app.controller('LabController', ['$interval', 'game', 'detector', function ($interval, game, detector) {
this.lab = game.lab;
this.showDetectorInfo = function () {
if (!this._detectorInfo) {
this._detectorInfo = Helpers.loadFile('html/detector.html');
function LabController($interval, game, detector, lab) {
// todo give workers instead of game
var vm = this;
vm.lab = lab;
vm.showDetectorInfo = function () {
if (!vm._detectorInfo) {
vm._detectorInfo = Helpers.loadFile('html/detector.html');
}
UI.showModal('Detector', this._detectorInfo);
UI.showModal('Detector', vm._detectorInfo);
};
$interval(function () { // one tick
var grant = game.lab.getGrant();
var grant = lab.getGrant();
UI.showUpdateValue("#update-funding", grant);
var sum = 0;
for (var i = 0; i < game.workers.length; i++) {
sum += game.workers[i].state.hired * game.workers[i].state.rate;
}
if (sum > 0) {
game.lab.acquireData(sum);
lab.acquireData(sum);
UI.showUpdateValue("#update-data", sum);
detector.addEventExternal(game.workers.map(function (w) {
return w.state.hired;
}).reduce(function (a, b) {
return a + b
return a + b;
}, 0));
}
}, 1000);
}]);
};
LabController.$inject = ['$interval', 'game', 'detector', 'lab'];
app.controller('LabController', LabController);
app.controller('ObservationsController', ['$scope', 'game', function ($scope, game) {
function ObservationsController($scope, game, lab) {
var vm = this;
vm.observations = game.lab.state.observations;
vm.observations = lab.state.observations;
vm.gridOptions = {
enableFiltering: true,
columnDefs: [
{ field: 'inputs', filter:{}, visible:true},
{ field: 'reactants', visible:false},
{ field: 'results', visible:true, sort: { direction: 'asc' }},
{ field: 'catalysts', visible:false},
{ field: 'conditions', visible:false},
],
columnDefs: [{
field: 'inputs',
filter: {},
visible: true
}, {
field: 'reactants',
visible: false
}, {
field: 'results',
visible: true,
sort: {
direction: 'asc'
}
}, {
field: 'catalysts',
visible: false
}, {
field: 'conditions',
visible: false
}, ],
data: vm.observations
};
}]);
};
ObservationsController.$inject = ['$scope', 'game', 'lab'];
app.controller('ObservationsController', ObservationsController);
app.controller('UpgradesController', ['$scope', 'game', function ($scope, game) {
this.upgrades = game.upgrades;
this.isVisible = function (upgrade) {
return upgrade.isVisible(game.lab, game.allObjects);
function UpgradesController($scope, game, lab) {
var vm = this;
vm.upgrades = game.upgrades;
vm.isVisible = function (upgrade) {
return upgrade.isVisible(lab, game.allObjects);
};
this.isAvailable = function (upgrade) {
return upgrade.isAvailable(game.lab, game.allObjects);
vm.isAvailable = function (upgrade) {
return upgrade.isAvailable(lab, game.allObjects);
};
this.upgrade = function (upgrade) {
if (upgrade.buy(game.lab, game.allObjects)) {
vm.upgrade = function (upgrade) {
if (upgrade.buy(lab, game.allObjects)) {
UI.showUpdateValue("#update-funding", upgrade.cost);
}
}
}]);
};
};
UpgradesController.$inject = ['$scope', 'game', 'lab'];
app.controller('UpgradesController', UpgradesController);
app.controller('AchievementsController', function ($scope, game) {
$scope.achievements = game.achievements;
$scope.progress = function () {
function AchievementsController($scope, game, lab) {
var vm = this;
vm.achievements = game.achievements;
vm.progress = function () {
return game.achievements.filter(function (a) {
return a.validate(game.lab, game.allObjects, game.lastSaved);
return a.validate(lab, game.allObjects, game.lastSaved);
}).length;
};
});
};
AchievementsController.$inject = ['$scope', 'game', 'lab'];
app.controller('AchievementsController', AchievementsController);
app.controller('SaveController', ['$scope', '$interval', 'game', function ($scope, $interval, game) {
function SaveController($scope, $interval, $window, game, lab) {
var vm = this;
game.lastSaved = new Date().getTime();
$scope.lastSaved = game.lastSaved;
$scope.saveNow = function () {
vm.lastSaved = game.lastSaved;
vm.saveNow = function () {
var saveTime = new Date().getTime();
game.lab.state.time += saveTime - game.lastSaved;
lab.state.time += saveTime - game.lastSaved;
game.save();
game.lastSaved = saveTime;
$scope.lastSaved = game.lastSaved;
vm.lastSaved = game.lastSaved;
};
$scope.restart = function () {
if (window.confirm(
vm.restart = function () {
if ($window.confirm(
'Do you really want to restart the game? All progress will be lost.'
)) {
ObjectStorage.clear();
window.location.reload(true);
$window.location.reload(true);
}
};
$interval($scope.saveNow, 10000);
}]);
$interval(vm.saveNow, 10000);
};
SaveController.$inject = ['$scope', '$interval', '$window', 'game', 'lab'];
app.controller('SaveController', SaveController);
app.controller('StatsController', ['$scope', 'game', function ($scope, game) {
$scope.lab = game.lab;
}]);
function StatsController($scope, lab) {
var vm = this;
vm.lab = lab;
};
StatsController.$inject = ['$scope', 'lab'];
app.controller('StatsController', StatsController);
analytics.init();
analytics.sendScreen(analytics.screens.main);
+18 -17
View File
@@ -6,8 +6,8 @@ var Detector = function(){
return {
core:
{
canvas: null,
ctx: null
// canvas: null,
// ctx: null
},
//
// events:
@@ -19,8 +19,8 @@ var Detector = function(){
flame:
{
canvas: null,
ctx: null
// canvas: null,
// ctx: null
},
elements: new GameObjects.ElementStores(),
@@ -39,15 +39,15 @@ var Detector = function(){
init: function(baseSize,element)
{
// get canvas
this.core.canvas = document.getElementById('detector-core');
if (!this.core.canvas) {
this.core.canvas=$('<canvas id="detector-core"></canvas>');
$(element).append(this.core.canvas);
}
this.core.ctx = this.core.canvas.getContext('2d');
this.flame.canvas = document.getElementById('detector-flame');
this.flame.ctx = this.flame.canvas.getContext('2d');
// this.core.canvas = document.getElementById('detector-core');
// if (!this.core.canvas) {
// this.core.canvas=$('<canvas id="detector-core"></canvas>');
// $(element).append(this.core.canvas);
// }
// this.core.ctx = this.core.canvas.getContext('2d');
//
// this.flame.canvas = document.getElementById('detector-flame');
// this.flame.ctx = this.flame.canvas.getContext('2d');
this.initBubbles();
this.initFlame();
@@ -130,8 +130,8 @@ var Detector = function(){
},
/** Clear an element back to element Store **/
storeElementByHashKey: function(hashKey,game){
var i = this.elements.findIndexByHashKey(hashKey);
storeElementBy: function(qObject,game){
var i = _.findIndex(this.elements,qObject);
var removedElement = this.elements.splice(i,1)[0];
return game.elements.get(removedElement.key).state.amount+=1;
},
@@ -139,7 +139,7 @@ var Detector = function(){
clearAll: function(game){
var hashKeys = this.elements.map(function(e){return e.$$hashKey;});
for (var i = 0; i < hashKeys.length; i++) {
this.storeElementByHashKey(hashKeys[i], game);
this.storeElementBy({'$$hashKey': hashKeys[i]}, game);
}
},
@@ -231,7 +231,8 @@ var Detector = function(){
for (var i = 0; i < reactants.length; i++) {
// get the uuid from inputs
var ingredient = inputs.filter(function(e){return e.key===reactants[i];})[0];
this.elements.findIndexByHashKey(ingredient.uuid);
var j = _.findIndex(this.elements,{uuid:ingredient.uuid});
var removed = this.elements.slice(j,1);
}
// TODO use angular effects to remove in puff of fade
+88 -43
View File
@@ -5,19 +5,20 @@ var Game = (function (Helpers, GameObjects, ObjectStorage) {
'use strict';
var Game = function () {
this.lab = new GameObjects.Lab();
// this.lab = new GameObjects.Lab();
this.elements = null;
this.workers = null;
this.upgrades = null;
this.achievements = null;
this.allObjects = {
lab: this.lab
// lab: this.lab
};
this.loaded = false;
this.rules = null;
};
Game.prototype.load = function () {
Game.prototype.load = function ($http, $q) {
var self = this;
if (this.loaded) {
return;
}
@@ -27,50 +28,94 @@ var Game = (function (Helpers, GameObjects, ObjectStorage) {
// make it work with Angular. If you know a way, let me know, and I'll
// give you a beer. - Kevin
this.elements = Helpers.loadFile('json/elements.json');
this.workers = Helpers.loadFile('json/workers.json');
this.upgrades = Helpers.loadFile('json/upgrades.json');
this.achievements = Helpers.loadFile('json/achievements.json');
this.keywords = Helpers.loadFile('json/keywords.json');
this.workers = Helpers.loadFile('/json/workers.json');
this.upgrades = Helpers.loadFile('./json/upgrades.json');
this.achievements = Helpers.loadFile('./json/achievements.json');
this.keywords = Helpers.loadFile('./json/keywords.json');
// Turn JSON files into actual game objects and fill map of all objects
var _this = this;
var makeGameObject = function (type, object) {
// It's okay to define this function here since load is only called
// once anyway...
var o = new type(object);
_this.allObjects[o.key] = o;
return o;
};
this.elements = this.elements.slice(0,20).map(
function (r) {
return makeGameObject(GameObjects.ElementStore, r);
});
this.workers = this.workers.map(
function (w) {
return makeGameObject(GameObjects.Worker, w);
});
this.upgrades = this.upgrades.map(
function (u) {
return makeGameObject(GameObjects.Upgrade, u);
});
this.achievements = this.achievements.map(
function (a) {
return makeGameObject(GameObjects.Achievement, a);
});
// Load states from local store
for (var key in this.allObjects) {
var o = this.allObjects[key];
o.loadState(ObjectStorage.load(key));
}
// function successCallback(response) {
// return angular.fromJson(response.data);
// }
//
// function errorCallback(response) {
// return console.error('Could not get url', response.statusText, response);
// }
// return $q.all(
// $http.get('json/elements.json', {
// transformResponse: angular.fromJson
// })
// .then(function (response) {
// return self.elements = response.data;
// }),
// $http.get('json/workers.json', {
// transformResponse: angular.fromJson
// })
// .then(function (response) {
// return self.workers = response.data;
// }),
// $http.get('json/upgrades.json', {
// transformResponse: angular.fromJson
// })
// .then(
// function (response) {
// return self.upgrades = response.data;
// }),
// $http.get('json/achievements.json', {
// transformResponse: angular.fromJson
// })
// .then(
// function (response) {
// return self.achievements = response.data;
// }),
// $http.get('json/keywords.json', {
// transformResponse: angular.fromJson
// })
// .then(
// function (response) {
// return self.keywords = response.data;
// })
// ).then(function () {
// put elements in extended array with utility methods
this.elementStore = new GameObjects.ElementStores();
this.elementStore.push.apply(this.elementStore, this.elements);
this.elements = this.elementStore;
// Turn JSON files into actual game objects and fill map of all objects
var makeGameObject = function (type, object) {
// It's okay to define this function here since load is only called
// once anyway...
var o = new type(object);
self.allObjects[o.key] = o;
return o;
};
self.elements = self.elements.slice(0, 20).map(
function (r) {
return makeGameObject(GameObjects.ElementStore, r);
});
self.workers = self.workers.map(
function (w) {
return makeGameObject(GameObjects.Worker, w);
});
self.upgrades = self.upgrades.map(
function (u) {
return makeGameObject(GameObjects.Upgrade, u);
});
self.achievements = self.achievements.map(
function (a) {
return makeGameObject(GameObjects.Achievement, a);
});
// Load states from local store
for (var key in self.allObjects) {
var o = self.allObjects[key];
o.loadState(ObjectStorage.load(key));
}
this.rules = this.generateRules();
// put elements in extended array with utility methods
self.elementStore = new GameObjects.ElementStores();
self.elementStore.push.apply(self.elementStore, self.elements);
self.elements = self.elementStore;
this.loaded = true;
self.rules = self.generateRules();
self.loaded = true;
return self;
// });
};
/** Generate rules between runes **/
+90 -83
View File
@@ -2,95 +2,102 @@
* Define some useful helpers that are used throughout the game.
*/
var Helpers = (function () {
'use strict';
/** Load a file (usually JSON).
*/
var loadFile = function (filename) {
var res;
$.ajax({
async: false,
url : filename,
success : function(data) {
res = data;
}
});
return res;
};
'use strict';
/** Load a file (usually JSON).
*/
var loadFile = function (filename) {
var res;
$.ajax({
async: false,
url: filename,
success: function (data) {
res = data;
}
});
return res;
};
var makeGameObject = function(type, object) {
// It's okay to define this function here since load is only called
// once anyway...
var o = new type(object);
_this.allObjects[o.key] = o;
return o;
};
/** Format a number with proper postfix.
*/
var formatNumberPostfix = function (number) {
if (typeof number !== "number") {
return 0;
}
/** Format a number with proper postfix.
*/
var formatNumberPostfix = function (number) {
if (typeof number !== "number") {
return 0;
var prefixes = [{
magnitude: 1e24,
label: 'Y'
}, {
magnitude: 1e21,
label: 'Z'
}, {
magnitude: 1e18,
label: 'E'
}, {
magnitude: 1e15,
label: 'P'
}, {
magnitude: 1e12,
label: 'T'
}, {
magnitude: 1e9,
label: 'B'
}, {
magnitude: 1e6,
label: 'M'
}, {
magnitude: 1e3,
label: 'k'
}];
var abs = Math.abs(number);
for (var i = 0; i < prefixes.length; i++) {
if (abs >= prefixes[i].magnitude) {
return (number / prefixes[i].magnitude).toFixed(1) + prefixes[i].label;
}
}
return number;
}
var prefixes = [
{ magnitude: 1e24, label: 'Y' },
{ magnitude: 1e21, label: 'Z' },
{ magnitude: 1e18, label: 'E' },
{ magnitude: 1e15, label: 'P' },
{ magnitude: 1e12, label: 'T' },
{ magnitude: 1e9, label: 'B' },
{ magnitude: 1e6, label: 'M' },
{ magnitude: 1e3, label: 'k' }
];
var formatTime = function (msec) {
var totals = Math.ceil(msec / 1000);
var days = Math.floor(totals / (24 * 60 * 60));
var hours = Math.floor((totals % (24 * 60 * 60)) / (60 * 60));
var totalmin = (totals % (24 * 60 * 60)) % (60 * 60);
var mins = Math.floor(totalmin / 60);
var secs = totalmin % 60;
var abs = Math.abs(number);
for (var i = 0; i < prefixes.length; i++) {
if (abs >= prefixes[i].magnitude) {
return (number / prefixes[i].magnitude).toFixed(1) + prefixes[i].label;
}
}
return number;
}
var str = [];
if (days > 0) {
str.push(days + ' day' + (days % 100 == 1 ? '' : 's'));
}
if (hours > 0) {
str.push(hours + ' h');
}
if (mins > 0) {
str.push(mins + ' min');
}
if (secs > 0) {
str.push(secs + ' s');
}
var formatTime = function (msec) {
var totals = Math.ceil(msec / 1000);
var days = Math.floor(totals / (24 * 60 * 60));
var hours = Math.floor((totals % (24 * 60 * 60)) / (60 * 60));
var totalmin = (totals % (24 * 60 * 60)) % (60 * 60);
var mins = Math.floor(totalmin / 60);
var secs = totalmin % 60;
return str.join(', ');
};
var str = [];
if (days > 0) {
str.push(days + ' day' + (days % 100 == 1 ? '' : 's'));
}
if (hours > 0) {
str.push(hours + ' h');
}
if (mins > 0) {
str.push(mins + ' min');
}
if (secs > 0) {
str.push(secs + ' s');
}
var saveVersion = '1.0';
var validateSaveVersion = function () {
var ver = ObjectStorage.load('saveVersion');
if (typeof ver === 'undefined' || ver != saveVersion) {
ObjectStorage.clear();
ObjectStorage.save('saveVersion', saveVersion);
}
};
return str.join(', ');
};
var saveVersion = '1.0';
var validateSaveVersion = function () {
var ver = ObjectStorage.load('saveVersion');
if (typeof ver === 'undefined' || ver != saveVersion) {
ObjectStorage.clear();
ObjectStorage.save('saveVersion', saveVersion);
}
};
return {
loadFile: loadFile,
formatNumberPostfix: formatNumberPostfix,
formatTime: formatTime,
validateSaveVersion: validateSaveVersion,
analytics: ''
};
return {
loadFile: loadFile,
formatNumberPostfix: formatNumberPostfix,
formatTime: formatTime,
validateSaveVersion: validateSaveVersion,
analytics: ''
};
})();
+59 -83
View File
@@ -1,83 +1,59 @@
[
{"key":""},
{"key":""},
{"key":""},
{"key":""},
{"key":""},
{"key":""},
{"key":""},
{"key":""},
{"key":""},
{"key":""},
{"key":""},
{"key":""},
{"key":""},
{"key":""},
{"key":""},
{"key":""},
{"key":""},
{"key":""},
{"key":""},
{"key":""},
{"key":""},
{"key":""},
{"key":""},
{"key":""},
{"key":""},
{"key":""},
{"key":""},
{"key":""},
{"key":""},
{"key":""},
{"key":""},
{"key":""},
{"key":""},
{"key":""},
{"key":""},
{"key":""},
{"key":""},
{"key":""},
{"key":""},
{"key":""},
{"key":""},
{"key":""},
{"key":""},
{"key":""},
{"key":""},
{"key":""},
{"key":""},
{"key":""},
{"key":""},
{"key":""},
{"key":""},
{"key":""},
{"key":""},
{"key":""},
{"key":""},
{"key":""},
{"key":""},
{"key":""},
{"key":"ᛚ"},
{"key":"ᛛ"},
{"key":"ᛜ"},
{"key":"ᛝ"},
{"key":"ᛞ"},
{"key":"ᛟ"},
{"key":"ᛠ"},
{"key":"ᛡ"},
{"key":"ᛢ"},
{"key":"ᛣ"},
{"key":"ᛤ"},
{"key":"ᛥ"},
{"key":"ᛦ"},
{"key":"ᛧ"},
{"key":"ᛨ"},
{"key":"ᛩ"},
{"key":"ᛪ"},
{"key":"᛫"},
{"key":""},
{"key":""},
{"key":"ᛮ"},
{"key":"ᛯ"},
{"key":"ᛰ"}
]
[{"key": "🂡","name":"Ace","value":"1","suite":"Spades","color":"Black","royal":"false","face":"false","number":"false"},
{"key": "🂢","name":"Two","value":"2","suite":"Spades","color":"Black","royal":"false","face":"false","number":"true"},
{"key": "🂣","name":"Three","value":"3","suite":"Spades","color":"Black","royal":"false","face":"false","number":"true"},
{"key": "🂤","name":"Four","value":"4","suite":"Spades","color":"Black","royal":"false","face":"false","number":"true"},
{"key": "🂥","name":"Five","value":"5","suite":"Spades","color":"Black","royal":"false","face":"false","number":"true"},
{"key": "🂦","name":"Six","value":"6","suite":"Spades","color":"Black","royal":"false","face":"false","number":"true"},
{"key": "🂧","name":"Seven","value":"7","suite":"Spades","color":"Black","royal":"false","face":"false","number":"true"},
{"key": "🂨","name":"Eight","value":"8","suite":"Spades","color":"Black","royal":"false","face":"false","number":"true"},
{"key": "🂩","name":"Nine","value":"9","suite":"Spades","color":"Black","royal":"false","face":"false","number":"true"},
{"key": "🂪","name":"Ten","value":"10","suite":"Spades","color":"Black","royal":"false","face":"true","number":"true"},
{"key": "🂫","name":"Jack","value":"11","suite":"Spades","color":"Black","royal":"true","face":"true","number":"false"},
{"key": "🂬","name":"Knight","value":"12","suite":"Spades","color":"Black","royal":"true","face":"true","number":"false"},
{"key": "🂭","name":"Queen","value":"13","suite":"Spades","color":"Black","royal":"true","face":"true","number":"false"},
{"key": "🂮","name":"King","value":"14","suite":"Spades","color":"Black","royal":"true","face":"true","number":"false"},
{"key": "🂱","name":"Ace","value":"1","suite":"Hearts","color":"Red","royal":"false","face":"false","number":"false"},
{"key": "🂲","name":"Two","value":"2","suite":"Hearts","color":"Red","royal":"false","face":"false","number":"true"},
{"key": "🂳","name":"Three","value":"3","suite":"Hearts","color":"Red","royal":"false","face":"false","number":"true"},
{"key": "🂴","name":"Four","value":"4","suite":"Hearts","color":"Red","royal":"false","face":"false","number":"true"},
{"key": "🂵","name":"Five","value":"5","suite":"Hearts","color":"Red","royal":"false","face":"false","number":"true"},
{"key": "🂶","name":"Six","value":"6","suite":"Hearts","color":"Red","royal":"false","face":"false","number":"true"},
{"key": "🂷","name":"Seven","value":"7","suite":"Hearts","color":"Red","royal":"false","face":"false","number":"true"},
{"key": "🂸","name":"Eight","value":"8","suite":"Hearts","color":"Red","royal":"false","face":"false","number":"true"},
{"key": "🂹","name":"Nine","value":"9","suite":"Hearts","color":"Red","royal":"false","face":"false","number":"true"},
{"key": "🂺","name":"Ten","value":"10","suite":"Hearts","color":"Red","royal":"false","face":"true","number":"true"},
{"key": "🂻","name":"Jack","value":"11","suite":"Hearts","color":"Red","royal":"true","face":"true","number":"false"},
{"key": "🂼","name":"Knight","value":"12","suite":"Hearts","color":"Red","royal":"true","face":"true","number":"false"},
{"key": "🂽","name":"Queen","value":"13","suite":"Hearts","color":"Red","royal":"true","face":"true","number":"false"},
{"key": "🂾","name":"King","value":"14","suite":"Hearts","color":"Red","royal":"true","face":"true","number":"false"},
{"key": "🃁","name":"Ace","value":"1","suite":"Diamonds","color":"Red","royal":"false","face":"false","number":"false"},
{"key": "🃂","name":"Two","value":"2","suite":"Diamonds","color":"Red","royal":"false","face":"false","number":"true"},
{"key": "🃃","name":"Three","value":"3","suite":"Diamonds","color":"Red","royal":"false","face":"false","number":"true"},
{"key": "🃄","name":"Four","value":"4","suite":"Diamonds","color":"Red","royal":"false","face":"false","number":"true"},
{"key": "🃅","name":"Five","value":"5","suite":"Diamonds","color":"Red","royal":"false","face":"false","number":"true"},
{"key": "🃆","name":"Six","value":"6","suite":"Diamonds","color":"Red","royal":"false","face":"false","number":"true"},
{"key": "🃇","name":"Seven","value":"7","suite":"Diamonds","color":"Red","royal":"false","face":"false","number":"true"},
{"key": "🃈","name":"Eight","value":"8","suite":"Diamonds","color":"Red","royal":"false","face":"false","number":"true"},
{"key": "🃉","name":"Nine","value":"9","suite":"Diamonds","color":"Red","royal":"false","face":"false","number":"true"},
{"key": "🃊","name":"Ten","value":"10","suite":"Diamonds","color":"Red","royal":"false","face":"true","number":"true"},
{"key": "🃋","name":"Jack","value":"11","suite":"Diamonds","color":"Red","royal":"true","face":"true","number":"false"},
{"key": "🃌","name":"Knight","value":"12","suite":"Diamonds","color":"Red","royal":"true","face":"true","number":"false"},
{"key": "🃍","name":"Queen","value":"13","suite":"Diamonds","color":"Red","royal":"true","face":"true","number":"false"},
{"key": "🃎","name":"King","value":"14","suite":"Diamonds","color":"Red","royal":"true","face":"true","number":"false"},
{"key": "🃑","name":"Ace","value":"1","suite":"Clubs","color":"Black","royal":"false","face":"false","number":"false"},
{"key": "🃒","name":"Two","value":"2","suite":"Clubs","color":"Black","royal":"false","face":"false","number":"true"},
{"key": "🃓","name":"Three","value":"3","suite":"Clubs","color":"Black","royal":"false","face":"false","number":"true"},
{"key": "🃔","name":"Four","value":"4","suite":"Clubs","color":"Black","royal":"false","face":"false","number":"true"},
{"key": "🃕","name":"Five","value":"5","suite":"Clubs","color":"Black","royal":"false","face":"false","number":"true"},
{"key": "🃖","name":"Six","value":"6","suite":"Clubs","color":"Black","royal":"false","face":"false","number":"true"},
{"key": "🃗","name":"Seven","value":"7","suite":"Clubs","color":"Black","royal":"false","face":"false","number":"true"},
{"key": "🃘","name":"Eight","value":"8","suite":"Clubs","color":"Black","royal":"false","face":"false","number":"true"},
{"key": "🃙","name":"Nine","value":"9","suite":"Clubs","color":"Black","royal":"false","face":"false","number":"true"},
{"key": "🃚","name":"Ten","value":"10","suite":"Clubs","color":"Black","royal":"false","face":"true","number":"true"},
{"key": "🃛","name":"Jack","value":"11","suite":"Clubs","color":"Black","royal":"true","face":"true","number":"false"},
{"key": "🃜","name":"Knight","value":"12","suite":"Clubs","color":"Black","royal":"true","face":"true","number":"false"},
{"key": "🃝","name":"Queen","value":"13","suite":"Clubs","color":"Black","royal":"true","face":"true","number":"false"},
{"key": "🃞","name":"King","value":"14","suite":"Clubs","color":"Black","royal":"true","face":"true","number":"false"},
{"key": "🂠","name":"Playing Card","value":"15","suite":"Black","color":"Black","royal":"false","face":"false","number":"false"},
{"key": "🃏","name":"Joker","value":"16","suite":"Black","color":"Black","royal":"false","face":"true","number":"false"},
{"key": "🃟","name":"Joker","value":"16","suite":"Red","color":"Red","royal":"false","face":"true","number":"false"}]
+41
View File
@@ -0,0 +1,41 @@
{
"name": "sciencealchemy",
"version": "0.0.5",
"description": "Science Alchemy",
"main": "js/app.js",
"directories": {
"test": "tests"
},
"scripts": {
"postinstall": "bower install",
"prestart": "npm install",
"start": "http-server -a 0.0.0.0 -p 8000",
"pretest": "npm install",
"test": "node node_modules/karma/bin/karma start test/karma.conf.js",
"test-single-run": "node node_modules/karma/bin/karma start test/karma.conf.js --single-run",
"preupdate-webdriver": "npm install",
"update-webdriver": "webdriver-manager update",
"preprotractor": "npm run update-webdriver",
"protractor": "protractor test/protractor-conf.js",
"update-index-async": "node -e \"require('shelljs/global'); sed('-i', /\\/\\/@@NG_LOADER_START@@[\\s\\S]*\\/\\/@@NG_LOADER_END@@/, '//@@NG_LOADER_START@@\\n' + cat('bower_components/angular-loader/angular-loader.min.js') + '\\n//@@NG_LOADER_END@@', 'app/index-async.html');\""
},
"author": "wassname",
"license": "MIT",
"devDependencies": {
"bower": "^1.7.7",
"eslint": "^2.2.0",
"eslint-config-angular": "^0.4.0",
"eslint-plugin-angular": "^0.15.0",
"http-server": "^0.9.0",
"jasmine": "^2.4.1",
"karma": "^0.13.21",
"karma-chrome-launcher": "^0.2.2",
"karma-firefox-launcher": "^0.1.7",
"karma-jasmine": "^0.3.7",
"ng-html2js": "^2.0.0",
"protractor": "^3.1.1",
"shelljs": "^0.6.0",
"tmp": "0.0.28",
"webdriver": "0.0.1"
}
}
+101
View File
@@ -0,0 +1,101 @@
'use strict';
/* http://docs.angularjs.org/guide/dev_guide.e2e-testing */
describe('PhoneCat App', function() {
it('should redirect index.html to index.html#/phones', function() {
browser.get('app/index.html');
browser.getLocationAbsUrl().then(function(url) {
expect(url).toEqual('/phones');
});
});
describe('Phone list view', function() {
beforeEach(function() {
browser.get('app/index.html#/phones');
});
it('should filter the phone list as a user types into the search box', function() {
var phoneList = element.all(by.repeater('phone in phones'));
var query = element(by.model('query'));
expect(phoneList.count()).toBe(20);
query.sendKeys('nexus');
expect(phoneList.count()).toBe(1);
query.clear();
query.sendKeys('motorola');
expect(phoneList.count()).toBe(8);
});
it('should be possible to control phone order via the drop down select box', function() {
var phoneNameColumn = element.all(by.repeater('phone in phones').column('phone.name'));
var query = element(by.model('query'));
function getNames() {
return phoneNameColumn.map(function(elm) {
return elm.getText();
});
}
query.sendKeys('tablet'); //let's narrow the dataset to make the test assertions shorter
expect(getNames()).toEqual([
"Motorola XOOM\u2122 with Wi-Fi",
"MOTOROLA XOOM\u2122"
]);
element(by.model('orderProp')).element(by.css('option[value="name"]')).click();
expect(getNames()).toEqual([
"MOTOROLA XOOM\u2122",
"Motorola XOOM\u2122 with Wi-Fi"
]);
});
it('should render phone specific links', function() {
var query = element(by.model('query'));
query.sendKeys('nexus');
element.all(by.css('.phones li a')).first().click();
browser.getLocationAbsUrl().then(function(url) {
expect(url).toEqual('/phones/nexus-s');
});
});
});
describe('Phone detail view', function() {
beforeEach(function() {
browser.get('app/index.html#/phones/nexus-s');
});
it('should display nexus-s page', function() {
expect(element(by.binding('phone.name')).getText()).toBe('Nexus S');
});
it('should display the first phone image as the main phone image', function() {
expect(element(by.css('img.phone.active')).getAttribute('src')).toMatch(/img\/phones\/nexus-s.0.jpg/);
});
it('should swap main image if a thumbnail image is clicked on', function() {
element(by.css('.phone-thumbs li:nth-child(3) img')).click();
expect(element(by.css('img.phone.active')).getAttribute('src')).toMatch(/img\/phones\/nexus-s.2.jpg/);
element(by.css('.phone-thumbs li:nth-child(1) img')).click();
expect(element(by.css('img.phone.active')).getAttribute('src')).toMatch(/img\/phones\/nexus-s.0.jpg/);
});
});
});
+101
View File
@@ -0,0 +1,101 @@
module.exports = function (config) {
config.set({
basePath: '../',
port: 9876,
// urlRoot: "/",
// enable / disable watching file and executing tests whenever any file changes
autoWatch: true,
// enable / disable colors in the output (reporters and logs)
colors: true,
frameworks: ['jasmine'],
browsers: ['Chrome', 'Firefox'],
plugins: [
'karma-chrome-launcher',
'karma-firefox-launcher',
'karma-jasmine'
],
junitReporter: {
outputFile: 'test_out/unit.xml',
suite: 'unit'
},
preprocessors: {
"*.html": ["ng-html2js"]
},
// ngHtml2JsPreprocessor: {
// // If your build process changes the path to your templates,
// // use stripPrefix and prependPrefix to adjust it.
// // stripPrefix: "source/path/to/templates/.*/",
// // prependPrefix: "web/path/to/templates/",
//
// // the name of the Angular module to create
// moduleName: "scienceAlchemy.templates"
// },
// use this to fix server 404 errors. Karma server everything at /base
proxies: {
'/json/': '/base/json/'
},
// list of files / patterns to load in the browser
files: [
// dependencies
'bower_components/jquery/dist/jquery.js',
'bower_components/jquery-ui/jquery-ui.js',
'bower_components/bootstrap/dist/js/bootstrap.js',
'bower_components/angular/angular.js',
'bower_components/angular-route/angular-route.js',
'bower_components/angular-resource/angular-resource.js',
'bower_components/angular-animate/angular-animate.js',
'bower_components/angular-mocks/angular-mocks.js',
'bower_components/angular-dragdrop/src/angular-dragdrop.js',
'bower_components/angular-ui-grid/ui-grid.js',
'bower_components/lodash/dist/lodash.js',
'js/external/*.js',
// fixtures
{
pattern: 'index.html',
watched: true,
served: true,
included: false
}, {
pattern: 'json/*.json',
watched: true,
served: true,
included: false
},
{
pattern: 'css/*.css',
watched: true,
served: true,
included: false
},
// files to test
'js/storage.js',
'js/helpers.js',
'js/analytics.js',
'js/gameobjects.js',
'js/detector/flame.js',
'js/detector/bubblr.js',
'js/detector/event.js',
'js/detector/detector.js',
'js/ui.js',
'js/game.js',
'js/app.js',
'test/unit/**/*.js'
],
});
};
+22
View File
@@ -0,0 +1,22 @@
exports.config = {
allScriptsTimeout: 11000,
specs: [
'e2e/*.js'
],
capabilities: {
'browserName': 'chrome'
},
chromeOnly: true,
baseUrl: 'http://localhost:8000/',
framework: 'jasmine',
jasmineNodeOpts: {
defaultTimeoutInterval: 30000
}
};
+53
View File
@@ -0,0 +1,53 @@
'use strict';
/* jasmine specs for controllers go here */
describe('scienceAlchemy controllers', function () {
var $controller;
beforeEach(function () {
jasmine.addMatchers({
toEqualData: function(util, customEqualityTesters) {
return {
compare: function(actual, expected) {
var passed = angular.equals(actual, expected);
return {
pass: passed,
message: 'Expected "' + actual + '"' + (passed ? '' : ' not') + ' to angular.equals "' + expected + '"'
};
}
};
}
});
});
beforeEach(module('scienceAlchemy'));
beforeEach(inject(function (_$controller_) {
// The injector unwraps the underscores (_) from around the parameter names when matching
$controller = _$controller_;
}));
describe('ElementController', function () {
var $scope, controller;
beforeEach(function () {
$scope = {};
controller = $controller('ElementController',{$scope:$scope});
});
it('should have elements', function () {
expect(controller.elements).toBeDefined();
});
it('should be visible', function () {
var item = controller.elements[0];
expect(controller.isVisible(item)).toBeDefined();
});
it('should be isAvailable', function () {
var item = controller.elements[0];
expect(controller.isAvailable(item)).toBeDefined();
});
// onDrop
});
});
+7
View File
@@ -0,0 +1,7 @@
'use strict';
/* jasmine specs for directives go here */
describe('directives', function() {
});
+53
View File
@@ -0,0 +1,53 @@
'use strict';
/* jasmine specs for filters go here */
describe('filter', function () {
beforeEach(
module('scienceAlchemy')
);
describe('niceNumber', function () {
it('should make numbers human readable',
inject(function (niceNumberFilter) {
expect(niceNumberFilter(100000000)).toBe("100.0M");
expect(niceNumberFilter(10000)).toBe("10.0k");
expect(niceNumberFilter(0.000000001)).toBe(1e-9);
}));
});
describe('niceTime', function () {
it('should make time human readable',
inject(function (niceTimeFilter) {
expect(niceTimeFilter(100000000)).toBe("1 day, 3 h, 46 min, 40 s");
expect(niceTimeFilter(10000)).toBe("10 s");
expect(niceTimeFilter(0.000000001)).toBe("1 s");
}));
});
describe('currency', function () {
it('should make currency human readable',
inject(function (currencyFilter) {
expect(currencyFilter(100000000)).toBe("JTN 100.0M");
expect(currencyFilter(10000)).toBe("JTN 10.0k");
expect(currencyFilter(0.000000001)).toBe('JTN 1e-9');
}));
});
describe('reverse', function () {
it('should reverse',
inject(function (reverseFilter) {
expect(reverseFilter([1,2,3])[0]).toBe(3);
expect(reverseFilter([1,2,3])[1]).toBe(2);
expect(reverseFilter([1,2,3])[2]).toBe(1);
expect(reverseFilter([]).length).toBe(0);
expect(reverseFilter([{i:1,2:2},{i:2},{i:3}])[0].i).toBe(3);
expect(reverseFilter([{i:1,2:2},{i:2},{i:3}])[1].i).toBe(2);
expect(reverseFilter([{i:1,2:2},{i:2},{i:3}])[2].i).toBe(1);
}));
});
});
+27
View File
@@ -0,0 +1,27 @@
'use strict';
describe('services', function () {
//load modules
beforeEach(module('scienceAlchemy'));
// Test service availability
describe('game', function () {
it('should exist', inject(function (game) {
expect(game).toBeDefined();
}));
});
describe('detector', function () {
it('should exist', inject(function (detector) {
expect(detector).toBeDefined();
}));
});
describe('lab', function () {
it('should exist', inject(function (lab) {
expect(lab).toBeDefined();
}));
});
});