mirror of
https://github.com/codeninjasllc/codecombat.git
synced 2025-02-17 00:40:56 -05:00
Update Vagrant setup scripts
install nodejs using nvm fix issues with Windows/Linux new line characters update auto-reload-brunch drop bless-brunch resolve related issue #3588
This commit is contained in:
parent
0770a61534
commit
672c89e0bc
7 changed files with 305 additions and 296 deletions
65
Vagrantfile
vendored
65
Vagrantfile
vendored
|
@ -1,32 +1,33 @@
|
|||
# -*- mode: ruby -*-
|
||||
# vi: set ft=ruby :
|
||||
|
||||
# Original content copyright (c) 2014 dpen2000 licensed under the MIT license
|
||||
|
||||
VAGRANTFILE_API_VERSION = "2"
|
||||
Vagrant.require_version ">= 1.5.0"
|
||||
|
||||
Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
|
||||
|
||||
# Ubuntu 14.04 compatible with both VirtualBox and VMWare Fusion
|
||||
# see https://github.com/phusion/open-vagrant-boxes#readme
|
||||
config.vm.box = "phusion/ubuntu-14.04-amd64"
|
||||
|
||||
config.vm.hostname = "coco-dev"
|
||||
|
||||
config.vm.network "forwarded_port", guest: 3000, host: 3000
|
||||
config.vm.network "forwarded_port", guest: 9485, host: 9485
|
||||
|
||||
config.vm.provision "shell", path: "scripts/vagrant/provision.sh", privileged: false
|
||||
|
||||
config.vm.provider "virtualbox" do |v|
|
||||
v.memory = 2048
|
||||
v.cpus = 2
|
||||
end
|
||||
|
||||
config.vm.provider "vmware_fusion" do |v|
|
||||
v.vmx["memsize"] = "2048"
|
||||
v.vmx["numvcpus"] = 2
|
||||
end
|
||||
|
||||
end
|
||||
# -*- mode: ruby -*-
|
||||
# vi: set ft=ruby :
|
||||
|
||||
# Original content copyright (c) 2014 dpen2000 licensed under the MIT license
|
||||
|
||||
VAGRANTFILE_API_VERSION = "2"
|
||||
Vagrant.require_version ">= 1.5.0"
|
||||
|
||||
Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
|
||||
|
||||
# Ubuntu 14.04 compatible with both VirtualBox and VMWare Fusion
|
||||
# see https://github.com/phusion/open-vagrant-boxes#readme
|
||||
config.vm.box = "phusion/ubuntu-14.04-amd64"
|
||||
|
||||
config.vm.hostname = "coco-dev"
|
||||
|
||||
config.vm.network "forwarded_port", guest: 3000, host: 13000
|
||||
config.vm.network "forwarded_port", guest: 9485, host: 19485
|
||||
|
||||
config.vm.provision "shell", path: "scripts/vagrant/provision.sh", privileged: false
|
||||
|
||||
config.vm.provider "virtualbox" do |v|
|
||||
v.memory = 2048
|
||||
v.cpus = 2
|
||||
#v.gui = true
|
||||
end
|
||||
|
||||
config.vm.provider "vmware_fusion" do |v|
|
||||
v.vmx["memsize"] = "2048"
|
||||
v.vmx["numvcpus"] = 2
|
||||
end
|
||||
|
||||
end
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
module.exports = nativeDescription: "English", englishDescription: "English", translation:
|
||||
module.exports = nativeDescription: "English", englishDescription: "English", translation:
|
||||
home:
|
||||
slogan: "Learn to Code by Playing a Game"
|
||||
no_ie: "CodeCombat does not run in Internet Explorer 8 or older. Sorry!" # Warning that only shows up in IE8 and older
|
||||
|
|
22
nodemon.json
22
nodemon.json
|
@ -1,13 +1,13 @@
|
|||
{
|
||||
"verbose": "true",
|
||||
"ignore": [],
|
||||
"events": {
|
||||
},
|
||||
"watch": [
|
||||
"server_config.js",
|
||||
"server_setup.coffee",
|
||||
"app/schemas",
|
||||
"./server"
|
||||
],
|
||||
"ext":"js coffee"
|
||||
"verbose": "true",
|
||||
"ignore": [],
|
||||
"events": {
|
||||
},
|
||||
"watch": [
|
||||
"server_config.js",
|
||||
"server_setup.coffee",
|
||||
"app/schemas",
|
||||
"./server"
|
||||
],
|
||||
"ext":"js coffee"
|
||||
}
|
||||
|
|
|
@ -36,7 +36,7 @@
|
|||
"postinstall": "bower install && brunch build --env fast",
|
||||
"brunch": "brunch",
|
||||
"bower": "bower",
|
||||
"dev": "brunch watch --server",
|
||||
"dev": "brunch watch --server --env fast",
|
||||
"nodemon": "nodemon",
|
||||
"jasmine-node": "jasmine-node",
|
||||
"multicore": "coffee multicore.coffee",
|
||||
|
@ -93,7 +93,7 @@
|
|||
"devDependencies": {
|
||||
"after-brunch": "0.0.5",
|
||||
"assetsmanager-brunch": "^1.8.1",
|
||||
"auto-reload-brunch": "> 1.0 < 1.8",
|
||||
"auto-reload-brunch": "^1.8.1",
|
||||
"bower": "~1.6.4",
|
||||
"brunch": "^1.8.5",
|
||||
"coffee-script-brunch": "^1.8.3",
|
||||
|
|
|
@ -2,8 +2,7 @@
|
|||
# Original content copyright (c) 2014 dpen2000 licensed under the MIT license
|
||||
|
||||
# some defaults
|
||||
DISTRO="trusty"
|
||||
NODE_VERSION="0.10" # 0.10 | 0.12 | 4.x | 5.x
|
||||
NODE_VERSION="5.x" # 0.10 | 0.12 | 4.x | 5.x | 6.x
|
||||
|
||||
# inform apt that there's no user to answer interactive questions
|
||||
export DEBIAN_FRONTEND=noninteractive
|
||||
|
@ -17,42 +16,51 @@ sudo mv /tmp/limits.conf /etc/security/limits.conf
|
|||
sudo chown root:root /etc/security/limits.conf
|
||||
|
||||
# install prerequisites
|
||||
curl -s https://deb.nodesource.com/gpgkey/nodesource.gpg.key | sudo apt-key add -
|
||||
echo "deb https://deb.nodesource.com/node_${NODE_VERSION} ${DISTRO} main
|
||||
deb-src https://deb.nodesource.com/node_${NODE_VERSION} ${DISTRO} main" | sudo tee /etc/apt/sources.list.d/nodesource.list
|
||||
curl -sL https://deb.nodesource.com/setup_${NODE_VERSION} | sudo -E bash -
|
||||
sudo apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv 7F0CEB10
|
||||
echo 'deb http://downloads-distro.mongodb.org/repo/ubuntu-upstart dist 10gen' | sudo tee /etc/apt/sources.list.d/mongodb.list
|
||||
|
||||
echo "updating apt sources..."
|
||||
sudo apt-get -qq update
|
||||
sudo apt-get update
|
||||
|
||||
echo "installing prerequisites..."
|
||||
sudo apt-get -qqy install --no-install-recommends git g++ make curl wget
|
||||
sudo apt-get -y install --no-install-recommends build-essential git g++ make curl wget python2.7 dos2unix
|
||||
|
||||
# install node.js
|
||||
echo "installing node.js..."
|
||||
sudo apt-get -qqy install nodejs
|
||||
sudo apt-get -y install nodejs
|
||||
npm config set python `which python2.7`
|
||||
|
||||
echo "upgrading npm..."
|
||||
sudo npm install -g npm@latest # upgrade npm
|
||||
sudo npm install -g geoip-lite
|
||||
sudo npm install -g bower
|
||||
sudo npm install -g brunch
|
||||
sudo npm install -g geoip-lite
|
||||
sudo npm install -g nodemon
|
||||
|
||||
# bind /vagrant/node_modules so that it does not leak through to the host file system
|
||||
# which triggers symlink and path size issues on Windows hosts
|
||||
mkdir -p /vagrant/node_modules
|
||||
sudo mkdir -p /node_modules
|
||||
sudo chown vagrant:vagrant /node_modules
|
||||
sudo chown -R vagrant:vagrant /node_modules
|
||||
sudo mount --bind /node_modules /vagrant/node_modules
|
||||
cd /vagrant
|
||||
|
||||
# prepare
|
||||
find /vagrant/app -type f -exec dos2unix {} \;
|
||||
find /vagrant/vendor -type f -exec dos2unix {} \;
|
||||
sudo chown -R vagrant:vagrant /home/vagrant
|
||||
|
||||
# install npm modules
|
||||
echo "installing modules..."
|
||||
cd /vagrant
|
||||
npm install
|
||||
bower install
|
||||
|
||||
# install mongo
|
||||
echo "installing mongodb..."
|
||||
sudo apt-get -qqy install --no-install-recommends mongodb-org
|
||||
sudo apt-get -y install --no-install-recommends mongodb-org
|
||||
|
||||
# start mongodb
|
||||
sudo service mongod start
|
||||
|
||||
# populate mongo
|
||||
echo "populating mongodb..."
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
Problem = require 'views/play/level/tome/Problem'
|
||||
Problem = require 'views/play/level/tome/Problem'
|
||||
|
||||
describe 'Problem', ->
|
||||
# boilerplate problem params
|
||||
|
|
472
vendor/scripts/spade.js
vendored
472
vendor/scripts/spade.js
vendored
|
@ -1,236 +1,236 @@
|
|||
var Spade = function Spade() {
|
||||
this.stack = [];
|
||||
}
|
||||
Spade.prototype = {
|
||||
track: function(_elem) {
|
||||
this.target = _elem;
|
||||
|
||||
var spade = this;
|
||||
|
||||
var el = document.createElement("div");
|
||||
|
||||
keyHook = null;
|
||||
if(_elem.textInput && _elem.textInput.getElement) {
|
||||
keyHook = _elem.textInput.getElement();
|
||||
} else {
|
||||
keyHook = _elem;
|
||||
}
|
||||
keyHook.addEventListener("keydown", function(_event) {spade.createEvent(spade.target)});
|
||||
//Maybe this is needed depending on Firefox/other browsers? Duplicate non-diff events get compiled down.
|
||||
keyHook.addEventListener("keyup", function(_event) {spade.createEvent(spade.target)});
|
||||
_elem.addEventListener("mouseup", function(_event) {spade.createEvent(spade.target)});
|
||||
},
|
||||
createEvent: function(_target) {
|
||||
if(_target.getValue) {
|
||||
this.stack.push({
|
||||
"startPos":_target.selection.getCursor(),
|
||||
"endPos":_target.selection.getSelectionAnchor(),
|
||||
"content":_target.getValue(),
|
||||
"timestamp":(new Date()).getTime()
|
||||
});
|
||||
} else {
|
||||
this.stack.push({
|
||||
"startPos":_target.selectionStart,
|
||||
"endPos":_target.selectionEnd,
|
||||
"content":_target.value,
|
||||
"timestamp":(new Date()).getTime()
|
||||
});
|
||||
}
|
||||
},
|
||||
compile: function() {
|
||||
var compiledStack = [];
|
||||
if(this.stack.length > 0) {
|
||||
var startTime = this.stack[0].timestamp;
|
||||
var sum = 0;
|
||||
var sum2 = 0;
|
||||
for(var i = 0; i < this.stack.length; i++) {
|
||||
var c = this.stack[i];
|
||||
var adjustedTimestamp = c.timestamp - startTime;
|
||||
|
||||
var tString = ""; //The changed string.
|
||||
var fIndex = null; //The first index of changes.
|
||||
var eIndex = null; //The last index of changes.
|
||||
var dCount = 0; //Amount of character changes.
|
||||
if(i >= 1) {
|
||||
var p = this.stack[i - 1];
|
||||
var isOkay = false;
|
||||
for(var key in p) {
|
||||
if(key != "timestamp") {
|
||||
if(typeof p[key] === "string") {
|
||||
if(p[key] !== c[key]) {
|
||||
isOkay = true;
|
||||
}
|
||||
} else {
|
||||
for(var key2 in p[key]) {
|
||||
if(c[key][key2] !== undefined) {
|
||||
if(p[key][key2] !== c[key][key2]) {
|
||||
isOkay = true;
|
||||
}
|
||||
} else {
|
||||
console.warn("Warning: c[key][key2] doesn't exist, but p[key][key2] does.");
|
||||
isOkay = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if(!isOkay) {
|
||||
sum2++;
|
||||
continue;
|
||||
}
|
||||
sum++;
|
||||
if(p.content != c.content) {
|
||||
//Check from the start to the end, which characters are different.
|
||||
for(var j = 0; j < Math.max(p.content.length, c.content.length); j++) {
|
||||
if(p.content.charAt(j) === c.content.charAt(j)) {
|
||||
if(fIndex != null) {
|
||||
tString += c.content.charAt(j);
|
||||
dCount++;
|
||||
}
|
||||
} else {
|
||||
tString += c.content.charAt(j);
|
||||
if(fIndex === null) {
|
||||
fIndex = j;
|
||||
}
|
||||
dCount++;
|
||||
}
|
||||
}
|
||||
//Check from the end to the start, which characters are different.
|
||||
for(var j = 0; j < Math.min(p.content.length, c.content.length) - fIndex; j++) {
|
||||
if(p.content.charAt(p.content.length - 1 - j) !== c.content.charAt(c.content.length - 1 - j)) {
|
||||
if(eIndex == null) {
|
||||
eIndex = j;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
//This accounts for the fact when changing from "aa" to "aaa" (for example).
|
||||
if(eIndex === null) {
|
||||
eIndex = Math.min(p.content.length, c.content.length) - fIndex;
|
||||
}
|
||||
tString = tString.substring(0, tString.length - eIndex);
|
||||
}
|
||||
} else {
|
||||
tString = c.content;
|
||||
fIndex = 0;
|
||||
eIndex = tString.length;
|
||||
}
|
||||
compiledStack.push({
|
||||
"timestamp":adjustedTimestamp,
|
||||
"difContent":tString,
|
||||
"difFIndex":fIndex,
|
||||
"difEIndex":eIndex,
|
||||
"selFIndex":c.startPos,
|
||||
"selEIndex":c.endPos
|
||||
});
|
||||
}
|
||||
} else {
|
||||
//Just return the empty array.
|
||||
}
|
||||
return compiledStack;
|
||||
},
|
||||
play: function(_stack, _elem) {
|
||||
if(_stack.length === 0) {
|
||||
console.warn("SPADE: No events to play.")
|
||||
return
|
||||
}
|
||||
if(_elem.setValue) {
|
||||
_elem.setValue(_stack[0].difContent);
|
||||
} else {
|
||||
_elem.value = _stack[0].difContent
|
||||
}
|
||||
_stack = _stack.slice();
|
||||
_stack.shift();
|
||||
var curTime, dTime;
|
||||
var elapsedTime = 0;
|
||||
var prevTime = (new Date()).getTime();
|
||||
var playbackInterval = setInterval(function() {
|
||||
curTime = (new Date()).getTime();
|
||||
dTime = curTime - prevTime;
|
||||
dTime *= 1; //Multiply for faster/slower playback speeds.
|
||||
elapsedTime += dTime;
|
||||
var tArray = _stack.filter(function(_event) {
|
||||
return ((_event.timestamp) >= (elapsedTime - dTime)) && ((_event.timestamp) < (elapsedTime));
|
||||
});
|
||||
for(var i = 0; i < tArray.length; i++) {
|
||||
var tEvent = tArray[i];
|
||||
var oVal = null;
|
||||
if(_elem.getValue) {
|
||||
oVal = _elem.getValue();
|
||||
} else {
|
||||
oVal = _elem.value;
|
||||
}
|
||||
if(tEvent.difFIndex !== null && tEvent.difEIndex !== null) {
|
||||
if(_elem.setValue) {
|
||||
_elem.setValue(oVal.substring(0, tEvent.difFIndex) + tEvent.difContent + oVal.substring(oVal.length - tEvent.difEIndex, oVal.length));
|
||||
} else {
|
||||
_elem.value = oVal.substring(0, tEvent.difFIndex) + tEvent.difContent + oVal.substring(oVal.length - tEvent.difEIndex, oVal.length)
|
||||
}
|
||||
}
|
||||
if(_elem.selection && _elem.selection.moveCursorToPosition) {
|
||||
//Maybe this will work someday
|
||||
_elem.selection.moveCursorToPosition(tEvent.selFIndex);
|
||||
_elem.selection.setSelectionAnchor(tEvent.selEIndex.row, tEvent.selEIndex.column);
|
||||
_elem.selection.selectTo(tEvent.selFIndex.row, tEvent.selFIndex.column);
|
||||
} else {
|
||||
//Likewise
|
||||
_elem.focus();
|
||||
_elem.setSelectionRange(tEvent.selFIndex, tEvent.selEIndex);
|
||||
}
|
||||
}
|
||||
if(_stack[_stack.length - 1] === undefined || elapsedTime > _stack[_stack.length - 1].timestamp) {
|
||||
clearInterval(playbackInterval);
|
||||
}
|
||||
prevTime = curTime;
|
||||
}, 10);
|
||||
},
|
||||
debugPlay: function(_stack) {
|
||||
var area = document.createElement('textarea');
|
||||
area.zIndex = 9999;
|
||||
area.style.width = "512px";
|
||||
area.style.height = "512px";
|
||||
area.style.position = "absolute";
|
||||
area.style.left = "100px";
|
||||
area.style.top = "100px";
|
||||
document.body.appendChild(area);
|
||||
this.play(_stack, area);
|
||||
},
|
||||
condense: function(_stack) {
|
||||
var compressedArray = [];
|
||||
for(var i = 0; i < _stack.length; i++) {
|
||||
var u = _stack[i];
|
||||
compressedArray.push([
|
||||
u.timestamp,
|
||||
u.difContent,
|
||||
u.difFIndex,
|
||||
u.difEIndex,
|
||||
u.selFIndex.row,
|
||||
u.selFIndex.column,
|
||||
u.selEIndex.row,
|
||||
u.selEIndex.column
|
||||
]);
|
||||
}
|
||||
return compressedArray;
|
||||
},
|
||||
expand: function(_array) {
|
||||
var uncompressedArray = [];
|
||||
for(var i = 0 ; i < _array.length; i++) {
|
||||
var c = _array[i];
|
||||
uncompressedArray.push({
|
||||
"timestamp":c[0],
|
||||
"difContent":c[1],
|
||||
"difFIndex":c[2],
|
||||
"difEIndex":c[3],
|
||||
"selFIndex":{
|
||||
"row":c[4],
|
||||
"column":c[5]
|
||||
},
|
||||
"selEIndex":{
|
||||
"row":c[6],
|
||||
"column":c[7]
|
||||
},
|
||||
});
|
||||
}
|
||||
return uncompressedArray;
|
||||
}
|
||||
}
|
||||
var Spade = function Spade() {
|
||||
this.stack = [];
|
||||
}
|
||||
Spade.prototype = {
|
||||
track: function(_elem) {
|
||||
this.target = _elem;
|
||||
|
||||
var spade = this;
|
||||
|
||||
var el = document.createElement("div");
|
||||
|
||||
keyHook = null;
|
||||
if(_elem.textInput && _elem.textInput.getElement) {
|
||||
keyHook = _elem.textInput.getElement();
|
||||
} else {
|
||||
keyHook = _elem;
|
||||
}
|
||||
keyHook.addEventListener("keydown", function(_event) {spade.createEvent(spade.target)});
|
||||
//Maybe this is needed depending on Firefox/other browsers? Duplicate non-diff events get compiled down.
|
||||
keyHook.addEventListener("keyup", function(_event) {spade.createEvent(spade.target)});
|
||||
_elem.addEventListener("mouseup", function(_event) {spade.createEvent(spade.target)});
|
||||
},
|
||||
createEvent: function(_target) {
|
||||
if(_target.getValue) {
|
||||
this.stack.push({
|
||||
"startPos":_target.selection.getCursor(),
|
||||
"endPos":_target.selection.getSelectionAnchor(),
|
||||
"content":_target.getValue(),
|
||||
"timestamp":(new Date()).getTime()
|
||||
});
|
||||
} else {
|
||||
this.stack.push({
|
||||
"startPos":_target.selectionStart,
|
||||
"endPos":_target.selectionEnd,
|
||||
"content":_target.value,
|
||||
"timestamp":(new Date()).getTime()
|
||||
});
|
||||
}
|
||||
},
|
||||
compile: function() {
|
||||
var compiledStack = [];
|
||||
if(this.stack.length > 0) {
|
||||
var startTime = this.stack[0].timestamp;
|
||||
var sum = 0;
|
||||
var sum2 = 0;
|
||||
for(var i = 0; i < this.stack.length; i++) {
|
||||
var c = this.stack[i];
|
||||
var adjustedTimestamp = c.timestamp - startTime;
|
||||
|
||||
var tString = ""; //The changed string.
|
||||
var fIndex = null; //The first index of changes.
|
||||
var eIndex = null; //The last index of changes.
|
||||
var dCount = 0; //Amount of character changes.
|
||||
if(i >= 1) {
|
||||
var p = this.stack[i - 1];
|
||||
var isOkay = false;
|
||||
for(var key in p) {
|
||||
if(key != "timestamp") {
|
||||
if(typeof p[key] === "string") {
|
||||
if(p[key] !== c[key]) {
|
||||
isOkay = true;
|
||||
}
|
||||
} else {
|
||||
for(var key2 in p[key]) {
|
||||
if(c[key][key2] !== undefined) {
|
||||
if(p[key][key2] !== c[key][key2]) {
|
||||
isOkay = true;
|
||||
}
|
||||
} else {
|
||||
console.warn("Warning: c[key][key2] doesn't exist, but p[key][key2] does.");
|
||||
isOkay = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if(!isOkay) {
|
||||
sum2++;
|
||||
continue;
|
||||
}
|
||||
sum++;
|
||||
if(p.content != c.content) {
|
||||
//Check from the start to the end, which characters are different.
|
||||
for(var j = 0; j < Math.max(p.content.length, c.content.length); j++) {
|
||||
if(p.content.charAt(j) === c.content.charAt(j)) {
|
||||
if(fIndex != null) {
|
||||
tString += c.content.charAt(j);
|
||||
dCount++;
|
||||
}
|
||||
} else {
|
||||
tString += c.content.charAt(j);
|
||||
if(fIndex === null) {
|
||||
fIndex = j;
|
||||
}
|
||||
dCount++;
|
||||
}
|
||||
}
|
||||
//Check from the end to the start, which characters are different.
|
||||
for(var j = 0; j < Math.min(p.content.length, c.content.length) - fIndex; j++) {
|
||||
if(p.content.charAt(p.content.length - 1 - j) !== c.content.charAt(c.content.length - 1 - j)) {
|
||||
if(eIndex == null) {
|
||||
eIndex = j;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
//This accounts for the fact when changing from "aa" to "aaa" (for example).
|
||||
if(eIndex === null) {
|
||||
eIndex = Math.min(p.content.length, c.content.length) - fIndex;
|
||||
}
|
||||
tString = tString.substring(0, tString.length - eIndex);
|
||||
}
|
||||
} else {
|
||||
tString = c.content;
|
||||
fIndex = 0;
|
||||
eIndex = tString.length;
|
||||
}
|
||||
compiledStack.push({
|
||||
"timestamp":adjustedTimestamp,
|
||||
"difContent":tString,
|
||||
"difFIndex":fIndex,
|
||||
"difEIndex":eIndex,
|
||||
"selFIndex":c.startPos,
|
||||
"selEIndex":c.endPos
|
||||
});
|
||||
}
|
||||
} else {
|
||||
//Just return the empty array.
|
||||
}
|
||||
return compiledStack;
|
||||
},
|
||||
play: function(_stack, _elem) {
|
||||
if(_stack.length === 0) {
|
||||
console.warn("SPADE: No events to play.")
|
||||
return
|
||||
}
|
||||
if(_elem.setValue) {
|
||||
_elem.setValue(_stack[0].difContent);
|
||||
} else {
|
||||
_elem.value = _stack[0].difContent
|
||||
}
|
||||
_stack = _stack.slice();
|
||||
_stack.shift();
|
||||
var curTime, dTime;
|
||||
var elapsedTime = 0;
|
||||
var prevTime = (new Date()).getTime();
|
||||
var playbackInterval = setInterval(function() {
|
||||
curTime = (new Date()).getTime();
|
||||
dTime = curTime - prevTime;
|
||||
dTime *= 1; //Multiply for faster/slower playback speeds.
|
||||
elapsedTime += dTime;
|
||||
var tArray = _stack.filter(function(_event) {
|
||||
return ((_event.timestamp) >= (elapsedTime - dTime)) && ((_event.timestamp) < (elapsedTime));
|
||||
});
|
||||
for(var i = 0; i < tArray.length; i++) {
|
||||
var tEvent = tArray[i];
|
||||
var oVal = null;
|
||||
if(_elem.getValue) {
|
||||
oVal = _elem.getValue();
|
||||
} else {
|
||||
oVal = _elem.value;
|
||||
}
|
||||
if(tEvent.difFIndex !== null && tEvent.difEIndex !== null) {
|
||||
if(_elem.setValue) {
|
||||
_elem.setValue(oVal.substring(0, tEvent.difFIndex) + tEvent.difContent + oVal.substring(oVal.length - tEvent.difEIndex, oVal.length));
|
||||
} else {
|
||||
_elem.value = oVal.substring(0, tEvent.difFIndex) + tEvent.difContent + oVal.substring(oVal.length - tEvent.difEIndex, oVal.length)
|
||||
}
|
||||
}
|
||||
if(_elem.selection && _elem.selection.moveCursorToPosition) {
|
||||
//Maybe this will work someday
|
||||
_elem.selection.moveCursorToPosition(tEvent.selFIndex);
|
||||
_elem.selection.setSelectionAnchor(tEvent.selEIndex.row, tEvent.selEIndex.column);
|
||||
_elem.selection.selectTo(tEvent.selFIndex.row, tEvent.selFIndex.column);
|
||||
} else {
|
||||
//Likewise
|
||||
_elem.focus();
|
||||
_elem.setSelectionRange(tEvent.selFIndex, tEvent.selEIndex);
|
||||
}
|
||||
}
|
||||
if(_stack[_stack.length - 1] === undefined || elapsedTime > _stack[_stack.length - 1].timestamp) {
|
||||
clearInterval(playbackInterval);
|
||||
}
|
||||
prevTime = curTime;
|
||||
}, 10);
|
||||
},
|
||||
debugPlay: function(_stack) {
|
||||
var area = document.createElement('textarea');
|
||||
area.zIndex = 9999;
|
||||
area.style.width = "512px";
|
||||
area.style.height = "512px";
|
||||
area.style.position = "absolute";
|
||||
area.style.left = "100px";
|
||||
area.style.top = "100px";
|
||||
document.body.appendChild(area);
|
||||
this.play(_stack, area);
|
||||
},
|
||||
condense: function(_stack) {
|
||||
var compressedArray = [];
|
||||
for(var i = 0; i < _stack.length; i++) {
|
||||
var u = _stack[i];
|
||||
compressedArray.push([
|
||||
u.timestamp,
|
||||
u.difContent,
|
||||
u.difFIndex,
|
||||
u.difEIndex,
|
||||
u.selFIndex.row,
|
||||
u.selFIndex.column,
|
||||
u.selEIndex.row,
|
||||
u.selEIndex.column
|
||||
]);
|
||||
}
|
||||
return compressedArray;
|
||||
},
|
||||
expand: function(_array) {
|
||||
var uncompressedArray = [];
|
||||
for(var i = 0 ; i < _array.length; i++) {
|
||||
var c = _array[i];
|
||||
uncompressedArray.push({
|
||||
"timestamp":c[0],
|
||||
"difContent":c[1],
|
||||
"difFIndex":c[2],
|
||||
"difEIndex":c[3],
|
||||
"selFIndex":{
|
||||
"row":c[4],
|
||||
"column":c[5]
|
||||
},
|
||||
"selEIndex":{
|
||||
"row":c[6],
|
||||
"column":c[7]
|
||||
},
|
||||
});
|
||||
}
|
||||
return uncompressedArray;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue