summaryrefslogtreecommitdiff
path: root/public/assets/javascripts
diff options
context:
space:
mode:
authorryderr <r@okfoc.us>2014-10-20 12:55:42 -0400
committerryderr <r@okfoc.us>2014-10-20 12:55:42 -0400
commit2300f22955c0ee8250195e7f4cb70ac675570d7f (patch)
treef2b40f33e4ba6ad65f08d35c0396d166afa1d3ec /public/assets/javascripts
parentc99a5651e30838db43ee6f1b24a9fdc71d7affff (diff)
parent7fac90101bb5803ba593b0e11950009aa2115045 (diff)
Merge branch 'master' of github.com:okfocus/vvalls
Diffstat (limited to 'public/assets/javascripts')
-rw-r--r--public/assets/javascripts/app.js5
-rw-r--r--public/assets/javascripts/mx/extensions/mx.movements.js27
-rw-r--r--public/assets/javascripts/rectangles/models/floor.js36
-rw-r--r--public/assets/javascripts/ui/_router.js1
-rw-r--r--public/assets/javascripts/ui/builder/BuilderInfo.js21
-rw-r--r--public/assets/javascripts/ui/editor/Presets.js11
-rw-r--r--public/assets/javascripts/ui/lib/UploadView.js4
-rw-r--r--public/assets/javascripts/ui/reader/MediaPlayer.js2
-rw-r--r--public/assets/javascripts/util.js55
9 files changed, 136 insertions, 26 deletions
diff --git a/public/assets/javascripts/app.js b/public/assets/javascripts/app.js
index f8372cd..cfbe4bf 100644
--- a/public/assets/javascripts/app.js
+++ b/public/assets/javascripts/app.js
@@ -57,11 +57,14 @@ app.launch = function () {
}
app.movements.init()
+ var last_t = 0
function animate (t) {
+ var dt = t - last_t
+ last_t = t
requestAnimationFrame(animate)
environment.update(t)
window.path && path.update(t)
- app.movements.update()
+ app.movements.update(dt || 0)
scene.update()
}
diff --git a/public/assets/javascripts/mx/extensions/mx.movements.js b/public/assets/javascripts/mx/extensions/mx.movements.js
index 5b1e2de..2993fb6 100644
--- a/public/assets/javascripts/mx/extensions/mx.movements.js
+++ b/public/assets/javascripts/mx/extensions/mx.movements.js
@@ -254,7 +254,7 @@ MX.Movements = function (cam) {
}
},
- update: function () {
+ update: function (dt) {
if (locked) { return }
@@ -263,6 +263,11 @@ MX.Movements = function (cam) {
var vrrrr = creeping ? vr * creepFactor * 5 : vr * 0.5
var moving = moveForward || moveBackward || moveRight || moveLeft || moveUp || moveDown || turnLeft || turnRight || turnUp || turnDown
vx = vz = 0
+
+ var vv = v
+// vv *= dt / 100 * 8
+// s *= dt / 100 * 8
+// console.log(dt / 100 * 8)
pos.x = cam.x
pos.z = cam.z
@@ -270,26 +275,26 @@ MX.Movements = function (cam) {
if (moving) {
if (moveForward) {
- vx += v * Math.cos(ry + Math.PI / 2) * s
- vz += v * Math.sin(ry + Math.PI / 2) * s
+ vx += vv * Math.cos(ry + Math.PI / 2) * s
+ vz += vv * Math.sin(ry + Math.PI / 2) * s
}
if (moveBackward) {
- vx -= v * Math.cos(ry + Math.PI / 2) * s
- vz -= v * Math.sin(ry + Math.PI / 2) * s
+ vx -= vv * Math.cos(ry + Math.PI / 2) * s
+ vz -= vv * Math.sin(ry + Math.PI / 2) * s
}
if (moveLeft) {
- vx -= v * Math.cos(ry) * s
- vz -= v * Math.sin(ry) * s
+ vx -= vv * Math.cos(ry) * s
+ vz -= vv * Math.sin(ry) * s
}
if (moveRight) {
- vx += v * Math.cos(ry) * s
- vz += v * Math.sin(ry) * s
+ vx += vv * Math.cos(ry) * s
+ vz += vv * Math.sin(ry) * s
}
if (moveUp) {
- pos.y += v * scale
+ pos.y += vv * scale
}
if (moveDown) {
- pos.y -= v * scale
+ pos.y -= vv * scale
}
if (turnUp) {
diff --git a/public/assets/javascripts/rectangles/models/floor.js b/public/assets/javascripts/rectangles/models/floor.js
index a144ecd..2fb870f 100644
--- a/public/assets/javascripts/rectangles/models/floor.js
+++ b/public/assets/javascripts/rectangles/models/floor.js
@@ -36,8 +36,40 @@
this.mx.forEach(function(mx, index){
$(mx.el).bind({
+ contextmenu: function(e){
+ if (! (e.ctrlKey || e.metaKey || e.shiftKey) ) {
+ e.preventDefault()
+ }
+ if (Scenery.nextMedia) {
+ e.preventDefault()
+ Scenery.nextMedia = null
+ app.tube('cancel-scenery')
+ }
+ else if (Scenery.nextWallpaper) {
+ e.preventDefault()
+ Scenery.nextWallpaper = null
+ app.tube('cancel-wallpaper')
+ }
+ },
+
mousedown: function(e){
- if (Scenery.nextWallpaper) {
+
+ // right-click
+ if (e.which == 3) {
+ if (Scenery.nextMedia) {
+ e.preventDefault()
+ Scenery.nextMedia = null
+ app.tube('cancel-scenery')
+ }
+ else if (Scenery.nextWallpaper) {
+ e.preventDefault()
+ Scenery.nextWallpaper = null
+ app.tube('cancel-wallpaper')
+ }
+ return
+ }
+
+ if (Scenery.nextWallpaper) {
var oldState = base.serialize()
base.wallpaper(Scenery.nextWallpaper)
// Scenery.nextWallpaper = null
@@ -50,6 +82,8 @@
// TODO: watch individual scenery object here
Minotaur.watch( app.router.editorView.settings )
+
+ app.controller.pickWall(base, null)
}
else {
app.controller.pickWall(base, null)
diff --git a/public/assets/javascripts/ui/_router.js b/public/assets/javascripts/ui/_router.js
index 794079e..bda0960 100644
--- a/public/assets/javascripts/ui/_router.js
+++ b/public/assets/javascripts/ui/_router.js
@@ -212,7 +212,6 @@ var SiteRouter = Router.extend({
// this.documentModal.destroy(name)
},
-
testWallpaper: function(e){
var content = document.getElementById("content")
content.style.width = "680px"
diff --git a/public/assets/javascripts/ui/builder/BuilderInfo.js b/public/assets/javascripts/ui/builder/BuilderInfo.js
index 67834e7..4fd145d 100644
--- a/public/assets/javascripts/ui/builder/BuilderInfo.js
+++ b/public/assets/javascripts/ui/builder/BuilderInfo.js
@@ -10,8 +10,11 @@ var BuilderInfo = View.extend({
"change [name=width]": 'changeWidth',
"change [name=depth]": 'changeDepth',
"change [name=height]": 'changeHeight',
+ "keydown [name=width]": 'enterWidth',
+ "keydown [name=depth]": 'enterDepth',
+ "keydown [name=height]": 'enterHeight',
"change [name=units]": 'changeUnits',
- "change [name=resolution]": 'changeResolution',
+ "keydown [name=viewHeight]": 'enterViewHeight',
"change [name=viewHeight]": 'changeViewHeight',
"click [data-role=destroy-room]": 'destroy',
},
@@ -85,16 +88,27 @@ var BuilderInfo = View.extend({
this.hide()
},
+ enterWidth: function(e){
+ if (e.keyCode == 13) this.changeWidth(e)
+ },
changeWidth: function(e){
e.stopPropagation()
this.room.rect.x.setLength( this.$width.unitVal() )
Rooms.rebuild()
},
+
+ enterDepth: function(e){
+ if (e.keyCode == 13) this.changeDepth(e)
+ },
changeDepth: function(e){
e.stopPropagation()
this.room.rect.y.setLength( this.$depth.unitVal() )
Rooms.rebuild()
},
+
+ enterHeight: function(e){
+ if (e.keyCode == 13) this.changeHeight(e)
+ },
changeHeight: function(e){
e.stopPropagation()
this.room.height = this.$height.unitVal()
@@ -114,7 +128,10 @@ var BuilderInfo = View.extend({
app.units = this.$units.val()
this.$('.units').resetUnitVal()
},
- changeViewHeight: function(){
+ enterViewHeight: function(e){
+ if (e.keyCode == 13) this.changeViewHeight(e)
+ },
+ changeViewHeight: function(){
window.viewHeight = this.$viewHeight.unitVal( )
},
diff --git a/public/assets/javascripts/ui/editor/Presets.js b/public/assets/javascripts/ui/editor/Presets.js
index be86af3..ab311ef 100644
--- a/public/assets/javascripts/ui/editor/Presets.js
+++ b/public/assets/javascripts/ui/editor/Presets.js
@@ -84,15 +84,12 @@ var Presets = View.extend({
this.parent.colorControl.modes.forEach(function(mode){
if (! preset[mode].length) {
Walls.setWallpaper[mode](preset[mode])
- Walls.setColor[mode](preset[mode].color)
}
else {
- if (preset[mode].length) {
- Walls.clearWallpaper[mode]()
- }
- Walls.setColor[mode](preset[mode])
- this.parent.colorControl.$swatch[ mode ].css("background-color", rgb_string(preset[mode]))
- }
+ Walls.clearWallpaper[mode]()
+ }
+ Walls.setColor[mode](preset[mode])
+ this.parent.colorControl.$swatch[ mode ].css("background-color", rgb_string(preset[mode]))
}.bind(this))
this.parent.colorControl.setMode(preset.wall.color ? "wall" : "floor")
Walls.setBodyColor()
diff --git a/public/assets/javascripts/ui/lib/UploadView.js b/public/assets/javascripts/ui/lib/UploadView.js
index efaa8c9..2d2c2c7 100644
--- a/public/assets/javascripts/ui/lib/UploadView.js
+++ b/public/assets/javascripts/ui/lib/UploadView.js
@@ -4,12 +4,12 @@ var UploadView = View.extend({
// define uploadAction
events: {
- "change .file": "handleFileSelect",
+ "change [type=file]": "handleFileSelect",
"submit form": "preventDefault",
},
initialize: function(){
- this.$file = this.$(".file")
+ this.$file = this.$("[type=file]")
this.$upload = this.$(".upload-icon")
},
diff --git a/public/assets/javascripts/ui/reader/MediaPlayer.js b/public/assets/javascripts/ui/reader/MediaPlayer.js
index 6195ab6..7f73e1b 100644
--- a/public/assets/javascripts/ui/reader/MediaPlayer.js
+++ b/public/assets/javascripts/ui/reader/MediaPlayer.js
@@ -44,7 +44,7 @@ var MediaPlayer = FormView.extend({
this.unbind()
}
if (media.type == "image") {
- if ((! media.title || ! media.title.length) && (! media.description || ! media.description.length)) {
+ if ((! media.title || ! media.title.length) && (! media.description || ! media.description.length) || (media.title == filenameFromUrl(media.url)) ) {
this.hide()
return
}
diff --git a/public/assets/javascripts/util.js b/public/assets/javascripts/util.js
index 367e20e..2fa994a 100644
--- a/public/assets/javascripts/util.js
+++ b/public/assets/javascripts/util.js
@@ -185,3 +185,58 @@ function bitcount(v) {
v = (v & 0x33333333) + ((v >>> 2) & 0x33333333);
return ((v + (v >>> 4) & 0xF0F0F0F) * 0x1010101) >>> 24;
}
+
+// Function.bind polyfill
+if (!Function.prototype.bind) {
+ Function.prototype.bind = function(oThis) {
+ if (typeof this !== 'function') {
+ // closest thing possible to the ECMAScript 5
+ // internal IsCallable function
+ throw new TypeError('Function.prototype.bind - what is trying to be bound is not callable');
+ }
+
+ var aArgs = Array.prototype.slice.call(arguments, 1),
+ fToBind = this,
+ fNOP = function() {},
+ fBound = function() {
+ return fToBind.apply(this instanceof fNOP && oThis
+ ? this
+ : oThis,
+ aArgs.concat(Array.prototype.slice.call(arguments)));
+ };
+
+ fNOP.prototype = this.prototype;
+ fBound.prototype = new fNOP();
+
+ return fBound;
+ };
+}
+
+// rAF polyfill
+(function() {
+ var lastTime = 0;
+ var vendors = ['ms', 'moz', 'webkit', 'o'];
+ for(var x = 0; x < vendors.length && !window.requestAnimationFrame; ++x) {
+ window.requestAnimationFrame = window[vendors[x]+'RequestAnimationFrame'];
+ window.cancelAnimationFrame = window[vendors[x]+'CancelAnimationFrame']
+ || window[vendors[x]+'CancelRequestAnimationFrame'];
+ }
+
+ if (!window.requestAnimationFrame)
+ window.requestAnimationFrame = function(callback, element) {
+ var currTime = new Date().getTime();
+ var timeToCall = Math.max(0, 16 - (currTime - lastTime));
+ var id = window.setTimeout(function() { callback(currTime + timeToCall); },
+ timeToCall);
+ lastTime = currTime + timeToCall;
+ return id;
+ };
+
+ if (!window.cancelAnimationFrame)
+ window.cancelAnimationFrame = function(id) {
+ clearTimeout(id);
+ };
+}());
+
+
+