diff --git a/.gitignore b/.gitignore index 986d545..d80831f 100644 --- a/.gitignore +++ b/.gitignore @@ -1,8 +1,9 @@ .DS_Store *.sublime* notes - - +secrets +build +dist # Created by https://www.gitignore.io/api/bower,node,linux diff --git a/css/style.css b/css/style.css index b16c5cd..5bb1e08 100644 --- a/css/style.css +++ b/css/style.css @@ -8,7 +8,7 @@ button, .badge, .modal-content { a, button { transition:all 0.2s; - -webkit-transition:all 0.2s; } + -webkit-transition:all 0.2s; } h1 br { diff --git a/favicon.ico b/favicon.ico deleted file mode 100644 index d6f9532..0000000 Binary files a/favicon.ico and /dev/null differ diff --git a/gulpfile.js b/gulpfile.js new file mode 100644 index 0000000..b912aeb --- /dev/null +++ b/gulpfile.js @@ -0,0 +1,85 @@ +'use strict'; +var gulp = require('gulp'); +// var path = require('path'); +var fs = require('fs'); +var gutil = require('gulp-util') + +// var source = require('vinyl-source-stream'); +// var buffer = require('vinyl-buffer'); +// var del = require('del'); +// var globby = require('globby'); + +var concurrent = require("concurrent-transform"); +var rename = require('gulp-rename'); +var awspublish = require('gulp-awspublish'); +var debug = require('gulp-debug'); + +// load in settings +var pjson = require('./package.json'); +var production = (process.env.NODE_ENV === 'production'); + +var DEBUG = !production; +console.log('Running in DEBUG='+DEBUG+' mode') + +var config = { + app_entry: 'client/scripts/main.js', + debug: DEBUG, +} + +/* +Just run webpack + */ +DEBUG = false +var webpack = require('webpack-stream'); +gulp.task('webpack', function () { + + var webpackConfig = require('./webpack.config.js') + console.log('debug: ', webpackConfig.debug); + + return gulp.src(config.app_entry) + .pipe(webpack(require('./webpack.config.js'))) + .pipe(gulp.dest('dist/')); +}); + + +/** deploy to s3 using gulp-awspublish + * https://github.com/pgherveou/gulp-awspublish + **/ + +gulp.task('s3', function () { + + // create a new publisher using S3 options + // http://docs.aws.amazon.com/AWSJavaScriptSDK/latest/AWS/S3.html#constructor-property + var credentials = JSON.parse(fs.readFileSync('secrets/aws-credentials.json', 'utf8')); + var publisher = awspublish.create(credentials); + + // define custom headers + var headers = { + 'Cache-Control': 'max-age=315360000, no-transform, public' + // ... + }; + + return gulp.src('./dist/**',{cwd:'.'}) + + // rename to put in subfolder + .pipe(rename(function (path) { + path.dirname = pjson.name + '/' + path.dirname; + })) + + // gzip, Set Content-Encoding headers and add .gz extension + .pipe(awspublish.gzip()) + + // publisher will add Content-Length, Content-Type and headers specified above + // If not specified it will set x-amz-acl to public-read by default + // Noe: this has been made concurrent using concurrent-transform + .pipe(concurrent(publisher.publish(headers,{'force':true})), 10) + + // create a cache file to speed up consecutive uploads + .pipe(publisher.cache()) + + // print upload updates to console + .pipe(awspublish.reporter()); +}); + +gulp.task('default', ['webpack']); +gulp.task('deploy', ['webpack','s3']); diff --git a/html/BBbar.html b/html/BBbar.html deleted file mode 100644 index 024ddeb..0000000 --- a/html/BBbar.html +++ /dev/null @@ -1,18 +0,0 @@ -

You discovered the Oscillation of Neutral B Mesons.

-
The Oscillation of Neutral B mesons
- -

-Like neutral Kaons (with which CP violation was discovered for the first time), neutral B mesons can also spontaneously turn into their own antiparticle. -Although suspected for a long time, this was first discovered in 1987 by the ARGUS collaboration at DESY in Germany. -

-

-With neutral B mesons, CP violation can now be studied very effectively. -Important experiments making use of B oscillation have been the so-called B factories BaBar (in the US) and Belle (in Japan), as well as LHCb at CERN. -These experiments have studied CP violation on a massive scale, looking at a large number of different decays of B mesons, as well as (more recently) Bs mesons and D mesons. -So far, no deviation from the CKM mechanism by Kobayashi and Maskawa has been observed. -

- -
Resources
- diff --git a/html/CPV.html b/html/CPV.html deleted file mode 100644 index 1155032..0000000 --- a/html/CPV.html +++ /dev/null @@ -1,71 +0,0 @@ -

You discovered CP violation!

- -
-

The Mystery of CP Violation

-

- The study of CP violation is concerned with some very fundamental questions:
-

-

-
- -
-

What is CP?

-

- CP is a possible symmetry of nature. - If the laws of nature were symmetric under CP, then matter and antimatter would be governed by the same rules. - This means that if we communicated with aliens from a distant galaxy, there would be no way to find out if they are made from matter or antimatter: - No experiment they could perform would allow us to deduce if they lived in a matter or antimatter world. - On the other hand, if there was a fundamental difference between matter and antimatter, such an experiment would be possible. - It turns out that this is the case in our universe! -

-
- -
-

How was CP violation discovered?

-

