mirror of
https://github.com/sudoxnym/habitica.git
synced 2026-07-13 15:38:59 +00:00
Coffeeify plugin for browserify to compile .coffee into browser.js.
This commit is contained in:
parent
4a3e8fdcfa
commit
ef9ec0cc22
19 changed files with 8149 additions and 525 deletions
2
Makefile
2
Makefile
|
|
@ -1,2 +1,2 @@
|
|||
compile:
|
||||
./node_modules/browserify/bin/cmd.js index.js > index-browser.js
|
||||
./node_modules/browserify/bin/cmd.js -t coffeeify ./script/index.js > browser/browser.js
|
||||
21
README.md
21
README.md
|
|
@ -4,22 +4,17 @@ Shared resources useful for the multiple HabitRPG repositories, that way all the
|
|||
* Algorithms - level up algorithm, scoring functions, etc
|
||||
* Item definitions - weapons, armor, pets
|
||||
|
||||
##Browserify Usage (TODO fix up this documentation to use old browserify setup)
|
||||
The `Makefile` runs Browserify to compile `index-browser.js`, which you include in a `<script/>` tag in your index.html. This way, you get all the JS min/concat'd
|
||||
* `npm install`
|
||||
* `make`
|
||||
|
||||
##Installation
|
||||
`npm install`
|
||||
`make`
|
||||
|
||||
* Node.js
|
||||
* "npm install coffee-script" to be able to require CS
|
||||
* "npm install requirejs" to enable loading of AMD type modules within indicated subfolder
|
||||
* Configure requirejs module as observerd in examples/node.js/server.js
|
||||
* run "node server" from within "examples/node.js" folder (it should output message in CAPS to console.log)
|
||||
* Browser - use require.js with "cs" plugin to include algos.coffee directly into your index.html
|
||||
* See examples/browser folder.
|
||||
* Run plain http-server from within "examples/browser" folder and point your browser to index.html to see how it works. (it should output message in CAPS to console.log)
|
||||
|
||||
* `require ('coffee-script')`
|
||||
* `var shared = require('./index.js')` or `require('./script/algos.coffee')` if you only need one file.
|
||||
* Browser
|
||||
* Use `<script/>` tag to include ./browser/browser.js it will export `window.habitrpgShared` object.
|
||||
|
||||
|
||||
* Note how to invoke scoring function:
|
||||
* algos.score = function (user, task, direction) {}
|
||||
|
||||
|
|
|
|||
8126
browser/browser.js
Normal file
8126
browser/browser.js
Normal file
File diff suppressed because it is too large
Load diff
|
|
@ -1,20 +0,0 @@
|
|||
//Set requireJS settings for coffee script plugin.
|
||||
requirejs.config({
|
||||
baseUrl:'../', //relative to this file
|
||||
paths: { //relative to baseUrl
|
||||
cs: 'requirejs/cs',
|
||||
'coffee-script': 'requirejs/coffee-script'
|
||||
}
|
||||
});
|
||||
|
||||
//Require files we need.
|
||||
//There are may ways to require files. Some of them just dump\run the file as it is within WINDOW scope. Some assign modules to given variables (like node.js does) and a few more.
|
||||
//Main difference is order in which your code gets executed. Read more about concept at http://requirejs.org/ there are a lot of problems solved by require.js.
|
||||
|
||||
|
||||
//Load array of modules (in this case 'app/module') into the variables (in this case module). "cs!" - means this file has to be parsed by cs plugin first.
|
||||
requirejs(['cs!app/module'], function (module) {
|
||||
//foo() is defined within module.coffee. We can use it within this callback.
|
||||
//Note that we are passing lowercase here. But will get UPPERCASE because we use parentModule within module.
|
||||
module.foo('Hello!')
|
||||
});
|
||||
|
|
@ -1,20 +0,0 @@
|
|||
#This is a boilerplate to make this file both node.js and AMD (require.js) module compatible.
|
||||
({ define: (
|
||||
if typeof define == "function"
|
||||
define
|
||||
else
|
||||
(F)->
|
||||
F(require, exports, module)
|
||||
)}).define (require, exports, module)->
|
||||
#Write your code here as usual
|
||||
|
||||
#I.e. require parent module
|
||||
#NOTE: I did not figure out how to require coffee-script here. As this has to be both Node.js and require.js compatible syntax. And they disagree on how to do that. Anyway we can stick with .js parent modules for a while.
|
||||
parent = require('cs!./parentModule');
|
||||
|
||||
module.exports =
|
||||
{
|
||||
foo: (message)->
|
||||
#use parent module
|
||||
console.log parent.parentFoo message
|
||||
}
|
||||
|
|
@ -1,13 +0,0 @@
|
|||
({ define: (
|
||||
if typeof define == "function"
|
||||
define
|
||||
else
|
||||
(F)->
|
||||
F(require, exports, module)
|
||||
)}).define (require, exports, module)->
|
||||
#Write your code here as usual
|
||||
module.exports =
|
||||
{
|
||||
parentFoo: (message)->
|
||||
message.toUpperCase()
|
||||
}
|
||||
|
|
@ -1,12 +0,0 @@
|
|||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<title>Require.js example</title>
|
||||
|
||||
<!--Require.js will start by loading app/main.js-->
|
||||
<script data-main="app/main" src="requirejs/require.js"></script>
|
||||
</head>
|
||||
<body>
|
||||
|
||||
</body>
|
||||
</html>
|
||||
File diff suppressed because one or more lines are too long
|
|
@ -1,168 +0,0 @@
|
|||
/**
|
||||
* Created with JetBrains PhpStorm.
|
||||
* User: y
|
||||
* Date: 5/10/13
|
||||
* Time: 6:48 PM
|
||||
* To change this template use File | Settings | File Templates.
|
||||
*/
|
||||
/**
|
||||
* @license cs 0.4.3 Copyright (c) 2010-2011, The Dojo Foundation All Rights Reserved.
|
||||
* Available via the MIT or new BSD license.
|
||||
* see: http://github.com/jrburke/require-cs for details
|
||||
*/
|
||||
|
||||
/*jslint */
|
||||
/*global define, window, XMLHttpRequest, importScripts, Packages, java,
|
||||
ActiveXObject, process, require */
|
||||
|
||||
define(['coffee-script'], function (CoffeeScript) {
|
||||
'use strict';
|
||||
var fs, getXhr,
|
||||
progIds = ['Msxml2.XMLHTTP', 'Microsoft.XMLHTTP', 'Msxml2.XMLHTTP.4.0'],
|
||||
fetchText = function () {
|
||||
throw new Error('Environment unsupported.');
|
||||
},
|
||||
buildMap = {};
|
||||
|
||||
if (typeof process !== "undefined" &&
|
||||
process.versions &&
|
||||
!!process.versions.node) {
|
||||
//Using special require.nodeRequire, something added by r.js.
|
||||
fs = require.nodeRequire('fs');
|
||||
fetchText = function (path, callback) {
|
||||
callback(fs.readFileSync(path, 'utf8'));
|
||||
};
|
||||
} else if ((typeof window !== "undefined" && window.navigator && window.document) || typeof importScripts !== "undefined") {
|
||||
// Browser action
|
||||
getXhr = function () {
|
||||
//Would love to dump the ActiveX crap in here. Need IE 6 to die first.
|
||||
var xhr, i, progId;
|
||||
if (typeof XMLHttpRequest !== "undefined") {
|
||||
return new XMLHttpRequest();
|
||||
} else {
|
||||
for (i = 0; i < 3; i += 1) {
|
||||
progId = progIds[i];
|
||||
try {
|
||||
xhr = new ActiveXObject(progId);
|
||||
} catch (e) {}
|
||||
|
||||
if (xhr) {
|
||||
progIds = [progId]; // so faster next time
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (!xhr) {
|
||||
throw new Error("getXhr(): XMLHttpRequest not available");
|
||||
}
|
||||
|
||||
return xhr;
|
||||
};
|
||||
|
||||
fetchText = function (url, callback) {
|
||||
var xhr = getXhr();
|
||||
xhr.open('GET', url, true);
|
||||
xhr.onreadystatechange = function (evt) {
|
||||
//Do not explicitly handle errors, those should be
|
||||
//visible via console output in the browser.
|
||||
if (xhr.readyState === 4) {
|
||||
callback(xhr.responseText);
|
||||
}
|
||||
};
|
||||
xhr.send(null);
|
||||
};
|
||||
// end browser.js adapters
|
||||
} else if (typeof Packages !== 'undefined') {
|
||||
//Why Java, why is this so awkward?
|
||||
fetchText = function (path, callback) {
|
||||
var stringBuffer, line,
|
||||
encoding = "utf-8",
|
||||
file = new java.io.File(path),
|
||||
lineSeparator = java.lang.System.getProperty("line.separator"),
|
||||
input = new java.io.BufferedReader(new java.io.InputStreamReader(new java.io.FileInputStream(file), encoding)),
|
||||
content = '';
|
||||
try {
|
||||
stringBuffer = new java.lang.StringBuffer();
|
||||
line = input.readLine();
|
||||
|
||||
// Byte Order Mark (BOM) - The Unicode Standard, version 3.0, page 324
|
||||
// http://www.unicode.org/faq/utf_bom.html
|
||||
|
||||
// Note that when we use utf-8, the BOM should appear as "EF BB BF", but it doesn't due to this bug in the JDK:
|
||||
// http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=4508058
|
||||
if (line && line.length() && line.charAt(0) === 0xfeff) {
|
||||
// Eat the BOM, since we've already found the encoding on this file,
|
||||
// and we plan to concatenating this buffer with others; the BOM should
|
||||
// only appear at the top of a file.
|
||||
line = line.substring(1);
|
||||
}
|
||||
|
||||
stringBuffer.append(line);
|
||||
|
||||
while ((line = input.readLine()) !== null) {
|
||||
stringBuffer.append(lineSeparator);
|
||||
stringBuffer.append(line);
|
||||
}
|
||||
//Make sure we return a JavaScript string and not a Java string.
|
||||
content = String(stringBuffer.toString()); //String
|
||||
} finally {
|
||||
input.close();
|
||||
}
|
||||
callback(content);
|
||||
};
|
||||
}
|
||||
|
||||
return {
|
||||
fetchText: fetchText,
|
||||
|
||||
get: function () {
|
||||
return CoffeeScript;
|
||||
},
|
||||
|
||||
write: function (pluginName, name, write) {
|
||||
if (buildMap.hasOwnProperty(name)) {
|
||||
var text = buildMap[name];
|
||||
write.asModule(pluginName + "!" + name, text);
|
||||
}
|
||||
},
|
||||
|
||||
version: '0.4.3',
|
||||
|
||||
load: function (name, parentRequire, load, config) {
|
||||
var path = parentRequire.toUrl(name + '.coffee');
|
||||
fetchText(path, function (text) {
|
||||
|
||||
//Do CoffeeScript transform.
|
||||
try {
|
||||
text = CoffeeScript.compile(text, config.CoffeeScript);
|
||||
} catch (err) {
|
||||
err.message = "In " + path + ", " + err.message;
|
||||
throw err;
|
||||
}
|
||||
|
||||
//Hold on to the transformed text if a build.
|
||||
if (config.isBuild) {
|
||||
buildMap[name] = text;
|
||||
}
|
||||
|
||||
//IE with conditional comments on cannot handle the
|
||||
//sourceURL trick, so skip it if enabled.
|
||||
/*@if (@_jscript) @else @*/
|
||||
if (!config.isBuild) {
|
||||
text += "\r\n//@ sourceURL=" + path;
|
||||
}
|
||||
/*@end@*/
|
||||
|
||||
load.fromText(name, text);
|
||||
|
||||
//Give result to load. Need to wait until the module
|
||||
//is fully parse, which will happen after this
|
||||
//execution.
|
||||
parentRequire([name], function (value) {
|
||||
load(value);
|
||||
});
|
||||
});
|
||||
}
|
||||
};
|
||||
});
|
||||
|
|
@ -1,35 +0,0 @@
|
|||
/*
|
||||
RequireJS 2.1.5 Copyright (c) 2010-2012, The Dojo Foundation All Rights Reserved.
|
||||
Available via the MIT or new BSD license.
|
||||
see: http://github.com/jrburke/requirejs for details
|
||||
*/
|
||||
var requirejs,require,define;
|
||||
(function(aa){function I(b){return"[object Function]"===L.call(b)}function J(b){return"[object Array]"===L.call(b)}function y(b,c){if(b){var d;for(d=0;d<b.length&&(!b[d]||!c(b[d],d,b));d+=1);}}function M(b,c){if(b){var d;for(d=b.length-1;-1<d&&(!b[d]||!c(b[d],d,b));d-=1);}}function s(b,c){return ga.call(b,c)}function m(b,c){return s(b,c)&&b[c]}function G(b,c){for(var d in b)if(s(b,d)&&c(b[d],d))break}function R(b,c,d,m){c&&G(c,function(c,j){if(d||!s(b,j))m&&"string"!==typeof c?(b[j]||(b[j]={}),R(b[j],
|
||||
c,d,m)):b[j]=c});return b}function u(b,c){return function(){return c.apply(b,arguments)}}function ba(b){if(!b)return b;var c=aa;y(b.split("."),function(b){c=c[b]});return c}function B(b,c,d,m){c=Error(c+"\nhttp://requirejs.org/docs/errors.html#"+b);c.requireType=b;c.requireModules=m;d&&(c.originalError=d);return c}function ha(b){function c(a,f,b){var e,n,c,g,d,S,i,h=f&&f.split("/");e=h;var j=k.map,l=j&&j["*"];if(a&&"."===a.charAt(0))if(f){e=m(k.pkgs,f)?h=[f]:h.slice(0,h.length-1);f=a=e.concat(a.split("/"));
|
||||
for(e=0;f[e];e+=1)if(n=f[e],"."===n)f.splice(e,1),e-=1;else if(".."===n)if(1===e&&(".."===f[2]||".."===f[0]))break;else 0<e&&(f.splice(e-1,2),e-=2);e=m(k.pkgs,f=a[0]);a=a.join("/");e&&a===f+"/"+e.main&&(a=f)}else 0===a.indexOf("./")&&(a=a.substring(2));if(b&&j&&(h||l)){f=a.split("/");for(e=f.length;0<e;e-=1){c=f.slice(0,e).join("/");if(h)for(n=h.length;0<n;n-=1)if(b=m(j,h.slice(0,n).join("/")))if(b=m(b,c)){g=b;d=e;break}if(g)break;!S&&(l&&m(l,c))&&(S=m(l,c),i=e)}!g&&S&&(g=S,d=i);g&&(f.splice(0,d,
|
||||
g),a=f.join("/"))}return a}function d(a){A&&y(document.getElementsByTagName("script"),function(f){if(f.getAttribute("data-requiremodule")===a&&f.getAttribute("data-requirecontext")===i.contextName)return f.parentNode.removeChild(f),!0})}function z(a){var f=m(k.paths,a);if(f&&J(f)&&1<f.length)return d(a),f.shift(),i.require.undef(a),i.require([a]),!0}function h(a){var f,b=a?a.indexOf("!"):-1;-1<b&&(f=a.substring(0,b),a=a.substring(b+1,a.length));return[f,a]}function j(a,f,b,e){var n,C,g=null,d=f?f.name:
|
||||
null,j=a,l=!0,k="";a||(l=!1,a="_@r"+(M+=1));a=h(a);g=a[0];a=a[1];g&&(g=c(g,d,e),C=m(q,g));a&&(g?k=C&&C.normalize?C.normalize(a,function(a){return c(a,d,e)}):c(a,d,e):(k=c(a,d,e),a=h(k),g=a[0],k=a[1],b=!0,n=i.nameToUrl(k)));b=g&&!C&&!b?"_unnormalized"+(Q+=1):"";return{prefix:g,name:k,parentMap:f,unnormalized:!!b,url:n,originalName:j,isDefine:l,id:(g?g+"!"+k:k)+b}}function r(a){var f=a.id,b=m(p,f);b||(b=p[f]=new i.Module(a));return b}function t(a,f,b){var e=a.id,n=m(p,e);if(s(q,e)&&(!n||n.defineEmitComplete))"defined"===
|
||||
f&&b(q[e]);else r(a).on(f,b)}function v(a,f){var b=a.requireModules,e=!1;if(f)f(a);else if(y(b,function(f){if(f=m(p,f))f.error=a,f.events.error&&(e=!0,f.emit("error",a))}),!e)l.onError(a)}function w(){T.length&&(ia.apply(H,[H.length-1,0].concat(T)),T=[])}function x(a){delete p[a];delete V[a]}function F(a,f,b){var e=a.map.id;a.error?a.emit("error",a.error):(f[e]=!0,y(a.depMaps,function(e,c){var g=e.id,d=m(p,g);d&&(!a.depMatched[c]&&!b[g])&&(m(f,g)?(a.defineDep(c,q[g]),a.check()):F(d,f,b))}),b[e]=!0)}
|
||||
function D(){var a,f,b,e,n=(b=1E3*k.waitSeconds)&&i.startTime+b<(new Date).getTime(),c=[],g=[],h=!1,j=!0;if(!W){W=!0;G(V,function(b){a=b.map;f=a.id;if(b.enabled&&(a.isDefine||g.push(b),!b.error))if(!b.inited&&n)z(f)?h=e=!0:(c.push(f),d(f));else if(!b.inited&&(b.fetched&&a.isDefine)&&(h=!0,!a.prefix))return j=!1});if(n&&c.length)return b=B("timeout","Load timeout for modules: "+c,null,c),b.contextName=i.contextName,v(b);j&&y(g,function(a){F(a,{},{})});if((!n||e)&&h)if((A||da)&&!X)X=setTimeout(function(){X=
|
||||
0;D()},50);W=!1}}function E(a){s(q,a[0])||r(j(a[0],null,!0)).init(a[1],a[2])}function K(a){var a=a.currentTarget||a.srcElement,b=i.onScriptLoad;a.detachEvent&&!Y?a.detachEvent("onreadystatechange",b):a.removeEventListener("load",b,!1);b=i.onScriptError;(!a.detachEvent||Y)&&a.removeEventListener("error",b,!1);return{node:a,id:a&&a.getAttribute("data-requiremodule")}}function L(){var a;for(w();H.length;){a=H.shift();if(null===a[0])return v(B("mismatch","Mismatched anonymous define() module: "+a[a.length-
|
||||
1]));E(a)}}var W,Z,i,N,X,k={waitSeconds:7,baseUrl:"./",paths:{},pkgs:{},shim:{},config:{}},p={},V={},$={},H=[],q={},U={},M=1,Q=1;N={require:function(a){return a.require?a.require:a.require=i.makeRequire(a.map)},exports:function(a){a.usingExports=!0;if(a.map.isDefine)return a.exports?a.exports:a.exports=q[a.map.id]={}},module:function(a){return a.module?a.module:a.module={id:a.map.id,uri:a.map.url,config:function(){return k.config&&m(k.config,a.map.id)||{}},exports:q[a.map.id]}}};Z=function(a){this.events=
|
||||
m($,a.id)||{};this.map=a;this.shim=m(k.shim,a.id);this.depExports=[];this.depMaps=[];this.depMatched=[];this.pluginMaps={};this.depCount=0};Z.prototype={init:function(a,b,c,e){e=e||{};if(!this.inited){this.factory=b;if(c)this.on("error",c);else this.events.error&&(c=u(this,function(a){this.emit("error",a)}));this.depMaps=a&&a.slice(0);this.errback=c;this.inited=!0;this.ignore=e.ignore;e.enabled||this.enabled?this.enable():this.check()}},defineDep:function(a,b){this.depMatched[a]||(this.depMatched[a]=
|
||||
!0,this.depCount-=1,this.depExports[a]=b)},fetch:function(){if(!this.fetched){this.fetched=!0;i.startTime=(new Date).getTime();var a=this.map;if(this.shim)i.makeRequire(this.map,{enableBuildCallback:!0})(this.shim.deps||[],u(this,function(){return a.prefix?this.callPlugin():this.load()}));else return a.prefix?this.callPlugin():this.load()}},load:function(){var a=this.map.url;U[a]||(U[a]=!0,i.load(this.map.id,a))},check:function(){if(this.enabled&&!this.enabling){var a,b,c=this.map.id;b=this.depExports;
|
||||
var e=this.exports,n=this.factory;if(this.inited)if(this.error)this.emit("error",this.error);else{if(!this.defining){this.defining=!0;if(1>this.depCount&&!this.defined){if(I(n)){if(this.events.error)try{e=i.execCb(c,n,b,e)}catch(d){a=d}else e=i.execCb(c,n,b,e);this.map.isDefine&&((b=this.module)&&void 0!==b.exports&&b.exports!==this.exports?e=b.exports:void 0===e&&this.usingExports&&(e=this.exports));if(a)return a.requireMap=this.map,a.requireModules=[this.map.id],a.requireType="define",v(this.error=
|
||||
a)}else e=n;this.exports=e;if(this.map.isDefine&&!this.ignore&&(q[c]=e,l.onResourceLoad))l.onResourceLoad(i,this.map,this.depMaps);x(c);this.defined=!0}this.defining=!1;this.defined&&!this.defineEmitted&&(this.defineEmitted=!0,this.emit("defined",this.exports),this.defineEmitComplete=!0)}}else this.fetch()}},callPlugin:function(){var a=this.map,b=a.id,d=j(a.prefix);this.depMaps.push(d);t(d,"defined",u(this,function(e){var n,d;d=this.map.name;var g=this.map.parentMap?this.map.parentMap.name:null,h=
|
||||
i.makeRequire(a.parentMap,{enableBuildCallback:!0});if(this.map.unnormalized){if(e.normalize&&(d=e.normalize(d,function(a){return c(a,g,!0)})||""),e=j(a.prefix+"!"+d,this.map.parentMap),t(e,"defined",u(this,function(a){this.init([],function(){return a},null,{enabled:!0,ignore:!0})})),d=m(p,e.id)){this.depMaps.push(e);if(this.events.error)d.on("error",u(this,function(a){this.emit("error",a)}));d.enable()}}else n=u(this,function(a){this.init([],function(){return a},null,{enabled:!0})}),n.error=u(this,
|
||||
function(a){this.inited=!0;this.error=a;a.requireModules=[b];G(p,function(a){0===a.map.id.indexOf(b+"_unnormalized")&&x(a.map.id)});v(a)}),n.fromText=u(this,function(e,c){var d=a.name,g=j(d),C=O;c&&(e=c);C&&(O=!1);r(g);s(k.config,b)&&(k.config[d]=k.config[b]);try{l.exec(e)}catch(ca){return v(B("fromtexteval","fromText eval for "+b+" failed: "+ca,ca,[b]))}C&&(O=!0);this.depMaps.push(g);i.completeLoad(d);h([d],n)}),e.load(a.name,h,n,k)}));i.enable(d,this);this.pluginMaps[d.id]=d},enable:function(){V[this.map.id]=
|
||||
this;this.enabling=this.enabled=!0;y(this.depMaps,u(this,function(a,b){var c,e;if("string"===typeof a){a=j(a,this.map.isDefine?this.map:this.map.parentMap,!1,!this.skipMap);this.depMaps[b]=a;if(c=m(N,a.id)){this.depExports[b]=c(this);return}this.depCount+=1;t(a,"defined",u(this,function(a){this.defineDep(b,a);this.check()}));this.errback&&t(a,"error",this.errback)}c=a.id;e=p[c];!s(N,c)&&(e&&!e.enabled)&&i.enable(a,this)}));G(this.pluginMaps,u(this,function(a){var b=m(p,a.id);b&&!b.enabled&&i.enable(a,
|
||||
this)}));this.enabling=!1;this.check()},on:function(a,b){var c=this.events[a];c||(c=this.events[a]=[]);c.push(b)},emit:function(a,b){y(this.events[a],function(a){a(b)});"error"===a&&delete this.events[a]}};i={config:k,contextName:b,registry:p,defined:q,urlFetched:U,defQueue:H,Module:Z,makeModuleMap:j,nextTick:l.nextTick,onError:v,configure:function(a){a.baseUrl&&"/"!==a.baseUrl.charAt(a.baseUrl.length-1)&&(a.baseUrl+="/");var b=k.pkgs,c=k.shim,e={paths:!0,config:!0,map:!0};G(a,function(a,b){e[b]?
|
||||
"map"===b?(k.map||(k.map={}),R(k[b],a,!0,!0)):R(k[b],a,!0):k[b]=a});a.shim&&(G(a.shim,function(a,b){J(a)&&(a={deps:a});if((a.exports||a.init)&&!a.exportsFn)a.exportsFn=i.makeShimExports(a);c[b]=a}),k.shim=c);a.packages&&(y(a.packages,function(a){a="string"===typeof a?{name:a}:a;b[a.name]={name:a.name,location:a.location||a.name,main:(a.main||"main").replace(ja,"").replace(ea,"")}}),k.pkgs=b);G(p,function(a,b){!a.inited&&!a.map.unnormalized&&(a.map=j(b))});if(a.deps||a.callback)i.require(a.deps||[],
|
||||
a.callback)},makeShimExports:function(a){return function(){var b;a.init&&(b=a.init.apply(aa,arguments));return b||a.exports&&ba(a.exports)}},makeRequire:function(a,f){function d(e,c,h){var g,k;f.enableBuildCallback&&(c&&I(c))&&(c.__requireJsBuild=!0);if("string"===typeof e){if(I(c))return v(B("requireargs","Invalid require call"),h);if(a&&s(N,e))return N[e](p[a.id]);if(l.get)return l.get(i,e,a,d);g=j(e,a,!1,!0);g=g.id;return!s(q,g)?v(B("notloaded",'Module name "'+g+'" has not been loaded yet for context: '+
|
||||
b+(a?"":". Use require([])"))):q[g]}L();i.nextTick(function(){L();k=r(j(null,a));k.skipMap=f.skipMap;k.init(e,c,h,{enabled:!0});D()});return d}f=f||{};R(d,{isBrowser:A,toUrl:function(b){var d,f=b.lastIndexOf("."),g=b.split("/")[0];if(-1!==f&&(!("."===g||".."===g)||1<f))d=b.substring(f,b.length),b=b.substring(0,f);return i.nameToUrl(c(b,a&&a.id,!0),d,!0)},defined:function(b){return s(q,j(b,a,!1,!0).id)},specified:function(b){b=j(b,a,!1,!0).id;return s(q,b)||s(p,b)}});a||(d.undef=function(b){w();var c=
|
||||
j(b,a,!0),d=m(p,b);delete q[b];delete U[c.url];delete $[b];d&&(d.events.defined&&($[b]=d.events),x(b))});return d},enable:function(a){m(p,a.id)&&r(a).enable()},completeLoad:function(a){var b,c,e=m(k.shim,a)||{},d=e.exports;for(w();H.length;){c=H.shift();if(null===c[0]){c[0]=a;if(b)break;b=!0}else c[0]===a&&(b=!0);E(c)}c=m(p,a);if(!b&&!s(q,a)&&c&&!c.inited){if(k.enforceDefine&&(!d||!ba(d)))return z(a)?void 0:v(B("nodefine","No define call for "+a,null,[a]));E([a,e.deps||[],e.exportsFn])}D()},nameToUrl:function(a,
|
||||
b,c){var e,d,h,g,j,i;if(l.jsExtRegExp.test(a))g=a+(b||"");else{e=k.paths;d=k.pkgs;g=a.split("/");for(j=g.length;0<j;j-=1)if(i=g.slice(0,j).join("/"),h=m(d,i),i=m(e,i)){J(i)&&(i=i[0]);g.splice(0,j,i);break}else if(h){a=a===h.name?h.location+"/"+h.main:h.location;g.splice(0,j,a);break}g=g.join("/");g+=b||(/\?/.test(g)||c?"":".js");g=("/"===g.charAt(0)||g.match(/^[\w\+\.\-]+:/)?"":k.baseUrl)+g}return k.urlArgs?g+((-1===g.indexOf("?")?"?":"&")+k.urlArgs):g},load:function(a,b){l.load(i,a,b)},execCb:function(a,
|
||||
b,c,d){return b.apply(d,c)},onScriptLoad:function(a){if("load"===a.type||ka.test((a.currentTarget||a.srcElement).readyState))P=null,a=K(a),i.completeLoad(a.id)},onScriptError:function(a){var b=K(a);if(!z(b.id))return v(B("scripterror","Script error",a,[b.id]))}};i.require=i.makeRequire();return i}var l,w,x,D,t,E,P,K,Q,fa,la=/(\/\*([\s\S]*?)\*\/|([^:]|^)\/\/(.*)$)/mg,ma=/[^.]\s*require\s*\(\s*["']([^'"\s]+)["']\s*\)/g,ea=/\.js$/,ja=/^\.\//;w=Object.prototype;var L=w.toString,ga=w.hasOwnProperty,ia=
|
||||
Array.prototype.splice,A=!!("undefined"!==typeof window&&navigator&&document),da=!A&&"undefined"!==typeof importScripts,ka=A&&"PLAYSTATION 3"===navigator.platform?/^complete$/:/^(complete|loaded)$/,Y="undefined"!==typeof opera&&"[object Opera]"===opera.toString(),F={},r={},T=[],O=!1;if("undefined"===typeof define){if("undefined"!==typeof requirejs){if(I(requirejs))return;r=requirejs;requirejs=void 0}"undefined"!==typeof require&&!I(require)&&(r=require,require=void 0);l=requirejs=function(b,c,d,z){var h,
|
||||
j="_";!J(b)&&"string"!==typeof b&&(h=b,J(c)?(b=c,c=d,d=z):b=[]);h&&h.context&&(j=h.context);(z=m(F,j))||(z=F[j]=l.s.newContext(j));h&&z.configure(h);return z.require(b,c,d)};l.config=function(b){return l(b)};l.nextTick="undefined"!==typeof setTimeout?function(b){setTimeout(b,4)}:function(b){b()};require||(require=l);l.version="2.1.5";l.jsExtRegExp=/^\/|:|\?|\.js$/;l.isBrowser=A;w=l.s={contexts:F,newContext:ha};l({});y(["toUrl","undef","defined","specified"],function(b){l[b]=function(){var c=F._;return c.require[b].apply(c,
|
||||
arguments)}});if(A&&(x=w.head=document.getElementsByTagName("head")[0],D=document.getElementsByTagName("base")[0]))x=w.head=D.parentNode;l.onError=function(b){throw b;};l.load=function(b,c,d){var l=b&&b.config||{},h;if(A)return h=l.xhtml?document.createElementNS("http://www.w3.org/1999/xhtml","html:script"):document.createElement("script"),h.type=l.scriptType||"text/javascript",h.charset="utf-8",h.async=!0,h.setAttribute("data-requirecontext",b.contextName),h.setAttribute("data-requiremodule",c),
|
||||
h.attachEvent&&!(h.attachEvent.toString&&0>h.attachEvent.toString().indexOf("[native code"))&&!Y?(O=!0,h.attachEvent("onreadystatechange",b.onScriptLoad)):(h.addEventListener("load",b.onScriptLoad,!1),h.addEventListener("error",b.onScriptError,!1)),h.src=d,K=h,D?x.insertBefore(h,D):x.appendChild(h),K=null,h;if(da)try{importScripts(d),b.completeLoad(c)}catch(j){b.onError(B("importscripts","importScripts failed for "+c+" at "+d,j,[c]))}};A&&M(document.getElementsByTagName("script"),function(b){x||(x=
|
||||
b.parentNode);if(t=b.getAttribute("data-main"))return r.baseUrl||(E=t.split("/"),Q=E.pop(),fa=E.length?E.join("/")+"/":"./",r.baseUrl=fa,t=Q),t=t.replace(ea,""),r.deps=r.deps?r.deps.concat(t):[t],!0});define=function(b,c,d){var l,h;"string"!==typeof b&&(d=c,c=b,b=null);J(c)||(d=c,c=[]);!c.length&&I(d)&&d.length&&(d.toString().replace(la,"").replace(ma,function(b,d){c.push(d)}),c=(1===d.length?["require"]:["require","exports","module"]).concat(c));if(O){if(!(l=K))P&&"interactive"===P.readyState||M(document.getElementsByTagName("script"),
|
||||
function(b){if("interactive"===b.readyState)return P=b}),l=P;l&&(b||(b=l.getAttribute("data-requiremodule")),h=F[l.getAttribute("data-requirecontext")])}(h?h.defQueue:T).push([b,c,d])};define.amd={jQuery:!0};l.exec=function(b){return eval(b)};l(r)}})(this);
|
||||
|
|
@ -1,20 +0,0 @@
|
|||
#This is a boilerplate to make this file both node.js and AMD (require.js) module compatible.
|
||||
({ define: (
|
||||
if typeof define == "function"
|
||||
define
|
||||
else
|
||||
(F)->
|
||||
F(require, exports, module)
|
||||
)}).define (require, exports, module)->
|
||||
#Write your code here as usual
|
||||
|
||||
#I.e. require parent module
|
||||
#NOTE: I did not figure out how to require coffee-script here. As this has to be both Node.js and require.js compatible syntax. And they disagree on how to do that. Anyway we can stick with .js parent modules for a while.
|
||||
parent = require('cs!./parentModule');
|
||||
|
||||
module.exports =
|
||||
{
|
||||
foo: (message)->
|
||||
#use parent module
|
||||
console.log parent.parentFoo message
|
||||
}
|
||||
|
|
@ -1,13 +0,0 @@
|
|||
({ define: (
|
||||
if typeof define == "function"
|
||||
define
|
||||
else
|
||||
(F)->
|
||||
F(require, exports, module)
|
||||
)}).define (require, exports, module)->
|
||||
#Write your code here as usual
|
||||
module.exports =
|
||||
{
|
||||
parentFoo: (message)->
|
||||
message.toUpperCase()
|
||||
}
|
||||
|
|
@ -1,168 +0,0 @@
|
|||
/**
|
||||
* Created with JetBrains PhpStorm.
|
||||
* User: y
|
||||
* Date: 5/10/13
|
||||
* Time: 6:48 PM
|
||||
* To change this template use File | Settings | File Templates.
|
||||
*/
|
||||
/**
|
||||
* @license cs 0.4.3 Copyright (c) 2010-2011, The Dojo Foundation All Rights Reserved.
|
||||
* Available via the MIT or new BSD license.
|
||||
* see: http://github.com/jrburke/require-cs for details
|
||||
*/
|
||||
|
||||
/*jslint */
|
||||
/*global define, window, XMLHttpRequest, importScripts, Packages, java,
|
||||
ActiveXObject, process, require */
|
||||
|
||||
define(['coffee-script'], function (CoffeeScript) {
|
||||
'use strict';
|
||||
var fs, getXhr,
|
||||
progIds = ['Msxml2.XMLHTTP', 'Microsoft.XMLHTTP', 'Msxml2.XMLHTTP.4.0'],
|
||||
fetchText = function () {
|
||||
throw new Error('Environment unsupported.');
|
||||
},
|
||||
buildMap = {};
|
||||
|
||||
if (typeof process !== "undefined" &&
|
||||
process.versions &&
|
||||
!!process.versions.node) {
|
||||
//Using special require.nodeRequire, something added by r.js.
|
||||
fs = require.nodeRequire('fs');
|
||||
fetchText = function (path, callback) {
|
||||
callback(fs.readFileSync(path, 'utf8'));
|
||||
};
|
||||
} else if ((typeof window !== "undefined" && window.navigator && window.document) || typeof importScripts !== "undefined") {
|
||||
// Browser action
|
||||
getXhr = function () {
|
||||
//Would love to dump the ActiveX crap in here. Need IE 6 to die first.
|
||||
var xhr, i, progId;
|
||||
if (typeof XMLHttpRequest !== "undefined") {
|
||||
return new XMLHttpRequest();
|
||||
} else {
|
||||
for (i = 0; i < 3; i += 1) {
|
||||
progId = progIds[i];
|
||||
try {
|
||||
xhr = new ActiveXObject(progId);
|
||||
} catch (e) {}
|
||||
|
||||
if (xhr) {
|
||||
progIds = [progId]; // so faster next time
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (!xhr) {
|
||||
throw new Error("getXhr(): XMLHttpRequest not available");
|
||||
}
|
||||
|
||||
return xhr;
|
||||
};
|
||||
|
||||
fetchText = function (url, callback) {
|
||||
var xhr = getXhr();
|
||||
xhr.open('GET', url, true);
|
||||
xhr.onreadystatechange = function (evt) {
|
||||
//Do not explicitly handle errors, those should be
|
||||
//visible via console output in the browser.
|
||||
if (xhr.readyState === 4) {
|
||||
callback(xhr.responseText);
|
||||
}
|
||||
};
|
||||
xhr.send(null);
|
||||
};
|
||||
// end browser.js adapters
|
||||
} else if (typeof Packages !== 'undefined') {
|
||||
//Why Java, why is this so awkward?
|
||||
fetchText = function (path, callback) {
|
||||
var stringBuffer, line,
|
||||
encoding = "utf-8",
|
||||
file = new java.io.File(path),
|
||||
lineSeparator = java.lang.System.getProperty("line.separator"),
|
||||
input = new java.io.BufferedReader(new java.io.InputStreamReader(new java.io.FileInputStream(file), encoding)),
|
||||
content = '';
|
||||
try {
|
||||
stringBuffer = new java.lang.StringBuffer();
|
||||
line = input.readLine();
|
||||
|
||||
// Byte Order Mark (BOM) - The Unicode Standard, version 3.0, page 324
|
||||
// http://www.unicode.org/faq/utf_bom.html
|
||||
|
||||
// Note that when we use utf-8, the BOM should appear as "EF BB BF", but it doesn't due to this bug in the JDK:
|
||||
// http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=4508058
|
||||
if (line && line.length() && line.charAt(0) === 0xfeff) {
|
||||
// Eat the BOM, since we've already found the encoding on this file,
|
||||
// and we plan to concatenating this buffer with others; the BOM should
|
||||
// only appear at the top of a file.
|
||||
line = line.substring(1);
|
||||
}
|
||||
|
||||
stringBuffer.append(line);
|
||||
|
||||
while ((line = input.readLine()) !== null) {
|
||||
stringBuffer.append(lineSeparator);
|
||||
stringBuffer.append(line);
|
||||
}
|
||||
//Make sure we return a JavaScript string and not a Java string.
|
||||
content = String(stringBuffer.toString()); //String
|
||||
} finally {
|
||||
input.close();
|
||||
}
|
||||
callback(content);
|
||||
};
|
||||
}
|
||||
|
||||
return {
|
||||
fetchText: fetchText,
|
||||
|
||||
get: function () {
|
||||
return CoffeeScript;
|
||||
},
|
||||
|
||||
write: function (pluginName, name, write) {
|
||||
if (buildMap.hasOwnProperty(name)) {
|
||||
var text = buildMap[name];
|
||||
write.asModule(pluginName + "!" + name, text);
|
||||
}
|
||||
},
|
||||
|
||||
version: '0.4.3',
|
||||
|
||||
load: function (name, parentRequire, load, config) {
|
||||
var path = parentRequire.toUrl(name + '.coffee');
|
||||
fetchText(path, function (text) {
|
||||
|
||||
//Do CoffeeScript transform.
|
||||
try {
|
||||
text = CoffeeScript.compile(text, config.CoffeeScript);
|
||||
} catch (err) {
|
||||
err.message = "In " + path + ", " + err.message;
|
||||
throw err;
|
||||
}
|
||||
|
||||
//Hold on to the transformed text if a build.
|
||||
if (config.isBuild) {
|
||||
buildMap[name] = text;
|
||||
}
|
||||
|
||||
//IE with conditional comments on cannot handle the
|
||||
//sourceURL trick, so skip it if enabled.
|
||||
/*@if (@_jscript) @else @*/
|
||||
if (!config.isBuild) {
|
||||
text += "\r\n//@ sourceURL=" + path;
|
||||
}
|
||||
/*@end@*/
|
||||
|
||||
load.fromText(name, text);
|
||||
|
||||
//Give result to load. Need to wait until the module
|
||||
//is fully parse, which will happen after this
|
||||
//execution.
|
||||
parentRequire([name], function (value) {
|
||||
load(value);
|
||||
});
|
||||
});
|
||||
}
|
||||
};
|
||||
});
|
||||
|
|
@ -1,18 +0,0 @@
|
|||
var requirejs = require('requirejs');
|
||||
|
||||
requirejs.config({
|
||||
//Pass the top-level main.js/index.js require
|
||||
//function to requirejs so that node modules
|
||||
//are loaded relative to the top-level JS file.
|
||||
nodeRequire: require,
|
||||
baseUrl:'', //relative to this file
|
||||
paths: { //relative to baseUrl
|
||||
cs: 'requirejs/cs', //plugin to use coffee-script to parse file first.
|
||||
'coffee-script': 'coffee-script'
|
||||
}
|
||||
});
|
||||
|
||||
requirejs(['cs!./app/module'],
|
||||
function (module) {
|
||||
module.foo('Hello!');
|
||||
});
|
||||
8
index.js
8
index.js
|
|
@ -1,8 +0,0 @@
|
|||
exports.algos = require('./script/algos')
|
||||
exports.items = require('./script/items')
|
||||
exports.helpers = require('./script/helpers')
|
||||
|
||||
try {
|
||||
window;
|
||||
window.habitrpgShared = exports;
|
||||
} catch(e) {}
|
||||
|
|
@ -3,6 +3,8 @@
|
|||
"version": "0.0.0",
|
||||
"dependencies": {
|
||||
"browserify": "~2.14.1",
|
||||
"coffeeify": "0.4.0",
|
||||
"coffee-script": "1.6.2",
|
||||
"lodash": "~1.2.1",
|
||||
"moment": "~2.0.0",
|
||||
"relative-date": "~1.1.1"
|
||||
|
|
|
|||
|
|
@ -1,8 +1,8 @@
|
|||
moment = require('moment')
|
||||
_ = require('lodash')
|
||||
|
||||
helpers = require('./helpers')
|
||||
items = require('./items')
|
||||
helpers = require('./helpers.coffee')
|
||||
items = require('./items.coffee')
|
||||
{pets, hatchingPotions} = items.items
|
||||
|
||||
XP = 15
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
moment = require 'moment'
|
||||
_ = require 'lodash'
|
||||
algos = require './algos'
|
||||
items = require('./items').items
|
||||
algos = require './algos.coffee'
|
||||
items = require('./items.coffee').items
|
||||
|
||||
sod = (timestamp, dayStart=0) ->
|
||||
#sanity-check reset-time (is it 24h time?)
|
||||
|
|
|
|||
8
script/index.js
Normal file
8
script/index.js
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
exports.algos = require('./algos.coffee');
|
||||
exports.items = require('./items.coffee');
|
||||
exports.helpers = require('./helpers.coffee');
|
||||
|
||||
try {
|
||||
window;
|
||||
window.habitrpgShared = exports;
|
||||
} catch(e) {}
|
||||
Loading…
Reference in a new issue