Skip to content
Snippets Groups Projects
Commit fac29f7c authored by Travis Savo's avatar Travis Savo
Browse files

Add fresh OSS libs extracted from project

parent 081fabfe
No related branches found
No related tags found
No related merge requests found
Pipeline #
require('app-module-path').addPath(__dirname)
serializer = require('./serialize')
serializer = require('serially')
loader = require("./loader")
watchr = require("watchr")
_ = require('underscore')
Loading
Loading
@@ -97,7 +97,7 @@ global.$driver.load = (filename) ->
return console.log e
console.log 'Loading checkpoint from ' + filename + '...'
try
global.$game = serializer.unserialize(data.toString())
global.$game = serializer.deserialize(data.toString())
console.log 'Checkpoint loaded.'
catch e
console.log e
Loading
Loading
wordsToNumbers =
"1":1
"2":2
"3":3
"4":4
"5":5
"6":6
"7":7
"8":8
"9":9
"10":10
"11":11
"12":12
"13":13
"14":14
"15":15
"16":16
"17":17
"18":18
"19":19
"20":20
"21":21
"22":22
"23":23
"24":24
"25":25
"26":26
"27":27
"28":28
"29":29
"30":30
"31":31
"32":32
"33":33
"34":34
"35":35
"36":36
"37":37
"38":38
"39":39
"40":40
"41":41
"42":42
"43":43
"44":44
"45":45
"46":46
"47":47
"48":48
"49":49
"50":50
"51":51
"52":52
"53":53
"54":54
"55":55
"56":56
"57":57
"58":58
"59":59
"60":60
"61":61
"62":62
"63":63
"64":64
"65":65
"66":66
"67":67
"68":68
"69":69
"70":70
"71":71
"72":72
"73":73
"74":74
"75":75
"76":76
"77":77
"78":78
"79":79
"80":80
"81":81
"82":82
"83":83
"84":84
"85":85
"86":86
"87":87
"88":88
"89":89
"90":90
"91":91
"92":92
"93":93
"94":94
"95":95
"96":96
"97":97
"98":98
"99":99
"100":100
"1st":1
"2rd":2
"3rd":3
"4th":4
"5th":5
"6th":6
"7th":7
"8th":8
"9th":9
"10th":10
"11th":11
"12th":12
"13th":13
"14th":14
"15th":15
"16th":16
"17th":17
"18th":18
"19th":19
"20th":20
"21st":21
"22rd":22
"23rd":23
"24th":24
"25th":25
"26th":26
"27th":27
"28th":28
"29th":29
"30th":30
"31st":31
"32rd":32
"33rd":33
"34th":34
"35th":35
"36th":36
"37th":37
"38th":38
"39th":39
"40th":40
"41st":41
"42rd":42
"43rd":43
"44th":44
"45th":45
"46th":46
"47th":47
"48th":48
"49th":49
"50th":50
"51st":51
"52rd":52
"53rd":53
"54th":54
"55th":55
"56th":56
"57th":57
"58th":58
"59th":59
"60th":60
"61st":61
"62rd":62
"63rd":63
"64th":64
"65th":65
"66th":66
"67th":67
"68th":69
"69th":69
"70th":70
"71st":71
"72rd":72
"73rd":73
"74th":74
"75th":75
"76th":76
"77th":77
"78th":78
"79th":79
"80th":80
"81st":81
"82rd":82
"83rd":83
"84th":84
"85th":85
"86th":86
"87th":87
"88th":88
"89th":89
"90th":90
"91st":91
"92rd":92
"93rd":93
"94th":94
"95th":95
"96th":96
"97th":97
"98th":98
"99th":99
"100th":100
"first":1
"second":2
"third":3
"fourth":4
"fifth":5
"sixth":6
"seventh":7
"eighth":8
"ninth":9
"tenth":10
"eleventh":11
"twelfth":12
"thirteenth":13
"fourteenth":14
"fifteenth":15
"sixteenth":16
"seventeenth":17
"eighteenth":18
"nineteenth":19
"twentieth":20
"twenty-first":21
"twenty-second":22
"twenty-third":23
"twenty-fourth":24
"twenty-fifth":25
"twenty-sixth":26
"twenty-seventh":27
"twenty-eighth":28
"twenty-ninth":29
"thirtieth":30
"thirty-first":31
"thirty-second":32
"thirty-third":33
"thirty-fourth":34
"thirty-fifth":35
"thirty-sixth":36
"thirty-seventh":37
"thirty-eighth":38
"thirty-ninth":39
"fortieth":40
"forty-first":41
"forty-second":42
"forty-third":43
"forty-fourth":44
"forty-fifth":45
"forty-sixth":46
"forty-seventh":47
"forty-eighth":48
"forty-ninth":49
"fiftieth":50
"fifty-first":51
"fifty-second":52
"fifty-third":53
"fifty-fourth":54
"fifty-fifth":55
"fifty-sixth":56
"fifty-seventh":57
"fifty-eighth":58
"fifty-ninth":59
"sixtieth":60
"sixty-first":61
"sixty-second":62
"sixty-third":63
"sixty-fourth":64
"sixty-fifth":65
"sixty-sixth":66
"sixty-seventh":67
"sixty-eighth":69
"sixty-ninth":69
"seventieth":70
"seventy-first":71
"seventy-second":72
"seventy-third":73
"seventy-four":74
"seventy-fifth":75
"seventy-sixth":76
"seventy-seventh":77
"seventy-eighth":78
"seventy-ninth":79
"eightieth":80
"eighty-first":81
"eighty-second":82
"eighty-third":83
"eighty-fourth":84
"eighty-fifth":85
"eighty-sixth":86
"eighty-seven":87
"eighty-eight":88
"eighty-ninth":89
"ninetieth":90
"ninety-first":91
"ninety-second":92
"ninety-third":93
"ninety-fourth":94
"ninety-fifth":95
"ninety-sixth":96
"ninety-seventh":97
"ninety-eighth":98
"ninety-ninth":99
"hundredth":100
"one-hundredth":100
"one":1
"two":2
"three":3
"four":4
"five":5
"six":6
"seven":7
"eight":8
"nine":9
"ten":10
"eleven":11
"twelve":12
"thirteen":13
"fourteen":14
"fifteen":15
"sixteen":16
"seventeen":17
"eighteen":18
"nineteen":19
"twenty":20
"twenty-one":21
"twenty-two":22
"twenty-three":23
"twenty-four":24
"twenty-five":25
"twenty-six":26
"twenty-seven":27
"twenty-eight":28
"twenty-nine":29
"thirty":30
"thirty-one":31
"thirty-two":32
"thirty-three":33
"thirty-four":34
"thirty-five":35
"thirty-six":36
"thirty-seven":37
"thirty-eight":38
"thirty-nine":39
"forty":40
"forty-one":41
"forty-two":42
"forty-three":43
"forty-four":44
"forty-five":45
"forty-six":46
"forty-seven":47
"forty-eight":48
"forty-nine":49
"fifty":50
"fifty-one":51
"fifty-two":52
"fifty-three":53
"fifty-four":54
"fifty-five":55
"fifty-six":56
"fifty-seven":57
"fifty-eight":58
"fifty-nine":59
"sixty":60
"sixty-one":61
"sixty-two":62
"sixty-three":63
"sixty-four":64
"sixty-five":65
"sixty-six":66
"sixty-seven":67
"sixty-eight":69
"sixty-nine":69
"seventy":70
"seventy-one":71
"seventy-two":72
"seventy-three":73
"seventy-four":74
"seventy-five":75
"seventy-six":76
"seventy-seven":77
"seventy-eight":78
"seventy-nine":79
"eighty":80
"eighty-one":81
"eighty-two":82
"eighty-three":83
"eighty-four":84
"eighty-five":85
"eighty-six":86
"eighty-seven":87
"eighty-eight":88
"eighty-nine":89
"ninety":90
"ninety-one":91
"ninety-two":92
"ninety-three":93
"ninety-four":94
"ninety-five":95
"ninety-six":96
"ninety-seven":97
"ninety-eight":98
"ninety-nine":99
"one-hundred":100
exports = (what)->
wordsToNumbers[what.trim().toLowerCase()]
module.exports = exports
\ No newline at end of file
Array.prototype.proportionate = (num, max)->
return this[0] if num <= 0
return this[this.length-1] if num >= max
percent = num / max
where = (this.length - 1) * percent
return this[parseInt(Math.min(this.length-2, Math.max(1,where)))]
\ No newline at end of file
"use strict"
FUNCFLAG = '_$$ND_FUNC$$_'
PROTOFLAG = '_$$ND_PROTO$$_'
PROTOTYPEFLAG = '_$$ND_PROTOTYPE$$_'
CIRCULARFLAG = '_$$ND_CC$$_'
DATEFLAG = '_$$ND_DATE$$_'
INFINITYFLAG = '_$$ND_INFINITY$$_'
NEGINFINITYFLAG = '_$$ND_NEGINFINITY$$_'
NANFLAG = '_$$ND_NAN$$_'
UNDEFINEDFLAG = '_$$ND_UNDEFINED$$_'
NULLFLAG = '_$$ND_NULL$$_'
KEYPATHSEPARATOR = '_$$.$$_'
ISNATIVEFUNC = /^function\s*[^(]*\(.*\)\s*\{\s*\[native code\]\s*\}$/
if (typeof String.prototype.startsWith isnt 'function')
String.prototype.startsWith = (str)->
return this.slice(0, str.length) is str
if (typeof String.prototype.endsWith isnt 'function')
String.prototype.endsWith = (str)->
return this.slice(-str.length) is str
getKeyPath = (obj, path) ->
path = path.split(KEYPATHSEPARATOR)
currentObj = obj
try
path.forEach (p, index) ->
currentObj = currentObj[p] if index
currentObj
catch e
false
serializeCircular = (obj, cache) ->
for subKey of cache
if cache.hasOwnProperty(subKey) and cache[subKey] is obj
return CIRCULARFLAG + subKey
false
serializeFunction = (func, ignoreNativeFunc) ->
funcStr = func.toString()
if ISNATIVEFUNC.test(funcStr)
if ignoreNativeFunc
funcStr = 'function() {throw new Error("Call a native function unserialized")}'
else
throw new Error('Can\'t serialize a object with a native function property. Use serialize(obj, true) to ignore the error.')
funcStr
unserializeFunction = (func, originObj) ->
vm = require("vm")
funcObj = vm.runInThisContext('( ' + func[FUNCFLAG] + ' )')
delete func[FUNCFLAG]
for key of func
funcObj[key] = func[key]
funcObj
serializeWrapped = (obj) ->
if obj instanceof Date then return DATEFLAG + obj.getTime()
if obj is undefined then return UNDEFINEDFLAG
if obj is null then return NULLFLAG
if obj is Infinity then return INFINITYFLAG
if obj is -Infinity then return NEGINFINITYFLAG
if Number.isNaN(obj) then return NANFLAG
obj
unserializeWrapped = (str) ->
if str.startsWith(DATEFLAG)
dateNum = parseInt(str.slice(DATEFLAG.length), 10)
new Date(dateNum)
else if str.startsWith(INFINITYFLAG)
Infinity
else if str.startsWith(NEGINFINITYFLAG)
-Infinity
else if str.startsWith(UNDEFINEDFLAG)
undefined
else if str.startsWith(NULLFLAG)
null
else if str.startsWith(NANFLAG)
NaN
else
str
serializeObject = (obj, ignoreNativeFunc, outputObj, cache, path) ->
obj = serializeWrapped(obj)
output = {}
keys = Object.keys(obj)
if not path.endsWith('prototype') and not path.endsWith('__proto__')
keys.push 'prototype'
keys.push '__proto__'
keys.forEach (key) ->
if obj.hasOwnProperty(key) or key is 'prototype' or key is '__proto__'
destKey = if key is '__proto__' then PROTOFLAG else if key is 'prototype' then PROTOTYPEFLAG else key
if (typeof obj[key] is 'object' or typeof obj[key] is 'function') and obj[key] isnt null
found = serializeCircular(obj[key], cache)
if found
output[destKey] = found
else
output[destKey] = module.exports.serialize(obj[key], ignoreNativeFunc, outputObj[key], cache, path + KEYPATHSEPARATOR + key)
else
output[destKey] = serializeWrapped(obj[key])
output
module.exports.serialize = (obj, ignoreNativeFunc = false, outputObj = {}, cache = {}, path = "$") ->
obj = serializeWrapped(obj)
if typeof obj is 'string' or typeof obj is 'number'
outputObj = obj
else if obj.constructor is Array
outputObj = []
cache[path] = outputObj
obj.forEach (value, index) ->
outputObj.push module.exports.serialize(value, ignoreNativeFunc, outputObj, cache, path + KEYPATHSEPARATOR + index)
else
found = serializeCircular(obj, cache)
if found
outputObj = found
else
cache[path] = obj
outputObj = serializeObject(obj, ignoreNativeFunc, outputObj, cache, path)
outputObj[FUNCFLAG] = serializeFunction(obj, ignoreNativeFunc) if typeof obj is 'function'
if path is '$' then JSON.stringify(outputObj) else outputObj
module.exports.unserialize = (obj, originObj) ->
circularTasks = []
obj = JSON.parse(obj) if typeof obj is 'string'
originObj = originObj or obj
obj = unserializeFunction(obj) if obj and obj[FUNCFLAG]
obj = unserializeWrapped(obj) if(typeof obj is 'string')
for key of obj
return if not obj.hasOwnProperty(key)
destKey = if key is PROTOFLAG then '__proto__' else if key is PROTOTYPEFLAG then 'prototype' else key
if(destKey is 'prototype' and obj[key] is UNDEFINEDFLAG)
delete obj[key]
continue
if typeof obj[key] is 'object' or typeof obj[key] is 'function'
obj[destKey] = module.exports.unserialize(obj[key], originObj)
else if typeof obj[key] is 'string'
if obj[key].indexOf(CIRCULARFLAG) is 0
obj[key] = obj[key].substring(CIRCULARFLAG.length)
circularTasks.push
obj: obj
sourceKey: key
destKey: destKey
else
obj[destKey] = unserializeWrapped(obj[key])
circularTasks.forEach (task) ->
task.obj[task.destKey] = found if found = getKeyPath(originObj, task.obj[task.sourceKey])
delete obj[PROTOTYPEFLAG] + delete obj[PROTOFLAG] if obj
obj
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment