From 6998fb70f38c963c5b4c1bd1c589e870ff0f6c04 Mon Sep 17 00:00:00 2001 From: Tyler Renelle Date: Tue, 18 Jun 2013 18:21:27 -0400 Subject: [PATCH 1/2] export all scripts into top-level index.js, so that coffeeify includes can import these properly. Hopefully this fixes the empty helpers bug. @yangit I'll merge this into master once I'm sure it works --- index.js | 8 ++++++++ script/algos.coffee | 6 +----- script/helpers.coffee | 4 ++-- 3 files changed, 11 insertions(+), 7 deletions(-) create mode 100644 index.js diff --git a/index.js b/index.js new file mode 100644 index 0000000000..0a04c43cfa --- /dev/null +++ b/index.js @@ -0,0 +1,8 @@ +module.exports.items = require('./script/items.coffee'); +module.exports.algos = require('./script/algos.coffee'); +module.exports.helpers = require('./script/helpers.coffee'); + +try { + window; + window.habitrpgShared = exports; +} catch(e) {} \ No newline at end of file diff --git a/script/algos.coffee b/script/algos.coffee index 851eeee1db..d445d82ac9 100644 --- a/script/algos.coffee +++ b/script/algos.coffee @@ -1,12 +1,8 @@ moment = require('moment') _ = require('lodash') -helpers = require('./helpers.coffee') -items = require('./items.coffee') +{helpers, items} = require('../index') {pets, hatchingPotions} = items.items -# Very strange bug where `require(./script/helpers.coffee)` is returning a blank object under certain circumsntances I haven't yet figured out -helpers = require('habitrpg-shared/script/helpers') if _.isEmpty(helpers) - XP = 15 HP = 2 obj = module.exports = {} diff --git a/script/helpers.coffee b/script/helpers.coffee index d33c4b735f..9091b26e4e 100644 --- a/script/helpers.coffee +++ b/script/helpers.coffee @@ -1,7 +1,7 @@ moment = require 'moment' _ = require 'lodash' -algos = require './algos.coffee' -items = require('./items.coffee').items +{algos, items} = require '../index' +{items} = items sod = (timestamp, dayStart=0) -> #sanity-check reset-time (is it 24h time?) From 6bf0305ea423a16be213bb8ad712c27c35299191 Mon Sep 17 00:00:00 2001 From: Tyler Renelle Date: Tue, 18 Jun 2013 21:40:43 -0400 Subject: [PATCH 2/2] fixed the empty helpers issue. it was circular dependencies - algos dep'd helpers, helpers dep'd algos. Since one came first, it didn't have the other - so it was an empty object. maybe this top-level index.js combinging ./script/* files isn't such a good idea, because I think manual requires from within a file will resolve circular dependencies @yangit --- index.js | 2 +- script/helpers.coffee | 11 +++++------ 2 files changed, 6 insertions(+), 7 deletions(-) diff --git a/index.js b/index.js index 0a04c43cfa..da0734d50c 100644 --- a/index.js +++ b/index.js @@ -1,6 +1,6 @@ module.exports.items = require('./script/items.coffee'); -module.exports.algos = require('./script/algos.coffee'); module.exports.helpers = require('./script/helpers.coffee'); +module.exports.algos = require('./script/algos.coffee'); try { window; diff --git a/script/helpers.coffee b/script/helpers.coffee index 9091b26e4e..b94a3fa0d6 100644 --- a/script/helpers.coffee +++ b/script/helpers.coffee @@ -1,7 +1,6 @@ moment = require 'moment' _ = require 'lodash' -{algos, items} = require '../index' -{items} = items +{items} = require '../index' sod = (timestamp, dayStart=0) -> #sanity-check reset-time (is it 24h time?) @@ -314,10 +313,10 @@ module.exports = userStr: (level) -> str = (level-1) / 2 totalStr: (level, weapon=0) -> str = (level-1) / 2 - totalStr = (str + items.weapon[weapon].strength) + totalStr = (str + items.items.weapon[weapon].strength) userDef: (level) -> def = (level-1) / 2 totalDef: (level, armor=0, helm=0, shield=0) -> def = (level-1) / 2 - totalDef = (def + items.armor[armor].defense + items.head[helm].defense + items.shield[shield].defense) - itemText: (type, item=0) -> items[type][parseInt(item)].text - itemStat: (type, item=0) -> if type is 'weapon' then items[type][parseInt(item)].strength else items[type][parseInt(item)].defense \ No newline at end of file + totalDef = (def + items.items.armor[armor].defense + items.items.head[helm].defense + items.items.shield[shield].defense) + itemText: (type, item=0) -> items.items[type][parseInt(item)].text + itemStat: (type, item=0) -> if type is 'weapon' then items.items[type][parseInt(item)].strength else items.items[type][parseInt(item)].defense \ No newline at end of file