mirror of
https://github.com/Ekokumppanit/Bicyclesim.git
synced 2026-01-26 03:04:09 +00:00
Upgrade Meteor. Use keyboard for speed input.
This commit is contained in:
1
.meteor/.gitignore
vendored
1
.meteor/.gitignore
vendored
@@ -1 +1,2 @@
|
||||
local
|
||||
meteorite
|
||||
|
||||
@@ -11,3 +11,5 @@ stylus
|
||||
accounts-google
|
||||
underscore
|
||||
accounts-ui
|
||||
jquery-ui
|
||||
jquery-ui-bootstrap
|
||||
|
||||
1
.meteor/release
Normal file
1
.meteor/release
Normal file
@@ -0,0 +1 @@
|
||||
0.6.2.1
|
||||
@@ -1,5 +1,5 @@
|
||||
var Routes = new Meteor.Collection('routes');
|
||||
var Points = new Meteor.Collection('points');
|
||||
Routes = new Meteor.Collection('routes');
|
||||
Points = new Meteor.Collection('points');
|
||||
|
||||
Routes.allow({
|
||||
insert: function (userId, doc) {
|
||||
|
||||
@@ -16,6 +16,7 @@
|
||||
{{/if}}
|
||||
{{#if sim}}
|
||||
{{> sim}}
|
||||
<div class="speedSliderContainer"><div class="speedSlider"></div></li></div>
|
||||
{{/if}}
|
||||
{{#if frontpage}}
|
||||
{{> frontpage}}
|
||||
@@ -165,20 +166,9 @@
|
||||
<ul class="speedometer">
|
||||
<li class="distance">{{km distance}} km</li>
|
||||
<li class="speed">{{kmh speed}} <sup>km</sup>/<sub>h<sub></li>
|
||||
<li class="calories"></li>
|
||||
</ul>
|
||||
</template>
|
||||
|
||||
<template name="distance">
|
||||
<span>{{distance}}</span> km
|
||||
</template>
|
||||
<template name="speed">
|
||||
<span>{{speed}}</span> <sup>km</sup>/<sub>h</sub>
|
||||
</template>
|
||||
<template name="calories">
|
||||
<span>{{calories}}</span> cal
|
||||
</template>
|
||||
|
||||
<template name="points">
|
||||
<h3>Points
|
||||
<span><label class="checkbox inline"><input type="checkbox" id="points-autoadd" {{#if autoadd}}checked="checked"{{/if}}/>Auto add points</label></span>
|
||||
|
||||
@@ -115,17 +115,16 @@ a.thumbnail
|
||||
height 250px
|
||||
left 0
|
||||
top 0
|
||||
opacity 0.8
|
||||
display none
|
||||
opacity 0.0
|
||||
|
||||
.street
|
||||
filter(blur(4px))
|
||||
// filter(blur(4px))
|
||||
|
||||
.show-map
|
||||
.street
|
||||
filter(blur(0))
|
||||
// filter(blur(0))
|
||||
.map
|
||||
display block
|
||||
opacity 0.8
|
||||
|
||||
.show-sidebar
|
||||
.street, .map
|
||||
@@ -138,7 +137,7 @@ a.thumbnail
|
||||
bottom 42px
|
||||
left 0
|
||||
right 0
|
||||
background rgba(0, 0, 0, 0.5)
|
||||
// background rgba(0, 0, 0, 0.5)
|
||||
padding-top 30px
|
||||
overflow-y auto
|
||||
|
||||
@@ -186,6 +185,13 @@ ol.points
|
||||
font-weight bold
|
||||
line-height 150%
|
||||
|
||||
.speedSliderContainer
|
||||
position absolute
|
||||
bottom 100px
|
||||
right 20px
|
||||
.speedSlider
|
||||
height 200px
|
||||
|
||||
::-webkit-scrollbar
|
||||
background transparent
|
||||
border none
|
||||
|
||||
@@ -118,14 +118,14 @@ Template.editing.owner = function () {
|
||||
return user.profile.name;
|
||||
};
|
||||
|
||||
function init_edit() {
|
||||
init_edit = function init_edit() {
|
||||
|
||||
Meteor.autorun(function () {
|
||||
if (Session.equals('page', 'edit') && Session.get('route')) {
|
||||
debug('sivu tai route vaihtui, route: ' + Session.get('route'));
|
||||
full_clear_required = true;
|
||||
|
||||
Meteor.deps.isolate(function () {
|
||||
Deps.nonreactive(function () {
|
||||
var route = Routes.findOne({_id: Session.get('route')});
|
||||
if (route) {
|
||||
maps.travel(route.first, {route: true});
|
||||
@@ -141,7 +141,7 @@ Meteor.autosubscribe(function () {
|
||||
|
||||
if (Session.equals('page', 'edit') && Session.get('route')) {
|
||||
if (full_clear_required) {
|
||||
Meteor.deps.isolate(function () {
|
||||
Deps.nonreactive(function () {
|
||||
debug('full clear');
|
||||
|
||||
maps.lines.route.clear();
|
||||
|
||||
@@ -10,12 +10,12 @@ helpers = {
|
||||
}
|
||||
};
|
||||
|
||||
var activateInput = function (input) {
|
||||
activateInput = function (input) {
|
||||
input.focus();
|
||||
input.select();
|
||||
};
|
||||
|
||||
var okCancelEvents = function (selector, callbacks) {
|
||||
okCancelEvents = function (selector, callbacks) {
|
||||
var ok = callbacks.ok || function () {};
|
||||
var cancel = callbacks.cancel || function () {};
|
||||
|
||||
@@ -38,9 +38,3 @@ var okCancelEvents = function (selector, callbacks) {
|
||||
};
|
||||
return events;
|
||||
};
|
||||
|
||||
// From: https://github.com/tmeasday/meteor-deps-extensions
|
||||
Meteor.deps.isolate = function(fn) {
|
||||
var context = new Meteor.deps.Context();
|
||||
return context.run(fn);
|
||||
};
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
function maps_loaded() {
|
||||
maps_loaded = function maps_loaded() {
|
||||
|
||||
window.markers = []; // fuu
|
||||
|
||||
@@ -170,7 +170,7 @@ $(document).ready(function () {
|
||||
init_edit();
|
||||
});
|
||||
|
||||
}
|
||||
};
|
||||
|
||||
window.onload = function () {
|
||||
var script = document.createElement("script");
|
||||
|
||||
@@ -164,7 +164,7 @@ Meteor.startup(function () {
|
||||
Backbone.history.start({pushState: true});
|
||||
});
|
||||
|
||||
function init_main() {
|
||||
init_main = function init_main() {
|
||||
Meteor.autosubscribe(function () {
|
||||
// When changing page
|
||||
|
||||
@@ -182,4 +182,4 @@ function init_main() {
|
||||
maps.mode('sim');
|
||||
}
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
@@ -1,30 +1,11 @@
|
||||
window.point = null;
|
||||
window.traveled = 0;
|
||||
|
||||
var createRingBuffer = function (length){
|
||||
var pointer = 0, buffer = [], sum = 0;
|
||||
function move () {
|
||||
if (!window.point) return;
|
||||
|
||||
return {
|
||||
push: function (item) {
|
||||
if (buffer[pointer] > 0) {
|
||||
sum -= buffer[pointer];
|
||||
if (sum <= 0) sum = 0;
|
||||
}
|
||||
buffer[pointer] = item;
|
||||
sum += item;
|
||||
pointer = (length + pointer + 1) % length;
|
||||
},
|
||||
sum: function () {
|
||||
return sum;
|
||||
}
|
||||
};
|
||||
};
|
||||
|
||||
var revs = 0;
|
||||
$(document).bind('keydown.space', function () {
|
||||
revs += 1;
|
||||
|
||||
var dist = localStorage['multiplier'] * c();
|
||||
// var dist = localStorage['multiplier'] * c();
|
||||
var dist = localStorage['multiplier'] * 0.1 * Session.get('speed');
|
||||
Session.set('distance', Session.get('distance') + dist);
|
||||
window.traveled += dist;
|
||||
|
||||
@@ -39,22 +20,23 @@ $(document).bind('keydown.space', function () {
|
||||
window.point = next;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
setInterval(move, 100);
|
||||
|
||||
var line = '';
|
||||
$(document).on('keydown', function (e) {
|
||||
if (e.keyCode === 13) { // enter
|
||||
if (line.length >= 1 && line[0] == 'S') {
|
||||
var speed = Number(line.slice(1));
|
||||
Session.set('speed', speed);
|
||||
}
|
||||
line = '';
|
||||
} else {
|
||||
line += String.fromCharCode(e.keyCode);
|
||||
}
|
||||
});
|
||||
|
||||
// function speedo() {
|
||||
// speed_buffer.push(revs * c());
|
||||
// revs = 0;
|
||||
|
||||
// Session.set('speed', speed_buffer.sum() / 5);
|
||||
// }
|
||||
|
||||
// setInterval(speedo, 500);
|
||||
|
||||
// 5sec, 2 values / sec.
|
||||
var speed_buffer = createRingBuffer(5 * 2);
|
||||
var speed_sum = 0;
|
||||
var speed_avg = 0;
|
||||
|
||||
Template.sim.speed = function () {
|
||||
return Session.get('speed');
|
||||
};
|
||||
@@ -72,47 +54,7 @@ Template.sim.helpers({
|
||||
}
|
||||
});
|
||||
|
||||
var sock = new SockJS("http://localhost:9999/speed");
|
||||
|
||||
function init_sim() {
|
||||
|
||||
|
||||
sock.onopen = function() {
|
||||
console.log('open');
|
||||
};
|
||||
|
||||
sock.onmessage = function(e) {
|
||||
if (Session.equals('page', 'sim') && window.point) {
|
||||
debug('message', e.data);
|
||||
|
||||
var dist = parseInt(e.data, 10) * c();
|
||||
speed_buffer.push(dist);
|
||||
|
||||
Session.set('speed', speed_buffer.sum() / 5);
|
||||
|
||||
Session.set('distance', Session.get('distance') + 3 * dist);
|
||||
window.traveled += 3 * dist;
|
||||
|
||||
if (window.traveled >= window.point.distance) {
|
||||
var next = Points.findOne({_id: window.point.next});
|
||||
|
||||
// Stay on current point if no next point exists
|
||||
if (next) {
|
||||
window.traveled -= next.distance;
|
||||
|
||||
maps.travel(next._id, {route: true});
|
||||
zoom = 1;
|
||||
zoom_target = 1;
|
||||
window.point = next;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
sock.onclose = function() {
|
||||
console.log('close');
|
||||
};
|
||||
init_sim = function init_sim() {
|
||||
|
||||
Meteor.autosubscribe(function () {
|
||||
if (Session.equals('page', 'sim')) {
|
||||
@@ -135,7 +77,18 @@ Meteor.autosubscribe(function () {
|
||||
p = Points.findOne({_id: p.next});
|
||||
}
|
||||
}
|
||||
|
||||
$('.speedSlider').slider({
|
||||
orientation: 'vertical',
|
||||
range: 'min',
|
||||
min: 0,
|
||||
max: 22.2, // m/s
|
||||
value: 0,
|
||||
slide: function (event, ui) {
|
||||
Session.set('speed', ui.value);
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
}
|
||||
};
|
||||
|
||||
@@ -15,13 +15,13 @@ if (typeof Number.prototype.toDeg == 'undefined') {
|
||||
};
|
||||
}
|
||||
|
||||
function computeDistance(from, to) {
|
||||
computeDistance = function computeDistance(from, to) {
|
||||
// Equirectangular approximation, should be enough as distances are small
|
||||
var R = 6371000; // km
|
||||
var x = (to[1].toRad() - from[1].toRad()) * Math.cos((from[0].toRad() + to[0].toRad()) / 2);
|
||||
var y = (from[0].toRad() - to[0].toRad());
|
||||
return Math.sqrt(x * x + y * y) * R;
|
||||
}
|
||||
};
|
||||
|
||||
function computeInitialBearing(from, to) {
|
||||
var dLat = (to[0] - from[0]).toRad();
|
||||
@@ -34,12 +34,12 @@ function computeInitialBearing(from, to) {
|
||||
return (Math.atan2(y, x).toDeg() + 360) % 360;
|
||||
}
|
||||
|
||||
function computeFinalBearing(from, to) {
|
||||
computeFinalBearing = function computeFinalBearing(from, to) {
|
||||
return (computeInitialBearing(to, from) + 180) % 360;
|
||||
}
|
||||
};
|
||||
|
||||
// Rest are copied from: https://github.com/moshen/node-googlemaps/blob/master/lib/googlemaps.js
|
||||
function createEncodedPolyline(points) {
|
||||
createEncodedPolyline = function createEncodedPolyline(points) {
|
||||
// Dear maintainer:
|
||||
//
|
||||
// Once you are done trying to 'optimize' this routine,
|
||||
@@ -70,7 +70,7 @@ function createEncodedPolyline(points) {
|
||||
encoded_points += encodeSignedNumber(dlat) + encodeSignedNumber(dlng);
|
||||
}
|
||||
return encoded_points;
|
||||
}
|
||||
};
|
||||
|
||||
function encodeNumber(num) {
|
||||
var encodeString = "";
|
||||
|
||||
6
smart.json
Normal file
6
smart.json
Normal file
@@ -0,0 +1,6 @@
|
||||
{
|
||||
"packages": {
|
||||
"jquery-ui": {},
|
||||
"jquery-ui-bootstrap": {}
|
||||
}
|
||||
}
|
||||
25
smart.lock
Normal file
25
smart.lock
Normal file
@@ -0,0 +1,25 @@
|
||||
{
|
||||
"meteor": {
|
||||
"git": "https://github.com/meteor/meteor.git",
|
||||
"branch": "master",
|
||||
"commit": "bfe4b72ebec4367eaddcdf0887fcf5e649d9dcb8"
|
||||
},
|
||||
"dependencies": {
|
||||
"basePackages": {
|
||||
"jquery-ui": {},
|
||||
"jquery-ui-bootstrap": {}
|
||||
},
|
||||
"packages": {
|
||||
"jquery-ui": {
|
||||
"git": "https://github.com/TimHeckel/meteor-jquery-ui.git",
|
||||
"tag": "v1.9.2",
|
||||
"commit": "c437d45edcf1367df8d5ffa8bad2867758030bd2"
|
||||
},
|
||||
"jquery-ui-bootstrap": {
|
||||
"git": "https://github.com/TimHeckel/meteor-jquery-ui-bootstrap.git",
|
||||
"tag": "v0.1.2",
|
||||
"commit": "fa742a85639307003e105898e15b631394b63509"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user