- In 1964, a team lead by Val Fitch and Jim Cronin performed experiments with neutral Kaons, particles formed by a strange and an anti-down quark. - These neutral Kaons have the amazing property that they can spontaneously transform into their own antiparticle. - Fitch and Cronin discovered that the rate at which these Kaons changed from matter to antimatter and vice versa was different, clear evidence for CP violation! - This discovery came as a total surprise to physicists (it was assumed that nature was symmetric under CP) and earned Cronin and Fitch the Nobel price in 1980. -

-
- -
-

How is CP violation currently understood?

-

- In 1973, two Japanese physicists, Makoto Kobayashi and Toshihide Maskawa, found a very simple and elegant way to explain the occurence of CP violation in our universe. - The only problem: The explanation required a third generation of quarks (the top and bottom quarks) for which there was zero evidence at the time. -

-

- This turned out to be an incredible prediction, when both of these quarks were discovered decades later. - So far, the idea of Kobayashi and Maskawa, called the CKM mechanism, has been able to explain every single occurence of CP violation that physicists managed to detect in the lab. - They were awarded the Nobel price in 2008. -

-
- -
-

What's next for CP violation?

-

- CP violation is one of the necessary ingredients for explaining the abundance of matter over antimatter in our universe. - But there is one problem: The CKM mechanism predicts too little of it. - The amount of matter in our universe suggests that a correction or even a complete revolution in our understanding of CP violation is necessary. -

-

- CP violation remains a hot topic in Physics research. - Specialized experiments like the LHCb detector at CERN in Switzerland are currently searching for hints of New Physics that could explain how our universe came to be the way it is. -

-
- - -
-
-
Resources
- -
diff --git a/html/Dstar_s.html b/html/Dstar_s.html deleted file mode 100644 index 634a729..0000000 --- a/html/Dstar_s.html +++ /dev/null @@ -1,10 +0,0 @@ -

You discovered the D*sJ(2860)- meson.

- -
-
-
Resources
- -
diff --git a/html/H.html b/html/H.html deleted file mode 100644 index 687cf2b..0000000 --- a/html/H.html +++ /dev/null @@ -1,74 +0,0 @@ -

You did it! You discovered the Higgs-boson!

- -
-

The Higgs field

-

- The Higgs-Englert field has a central role in our current understanding of the universe. - Through a process called Spontaneous Symmetry Breaking, it is responsible for the masses of all massive fundamental particles that we know of. -

-
- -
-

What is Spontaneous Symmetry Breaking?

-

- At every point in space, the Higgs field has a certain strength, a number that tells you how active the field is. - This is quite similar to temperature: You can assign a temperature to every point in a room, and the temperatures might be different for different points in the room and even change with time. -

-

- The Higgs-Englert field is the most special fundamental field that we know of: It interacts with nearly all of the other fields (like the electron field or the quark fields). - This means that the Higgs field can greatly influence the other fields: If it is active somewhere, then electrons, quarks and other particles in that region will be slowed down by it. - This is equivalent to them gaining mass! -

-

- But if the Higgs field would have an average strength of zero (as is usual for a field), then we would not be able to observe this slowdown (meaning no mass for other particles). -

-

- So how come this is not the case? - It turns out that the Higgs field's potential, which governs how much energy is needed to increase its strength, has a very special form (see below). - If the energy density in the universe is low enough, the field will drop down into the valley in the potential. - This means it will be locked to a non-zero strength, and other particles gain mass everywhere in the universe! -

- -

- Source: Flip Tanedo -

-
- -
-

Higgs' contribution

-

- The mechanism of spontaneous symmetry breaking was discovered and explored by various different researchers. - But it was Peter Higgs who first proposed, in 1964, that we could find evidence of it by searching for a new fundamental particle, now called the Higgs boson. -

-
- -
-

Discovery at the LHC

-

- After decades of work, the discovery of the Higgs boson was announced in 2012 by the ATLAS and CMS collaborations at CERN. - In 2013, Englert and Higgs received a Nobel Price for their contributions to the Higgs mechanism and the prediction of the Higgs particle. -

-
- -
-

The future of Higgs physics

-

- You might think that we now know everything there is to know about the Higgs field, but it turns out that we actually know very little! - Questions like -

- are sure to have physicists on the edge of their seats for many years to come! -

-
- -
-
Resources
- -
- diff --git a/html/Jpsi.html b/html/Jpsi.html deleted file mode 100644 index 7bfa08f..0000000 --- a/html/Jpsi.html +++ /dev/null @@ -1,27 +0,0 @@ -

You discovered the J/ψ meson!

- -
-

The J/ψ meson

- A plot from one of the original publications -

- The J/ψ is a meson consisting of a charm quark and its antiquark. It is the first excited state of the charmonium (a bound charm-anticharm state), and was discovered independently by two research groups in 1974: one at the Stanford Linear Accelerator Center, led by Burton Richter, and one at the Brookhaven National Laboratory, led by Samuel Ting of MIT. Richter and Ting were awarded the 1976 Nobel Prize in Physics for their shared discovery. -

-
- -
-
History of the name
-

- The J/ψ is the only particle with a two-letter name, as a result of its nearly simultaneous discovery by two independent groups. Ting wanted to name the particle “J”, while Richter called it “SP” (after the SPEAR accelerator used at SLAC), a name none of his colleagues liked. Richter finally settled on the Greek letter “ψ” (pronounced “psi”). -

-

- Since the scientific community considered it unjust to give one of the two discoverers priority, most subsequent publications have referred to the particle as the “J/ψ”. -

-
- -
-
Resources
- diff --git a/html/Xi_b.html b/html/Xi_b.html deleted file mode 100644 index d0cbbe8..0000000 --- a/html/Xi_b.html +++ /dev/null @@ -1,11 +0,0 @@ -

You discovered the Ξb'- and the Ξb*- baryons.

- -
-
-
Resources
- -
diff --git a/html/b.html b/html/b.html deleted file mode 100644 index 6490f40..0000000 --- a/html/b.html +++ /dev/null @@ -1,29 +0,0 @@ -

You discovered the bottom quark!

- -
-

The bottom (or beauty) quark

- A plot from one of the original publications -

- The bottom (or beauty) quark is a third-generation quark with a charge of −⅓ times the electron charge. - It has a large mass (around 4.2 GeV/c2 — more that four times the mass of a proton!). - The bottom quark is notable because it is a product in almost all decays of the top quark and is a frequent decay product for the Higgs boson. -

-
- -
-
History of the discovery
-

- The bottom quark was predicted in 1973 by physicists Makoto Kobayashi and Toshihide Maskawa as part of their explanation for CP violation. - The name “bottom” was introduced in 1975 by Haim Harari. - The bottom quark was discovered in 1977 by the Fermilab E288 experiment team led by Leon M. Lederman, when collisions produced bottomonia (mesons with a bottom quark and its antiquark). - Kobayashi and Maskawa won the 2008 Nobel Prize in Physics for their explanation of CP violation. - Upon its discovery, there were efforts to name the bottom quark “beauty”, but “bottom” became the predominant name. -

-
- -
-
Resources
- diff --git a/html/detector.html b/html/detector.html index d8890e7..ae94e9c 100644 --- a/html/detector.html +++ b/html/detector.html @@ -1,38 +1,13 @@ -

What are particle detectors?

+

Cards for science

-Particle detectors can be thought of as high-tech cameras that take “photographs” of phenomena that physicists want to study. These phenomena may originate in nuclear decays, cosmic radiation or interactions in a particle accelerator. Let us take a closer look at detectors such as those used at the LHC, which consist of layers of specialized components each designed to specific particles and identify certain properties. +This is a game with a secret rule. You try to put down the next card and work out the rule by trial and error. The rule is randomised each time and there are hints available. At it's base this is a game of inductive reason and the scientific method.

-
Components
- -
  Tracker

- The tracker helps us to calculate the momentum of charged particles. They bend due to magnetic field. The smaller the curve radius is, the less momentum the particle had. We also differentiate positive and negative particles based on the direction of the track. +Hints:

-
  Electromagnetic calorimeter

- The Electromagnetic Calorimeter (ECAL) is used to measure the energies of electrons and photons. +This game is based on Eleusis by Robert Abbott and John Golden's Eleusis Express.

- -
  Hadronic calorimeter
-

- The Hadron Calorimeter (HCAL) is used to measure the energy of hadrons, composite particles that made of quarks and gluons. Some examples of hadrons are protons, neutrons and pions. It also helps us detect neutrinos but indirectly. Energy needs to be conserved, so if we observe missing enery, this indicates neutrinos or as-yet-undiscovered particles flew through the detector. -

- -
  Magnet
-

- Particle detectors require magnets with very strong magnetic fields in order to sufficiently bend particles flying with high momenta. Trajectories of particles with higher momenta bend less, while those with lower momenta bend a lot more. The magnetic field also helps distinguish between positively and negatively charged particles: they bend in opposite directions in the same magnetic field. -

- -
  Muon chamber
-

- Muons are charged particles that are just like electrons and positrons, but are 200 times more massive. Because they can penetrate several metres of iron without interacting, the muon chamber is placed at the very edge of the detector where they are the only particles likely to register a signal. -

- -
Resources
- diff --git a/html/gluons.html b/html/gluons.html deleted file mode 100644 index 263aa0b..0000000 --- a/html/gluons.html +++ /dev/null @@ -1,29 +0,0 @@ - -

You discovered the strong interaction!

- -
-

Quarks and Gluons

-

- For a long time, it was believed that the Proton and the Neutron, which make up the atomic nucleus, were fundamental particles. - During the 1950s and 1960, an immense number of new, seemingly fundamental particles was discovered. - This "particle zoo" confused physicists greatly, until a radical idea was proposed in 1964: - What if these new particles were not fundamental, but instead made up of other particles, called quarks. - These quarks would have a new three-fold charge called "color charge" (which has nothing to do with visible colors). - Color charge would be transmitted via a new (eight-fold) fundamental particle, called the gluon. -

-

- Spectacularly, this model could explain all of the newly discovered composite hadrons, and even predict a few that had not been discovered! - Shortly afterwards, it was confirmed through experiments with deep inelastic scattering that the Proton and Neutron were not fundamental. - They, too, are made up of quarks! -

-
- -
-
-
Resources
- -
- - diff --git a/html/tau.html b/html/tau.html deleted file mode 100644 index 6ddbe2e..0000000 --- a/html/tau.html +++ /dev/null @@ -1,26 +0,0 @@ -

You discovered the τ lepton!

- -
-

The τ lepton

- A plot from the original publication -

- The τ (tau) is an elementary particle that can be thought of as a much heavier cousin of the electron, with a spin of ½. It belongs to the family of leptons, along with the electron, the muon, and the three neutrinos. Despite the origin of the word lepton (meaning fine, small, thin) the τ is very massive at 1776.82 MeV/c2, which is nearly 3500 times the mass of the electron and around twice the mass of the proton. -

-
- -
-
The discovery of the τ
-

- The τ was detected in a series of experiments between 1974 and 1977 by Martin Lewis Perl and his colleagues at the SLAC-LBL group. Their equipment consisted of SLAC’s then-new e+e colliding ring, called SPEAR, and the LBL magnetic detector. They could detect and distinguish between leptons, hadrons and photons. -

-

- Martin Perl shared the 1995 Nobel Prize in Physics with Frederick Reines. The latter was awarded his share of the prize for experimental discovery of the neutrino. -

-
- -
-
Resources
- diff --git a/html/top.html b/html/top.html deleted file mode 100644 index 46aed2e..0000000 --- a/html/top.html +++ /dev/null @@ -1,17 +0,0 @@ -

You discovered the top quark!

-
The top quark
-A proton and an antiproton annhilate to form a top-antitop pair - -

-At 174.2 GeV/c2, the top quark is the heaviest particle we know of. It belongs to the third generation of quarks and has a charge of ⅔ times the electron charge. As a result of its large mass, it decays (mostly into bottom quarks) almost instantly after it is produced. This behemoth does not form bound states with other quarks or antiquarks. -

- -

-It was discovered by the DØ and CDF collaborations at Fermilab in the US. -Nowadays, top quarks and their properties are studied intensively by ATLAS and CMS at CERN. -

- -
Resources
- diff --git a/html/weak.html b/html/weak.html deleted file mode 100644 index d06adff..0000000 --- a/html/weak.html +++ /dev/null @@ -1,19 +0,0 @@ -

You discovered the W and Z bosons!

-
The weak force
-A W− boson produced in the transformation of a neutron into a proton -

-The weak interaction is a nuclear process that is responsible, among other things, for β (beta) decay the transformation of neutrons into protons. The weak force is mediated by two bosons called the W and the Z. The W comes in two types: W+ and W−. The Z is neutral and is sometimes represented as Z0. -

- -
Discovery of the W and Z bosons
- -

-The W and Z bosons are quite massive and so require powerful accelerators in order to be produced and studied. The Super Proton Synchrotron at CERN was the first machine capable of this, and the UA1 collaboration lead by Carlo Rubbia discovered both particles in 1983. Rubbia along with Simon Van der Meer, whose developments on the accelerator allowed such a machine to be built, were jointly awarded the Nobel Prize in Physics in 1984. -

- -
Resources
- diff --git a/index.js b/index.js new file mode 100644 index 0000000..0cf4ef4 --- /dev/null +++ b/index.js @@ -0,0 +1,41 @@ +/** App imports **/ + +// css +require("css/bootstrap.min.css"); +require("font-awesome/css/font-awesome.css"); +// require("font-awesome/scss/font-awesome.scss"); +// require("bower_components/angular-ui-grid/ui-grid.min.css"); +// require("css/ui-grid.css"); +require("css/style.css"); + +// img +require("assets/favicon.png"); +require("assets/mobile/icon.png"); +require("assets/mobile/icon.png"); +require("assets/pc32sw.png"); + +// json +var jquery = require("jquery"); +var jqueryUi = require("jquery-ui"); +var jqueryUiTouchPunch = require("jquery-ui-touch-punch"); +var jqueryCookie = require("js-cookie"); + +var bootstrap = require("bootstrap"); +// var retina = require("retina"); +var FastClick = require("fastclick"); + +var chai = require("chai"); +var lodash = require("lodash"); + +var angular = require("angular"); +var angularDragdrop = require("angular-dragdrop"); +var angularAnimate = require("angular-animate"); + +var ObjectStorage = require("js/storage.js"); +var Helpers = require("js/helpers.js"); +var Analytics = require("js/analytics.js"); +var GameObjects = require("js/gameobjects.js"); +var Rules = require("js/rules.js"); +var UI = require("js/ui.js"); +var Game = require("js/game.js"); +var app = require("js/app.js"); diff --git a/js/analytics.js b/js/analytics.js index e9fe203..5623ca4 100644 --- a/js/analytics.js +++ b/js/analytics.js @@ -1,5 +1,6 @@ /** Custom google analystics events **/ -var analytics = +var Helpers = require("js/helpers"); +var analytics = module.exports = { enabled: true, diff --git a/js/app.js b/js/app.js index cafaec4..ff31734 100644 --- a/js/app.js +++ b/js/app.js @@ -2,46 +2,44 @@ * Define the angular app */ 'use strict'; -var app = (function () { +var ObjectStorage = require("js/storage"); +var Helpers = require("js/helpers"); +var GameObjects = require("js/gameobjects"); +var analytics = require("js/analytics"); +var Game = require("js/game"); +var Rules = require("js/rules.js"); + +var app = (function (Helpers,analytics,Game,Rules) { Helpers.validateSaveVersion(); - var app = angular.module('scienceAlchemy', ['ngDragDrop', 'ui.grid','ngAnimate']); + var app = angular.module('scienceAlchemy', ['ngDragDrop','ngAnimate']); // directives - /** - * Provides an easy way to toggle a checkboxes indeterminate property - * - * @example - */ - // app.directive('uiIndeterminate', [ - // function () { - // - // return { - // compile: function (tElm, tAttrs) { - // if (!tAttrs.type || tAttrs.type.toLowerCase() !== 'checkbox') { - // return angular.noop; - // } - // - // return function ($scope, elm, attrs) { - // $scope.$watch(attrs.uiIndeterminate, function (newVal) { - // elm[0].indeterminate = !!newVal; - // }); - // }; - // } - // }; - // } - // ]); /** - * Make little score animations when score changes require ng-model="score" + * Make little "+2" "-1" score animations when score changes requires ng-model="score" + * Associated css: + * ``` + * .update-value { // set constant height, and the position + position: relative; + right: -2em; + top: -1.42857em; + height: 1.42857em; + } + .update-plus { // if the change is +ve + color: green; + position: relative; + } + .update-minus { + color: red; + position: relative; + } */ function cfsScoreChange($compile) { return { link: function (scope, element, attrs) { scope.$watch(attrs.ngModel, function (newValue, oldValue) { - console.log('value changed, new value is: ' + newValue, oldValue); - // showUpdateValue var num = newValue-oldValue; var formatted = Helpers.formatNumberPostfix(num); @@ -56,6 +54,7 @@ var app = (function () { .html(formatted); } + // TODO it would be better to use an ::after element for this // showUpdate element.append(insert); insert.animate({ @@ -416,4 +415,5 @@ var app = (function () { analytics.init(); analytics.sendScreen(analytics.screens.main); -})(); +})(Helpers,analytics,Game,Rules); +module.exports=app; diff --git a/js/detector/detector.js b/js/detector/detector.js deleted file mode 100644 index 9f548c1..0000000 --- a/js/detector/detector.js +++ /dev/null @@ -1,127 +0,0 @@ -/** Manages the detector animation in the canvas of the detector pane **/ - -var Detector = function(){ - - - return { - elements: new GameObjects.Cards(), - lastCards: new GameObjects.Cards(), - incorrectCards: new GameObjects.Cards(), - - visible: true, - - width: 400, - height: 400, - - ratio: 1, - - lastRender: 0, - - bubblr: undefined, - - init: function(game) - { - // deal first card - this.lastCards.push(_.sample(game.elements)); - }, - - /** When a user clicks the detector **/ - addEvent: function() - { - // this.bubblr.bubble(); // bubble for 500ms, TODO make one bubble - }, - - /** When a worker clicks the detector **/ - addEventExternal: function(numWorkers) - { - // this.bubblr.genBubbles(numWorkers); - }, - - /** Draw current events **/ - draw: function(duration) - { - // this.bubblr.bubble(); - }, - - - onDrop: function(event, ui, game){ - var self=this; - console.debug('onDrop',arguments); - var $draggable = angular.element(ui.draggable), - $droppable = angular.element(event.target); - - // if the dragger came from the elements panels, clone it to here - var newElement; - if ($draggable.hasClass('element-store')){ - var elementStore = game.elements.filter(function(e){return e.key==$draggable.data('element');})[0]; - elementStore.state.amount-=1; - newElement = angular.copy(elementStore); - this.elements.push(newElement); - } - - var observation = game.test - console.log('intersectingElements', intersectingElements.length, observation); - return observation; - }, - - /** Run an experiment depending on reactants and conditions **/ - experiment: function(options,game) { - var inputs = options.inputs || []; - var inputKeys = inputs.map(function(e){return e.key;}); - inputKeys.sort(); // this makes reaction be independant of order - - var result = game.testRules(inputKeys); - if (result) { - this.reaction(inputs,result.reactants,result.results, options.location, game); - } else { - result = { - reactants: [], - catalysts: [], - conditions: [], - results: [], - inputs: inputKeys - }; - } - return result; - }, - - /** Remove reactants and make results with animations **/ - reaction: function(inputs,reactants,results,location,game){ - - // remove reactants from detector - 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]; - var j = _.findIndex(this.elements,{uuid:ingredient.uuid}); - var removed = this.elements.splice(j,1); - } - - // TODO use angular effects to remove in puff of fade - - // add results and discover them - for (var i = 0; i < results.length; i++) { - var resultKey = results[i]; - - // make sure it's discovered - var elementStore = game.elements.get(resultKey); - if (!elementStore.state.discovered){ - // old discoveries are not interesting - game.elements.map(function(e){e.state.interesting=false;}); - // a new discovery is interesting - elementStore.state.interesting=true; - elementStore.state.discovered=true; - } - - // add new element to beaker - var newElem = elementStore.spawn(); - newElem.state=location; - - this.elements.push(newElem); - } - - // effects - // this.bubblr.bubble(); - - }, - }; -}; diff --git a/js/external/canvas2svg.js b/js/external/canvas2svg.js deleted file mode 100644 index d276d1c..0000000 --- a/js/external/canvas2svg.js +++ /dev/null @@ -1,989 +0,0 @@ -/*!! - * Canvas 2 Svg v1.0.6 - * A low level canvas to SVG converter. Uses a mock canvas context to build an SVG document. - * - * Licensed under the MIT license: - * http://www.opensource.org/licenses/mit-license.php - * - * Author: - * Kerry Liu - * - * Copyright (c) 2014 Gliffy Inc. - */ - -;(function() { - "use strict"; - - var STYLES, ctx, CanvasGradient, CanvasPattern, namedEntities; - - //helper function to format a string - function format(str, args) { - var keys = Object.keys(args), i; - for (i=0; i 1) { - options = defaultOptions; - options.width = arguments[0]; - options.height = arguments[1]; - } else if( !o ) { - options = defaultOptions; - } else { - options = o; - } - - if(!(this instanceof ctx)) { - //did someone call this without new? - return new ctx(options); - } - - //setup options - this.width = options.width || defaultOptions.width; - this.height = options.height || defaultOptions.height; - this.enableMirroring = options.enableMirroring !== undefined ? options.enableMirroring : defaultOptions.enableMirroring; - - this.canvas = this; ///point back to this instance! - this.__canvas = document.createElement("canvas"); - this.__ctx = this.__canvas.getContext("2d"); - - this.__setDefaultStyles(); - this.__stack = [this.__getStyleState()]; - this.__groupStack = []; - - //the root svg element - this.__root = document.createElementNS("http://www.w3.org/2000/svg", "svg"); - this.__root.setAttribute("version", 1.1); - this.__root.setAttribute("xmlns", "http://www.w3.org/2000/svg"); - this.__root.setAttributeNS("http://www.w3.org/2000/xmlns/", "xmlns:xlink", "http://www.w3.org/1999/xlink"); - this.__root.setAttribute("width", this.width); - this.__root.setAttribute("height", this.height); - - //make sure we don't generate the same ids in defs - this.__ids = {}; - - //defs tag - this.__defs = document.createElementNS("http://www.w3.org/2000/svg", "defs"); - this.__root.appendChild(this.__defs); - - //also add a group child. the svg element can't use the transform attribute - this.__currentElement = document.createElementNS("http://www.w3.org/2000/svg", "g"); - this.__root.appendChild(this.__currentElement); - - }; - - /** - * Creates the specified svg element - * @private - */ - ctx.prototype.__createElement = function(elementName, properties, resetFill) { - var element = document.createElementNS("http://www.w3.org/2000/svg", elementName), - keys = Object.keys(properties), i, key; - if(resetFill) { - //if fill or stroke is not specified, the svg element should not display. By default SVG's fill is black. - element.setAttribute("fill", "none"); - element.setAttribute("stroke", "none"); - } - for(i=0; i Math.PI ? 0 : 1; - } else { - largeArcFlag = diff > Math.PI ? 1 : 0; - } - - this.moveTo(startX, startY); - this.__addPathCommand(format("A {rx} {ry} {xAxisRotation} {largeArcFlag} {sweepFlag} {endX} {endY}", - {rx:radius, ry:radius, xAxisRotation:0, largeArcFlag:largeArcFlag, sweepFlag:sweepFlag, endX:endX, endY:endY})); - - }; - - /** - * Generates a ClipPath from the clip command. - */ - ctx.prototype.clip = function(){ - var group = this.__closestGroupOrSvg(), - clipPath = document.createElementNS("http://www.w3.org/2000/svg", "clipPath"), - id = randomString(this.__ids), - newGroup = document.createElementNS("http://www.w3.org/2000/svg", "g"); - - group.removeChild(this.__currentElement); - clipPath.setAttribute("id", id); - clipPath.appendChild(this.__currentElement); - - this.__defs.appendChild(clipPath); - - //set the clip path to this group - group.setAttribute("clip-path", format("url(#{id})", {id:id})); - - //clip paths can be scaled and transformed, we need to add another wrapper group to avoid later transformations - // to this path - group.appendChild(newGroup); - - this.__currentElement = newGroup; - - }; - - /** - * Draws a canvas, image or mock context to this canvas. - * Note that all svg dom manipulation uses node.childNodes rather than node.children for IE support. - * http://www.whatwg.org/specs/web-apps/current-work/multipage/the-canvas-element.html#dom-context-2d-drawimage - */ - ctx.prototype.drawImage = function(){ - //convert arguments to a real array - var args = Array.prototype.slice.call(arguments), - image=args[0], - dx, dy, dw, dh, sx=0, sy=0, sw, sh, parent, svg, defs, group, - currentElement, svgImage, canvas, context, id; - - if(args.length === 3) { - dx = args[1]; - dy = args[2]; - sw = image.width; - sh = image.height; - dw = sw; - dh = sh; - } else if(args.length === 5) { - dx = args[1]; - dy = args[2]; - dw = args[3]; - dh = args[4]; - sw = image.width; - sh = image.height; - } else if(args.length === 9) { - sx = args[1]; - sy = args[2]; - sw = args[3]; - sh = args[4]; - dx = args[5]; - dy = args[6]; - dw = args[7]; - dh = args[8]; - } else { - throw new Error("Inavlid number of arguments passed to drawImage: " + arguments.length); - } - - parent = this.__closestGroupOrSvg(); - currentElement = this.__currentElement; - - if(image instanceof ctx) { - //canvas2svg mock canvas context. In the future we may want to clone nodes instead. - //also I'm currently ignoring dw, dh, sw, sh, sx, sy for a mock context. - svg = image.getSvg(); - defs = svg.childNodes[0]; - while(defs.childNodes.length) { - id = defs.childNodes[0].getAttribute("id"); - this.__ids[id] = id; - this.__defs.appendChild(defs.childNodes[0]); - } - group = svg.childNodes[1]; - parent.appendChild(group); - this.__currentElement = group; - this.translate(dx, dy); - this.__currentElement = currentElement; - } else if(image.nodeName === "CANVAS" || image.nodeName === "IMG") { - //canvas or image - svgImage = document.createElementNS("http://www.w3.org/2000/svg", "image"); - svgImage.setAttribute("width", dw); - svgImage.setAttribute("height", dh); - svgImage.setAttribute("preserveAspectRatio", "none"); - - if(sx || sy || sw !== image.width || sh !== image.height) { - //crop the image using a temporary canvas - canvas = document.createElement("canvas"); - canvas.width = dw; - canvas.height = dh; - context = canvas.getContext("2d"); - context.drawImage(image, sx, sy, sw, sh, 0, 0, dw, dh); - image = canvas; - } - - svgImage.setAttributeNS("http://www.w3.org/1999/xlink", "xlink:href", - image.nodeName === "CANVAS" ? image.toDataURL() : image.getAttribute("src")); - parent.appendChild(svgImage); - this.__currentElement = svgImage; - this.translate(dx, dy); - this.__currentElement = currentElement; - } - }; - - /** - * Generates a pattern tag - */ - ctx.prototype.createPattern = function(image, repetition){ - var pattern = document.createElementNS("http://www.w3.org/2000/svg", "pattern"), id = randomString(this.__ids), - img; - pattern.setAttribute("id", id); - pattern.setAttribute("width", image.width); - pattern.setAttribute("height", image.height); - if(image.nodeName === "CANVAS" || image.nodeName === "IMG") { - img = document.createElementNS("http://www.w3.org/2000/svg", "image"); - img.setAttribute("width", image.width); - img.setAttribute("height", image.height); - img.setAttributeNS("http://www.w3.org/1999/xlink", "xlink:href", - image.nodeName === "CANVAS" ? image.toDataURL() : image.getAttribute("src")); - pattern.appendChild(img); - this.__defs.appendChild(pattern); - } else if(image instanceof ctx) { - pattern.appendChild(image.__root.childNodes[1]); - this.__defs.appendChild(pattern); - } - return new CanvasPattern(pattern, this); - }; - - /** - * Not yet implemented - */ - ctx.prototype.drawFocusRing = function(){}; - ctx.prototype.createImageData = function(){}; - ctx.prototype.getImageData = function(){}; - ctx.prototype.putImageData = function(){}; - ctx.prototype.globalCompositeOperation = function(){}; - ctx.prototype.arcTo = function(){}; - ctx.prototype.setTransform = function(){}; - - //add options for alternative namespace - window.C2S = ctx; - -}()); diff --git a/js/external/retina.js b/js/external/retina.js deleted file mode 100644 index 38d5515..0000000 --- a/js/external/retina.js +++ /dev/null @@ -1,196 +0,0 @@ -/*! - * Retina.js v1.3.0 - * - * Copyright 2014 Imulus, LLC - * Released under the MIT license - * - * Retina.js is an open source script that makes it easy to serve - * high-resolution images to devices with retina displays. - */ - -(function() { - var root = (typeof exports === 'undefined' ? window : exports); - var config = { - // An option to choose a suffix for 2x images - retinaImageSuffix : '@2x', - - // Ensure Content-Type is an image before trying to load @2x image - // https://github.com/imulus/retinajs/pull/45) - check_mime_type: true, - - // Resize high-resolution images to original image's pixel dimensions - // https://github.com/imulus/retinajs/issues/8 - force_original_dimensions: true - }; - - function Retina() {} - - root.Retina = Retina; - - Retina.configure = function(options) { - if (options === null) { - options = {}; - } - - for (var prop in options) { - if (options.hasOwnProperty(prop)) { - config[prop] = options[prop]; - } - } - }; - - Retina.init = function(context) { - if (context === null) { - context = root; - } - - var existing_onload = context.onload || function(){}; - - context.onload = function() { - var images = document.getElementsByTagName('img'), retinaImages = [], i, image; - for (i = 0; i < images.length; i += 1) { - image = images[i]; - if (!!!image.getAttributeNode('data-no-retina')) { - image.setAttribute('data-at2x-loaded', true); - retinaImages.push(new RetinaImage(image)); - } - } - existing_onload(); - }; - }; - - Retina.recheck = function() { - var images = document.getElementsByTagName('img'), retinaImages = [], i, image; - for (i = 0; i < images.length; i += 1) { - image = images[i]; - if (!!!image.getAttributeNode('data-no-retina')) { - if (!!!image.getAttributeNode('data-at2x-loaded')) { - image.setAttribute('data-at2x-loaded', true); - retinaImages.push(new RetinaImage(image)); - } - } - } - }; - - Retina.isRetina = function(){ - var mediaQuery = '(-webkit-min-device-pixel-ratio: 1.5), (min--moz-device-pixel-ratio: 1.5), (-o-min-device-pixel-ratio: 3/2), (min-resolution: 1.5dppx)'; - - if (root.devicePixelRatio > 1) { - return true; - } - - if (root.matchMedia && root.matchMedia(mediaQuery).matches) { - return true; - } - - return false; - }; - - - var regexMatch = /\.\w+$/; - function suffixReplace (match) { - return config.retinaImageSuffix + match; - } - - function RetinaImagePath(path, at_2x_path) { - this.path = path || ''; - if (typeof at_2x_path !== 'undefined' && at_2x_path !== null) { - this.at_2x_path = at_2x_path; - this.perform_check = false; - } else { - if (undefined !== document.createElement) { - var locationObject = document.createElement('a'); - locationObject.href = this.path; - locationObject.pathname = locationObject.pathname.replace(regexMatch, suffixReplace); - this.at_2x_path = locationObject.href; - } else { - var parts = this.path.split('?'); - parts[0] = parts[0].replace(regexMatch, suffixReplace); - this.at_2x_path = parts.join('?'); - } - this.perform_check = true; - } - } - - root.RetinaImagePath = RetinaImagePath; - - RetinaImagePath.confirmed_paths = []; - - RetinaImagePath.prototype.is_external = function() { - return !!(this.path.match(/^https?\:/i) && !this.path.match('//' + document.domain) ); - }; - - RetinaImagePath.prototype.check_2x_variant = function(callback) { - var http, that = this; - if (this.is_external()) { - return callback(false); - } else if (!this.perform_check && typeof this.at_2x_path !== 'undefined' && this.at_2x_path !== null) { - return callback(true); - } else if (this.at_2x_path in RetinaImagePath.confirmed_paths) { - return callback(true); - } else { - http = new XMLHttpRequest(); - http.open('HEAD', this.at_2x_path); - http.onreadystatechange = function() { - if (http.readyState !== 4) { - return callback(false); - } - - if (http.status >= 200 && http.status <= 399) { - if (config.check_mime_type) { - var type = http.getResponseHeader('Content-Type'); - if (type === null || !type.match(/^image/i)) { - return callback(false); - } - } - - RetinaImagePath.confirmed_paths.push(that.at_2x_path); - return callback(true); - } else { - return callback(false); - } - }; - http.send(); - } - }; - - - function RetinaImage(el) { - this.el = el; - this.path = new RetinaImagePath(this.el.getAttribute('src'), this.el.getAttribute('data-at2x')); - var that = this; - this.path.check_2x_variant(function(hasVariant) { - if (hasVariant) { - that.swap(); - } - }); - } - - root.RetinaImage = RetinaImage; - - RetinaImage.prototype.swap = function(path) { - if (typeof path === 'undefined') { - path = this.path.at_2x_path; - } - - var that = this; - function load() { - if (! that.el.complete) { - setTimeout(load, 5); - } else { - if (config.force_original_dimensions) { - that.el.setAttribute('width', that.el.width); - that.el.setAttribute('height', that.el.height); - } - - that.el.setAttribute('src', path); - } - } - load(); - }; - - - if (Retina.isRetina()) { - Retina.init(root); - } -})(); diff --git a/js/game.js b/js/game.js index 46113bf..2c78867 100644 --- a/js/game.js +++ b/js/game.js @@ -1,7 +1,11 @@ /** * Game object load/saves game resources and stores game objects */ -var Game = (function (Helpers, GameObjects, ObjectStorage) { +var ObjectStorage = require("js/storage"); +var Helpers = require("js/helpers"); +var GameObjects = require("js/gameobjects"); +var Rules = require("js/rules.js"); +var Game = module.exports =(function (Helpers, GameObjects, ObjectStorage,Rules) { 'use strict'; var Game = function () { @@ -193,4 +197,4 @@ var Game = (function (Helpers, GameObjects, ObjectStorage) { }; return Game; -}(Helpers, GameObjects, ObjectStorage)); +}(Helpers, GameObjects, ObjectStorage,Rules)); diff --git a/js/gameobjects.js b/js/gameobjects.js index 29c7094..be71cfa 100644 --- a/js/gameobjects.js +++ b/js/gameobjects.js @@ -2,7 +2,7 @@ * Game objects such as workers, research, upgrades, and achievements. */ -var GameObjects = (function () { +var GameObjects = module.exports = (function () { 'use strict'; var GLOBAL_VISIBILITY_THRESHOLD = 0.5; diff --git a/js/helpers.js b/js/helpers.js index a903ba4..0cb0c68 100644 --- a/js/helpers.js +++ b/js/helpers.js @@ -1,7 +1,8 @@ /** @module Helpers * Define some useful helpers that are used throughout the game. */ -var Helpers = (function () { +var ObjectStorage = require("js/storage"); +var Helpers = (function (ObjectStorage) { 'use strict'; /** Load a file (usually JSON). */ @@ -100,4 +101,5 @@ var Helpers = (function () { validateSaveVersion: validateSaveVersion, analytics: '' }; -})(); +})(ObjectStorage); +module.exports=Helpers; diff --git a/js/rules.js b/js/rules.js index 3a3a331..98c4da0 100644 --- a/js/rules.js +++ b/js/rules.js @@ -3,7 +3,8 @@ * @param {[type]} function functionName( [description] * @return {[type]} [description] */ -var Rules = (function functionName(_) { +var chai = require("chai"); +var Rules = module.exports = (function functionName(_,chai) { @@ -250,7 +251,7 @@ var Rules = (function functionName(_) { }; /** How many combination of this rule **/ - Rule.prototype.combinations = function (arguments) { + Rule.prototype.combinations = function () { var pos = _.map(this.optionDesc, 'possibleVals'); var c = 0; for (var i = 0; i < pos.length; i++) { @@ -577,4 +578,4 @@ var Rules = (function functionName(_) { }; -})(_); +})(_,chai); diff --git a/js/storage.js b/js/storage.js index 3473098..6c35b35 100644 --- a/js/storage.js +++ b/js/storage.js @@ -1,7 +1,7 @@ /** Allows to save objects to HTML5 local storage. * However, it can only save properties, not functions. */ -var ObjectStorage = (function() { +var ObjectStorage = module.exports = (function() { 'use strict'; try { var _s = localStorage; diff --git a/js/ui.js b/js/ui.js index 475ae0c..1d74f6b 100644 --- a/js/ui.js +++ b/js/ui.js @@ -2,7 +2,9 @@ /** Define UI specific stuff. */ -var UI = (function () { +var FastClick = require("fastclick"); +var Cookies = require("js-cookie"); +var UI = module.exports = (function (FastClick,Cookies) { /** Introduce FastClick for faster clicking on mobile. */ $(function() { @@ -84,7 +86,7 @@ var UI = (function () { } // display cookie warning - if (typeof $.cookie('cookielaw') === 'undefined') { + if (typeof Cookies.get('cookielaw') === 'undefined') { var alert = '