From 521bc31fa5b271025ed9798b54133f8393d69424 Mon Sep 17 00:00:00 2001 From: Dominik Maier Date: Tue, 13 May 2014 04:32:29 +0200 Subject: [PATCH] + Created function for generating a reproducable seed out of user code - as using JSON.stringify is not garanteed to be the same on every browser for objects. --- app/lib/world/world.coffee | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/app/lib/world/world.coffee b/app/lib/world/world.coffee index 23f7222fc..8dd139364 100644 --- a/app/lib/world/world.coffee +++ b/app/lib/world/world.coffee @@ -31,15 +31,13 @@ module.exports = class World @systemMap = {} @scriptNotes = [] # We want a seed thats not always 0 yet reproducable. - console.log "Seed: ", @getSeed() @rand = new Rand @getSeed() @frames = [new WorldFrame(@, 0)] getSeed: -> - return 0 unless @userCodeMap #TODO: When does this happen? #Packs all methods in all thangs in one big array, then sorts and joins them. Then returns a hash value of the result. @hashString((methods for thangID, methods of @userCodeMap).reduce(((ret, methods) -> - (method for methodID, method of methods).reduce(((ret, method) -> ret.push(method)), ret) + ret.push method for methodID, method of methods ), []).sort().join()) getFrame: (frameIndex) -> @@ -497,4 +495,4 @@ module.exports = class World #djb2 algorithm hashString: (str) -> - (str.charCodeAt i for i in [0...str]).reduce(((hash, char) -> ((hash << 5) + hash) + char), 5381) # hash * 33 + c + (str.charCodeAt i for i in [0...str.length]).reduce(((hash, char) -> ((hash << 5) + hash) + char), 5381) # hash * 33 + c