Pārlūkot izejas kodu

fixes #34

tags/v0.1.8^2
Big Bad Waffle pirms 6 gadiem
vecāks
revīzija
8fc8d853d5
4 mainītis faili ar 64 papildinājumiem un 39 dzēšanām
  1. +12
    -13
      src/client/js/input.js
  2. +10
    -10
      src/client/js/main.js
  3. +17
    -15
      src/client/js/system/client.js
  4. +25
    -1
      src/server/components/trade.js

+ 12
- 13
src/client/js/input.js Parādīt failu

@@ -1,7 +1,7 @@
define([
'js/system/events',
'js/rendering/renderer'
], function(
], function (
events,
renderer
) {
@@ -48,7 +48,7 @@ define([

enabled: true,

init: function() {
init: function () {
$(window).on('keydown', this.events.keyboard.keyDown.bind(this));
$(window).on('keyup', this.events.keyboard.keyUp.bind(this));
events.on('onSceneMove', this.events.mouse.mouseMove.bind(this));
@@ -59,7 +59,7 @@ define([
.on('mousemove', this.events.mouse.mouseMove.bind(this));
},

resetKeys: function() {
resetKeys: function () {
for (var k in this.keys) {
events.emit('onKeyUp', k);
}
@@ -67,7 +67,7 @@ define([
this.keys = {};
},

getMapping: function(charCode) {
getMapping: function (charCode) {
if (charCode >= 97)
return (charCode - 96).toString();

@@ -78,7 +78,7 @@ define([

},

isKeyDown: function(key, noConsume) {
isKeyDown: function (key, noConsume) {
var down = this.keys[key];
if (down != null) {
if (noConsume)
@@ -90,7 +90,7 @@ define([
} else
return false;
},
getAxis: function(name) {
getAxis: function (name) {
var axis = this.axes[name];
if (!axis)
return 0;
@@ -116,7 +116,7 @@ define([

events: {
keyboard: {
keyDown: function(e) {
keyDown: function (e) {
if (!this.enabled)
return;

@@ -138,9 +138,8 @@ define([
return false;
else if (e.key == 'F11')
events.emit('onToggleFullscreen');

},
keyUp: function(e) {
keyUp: function (e) {
if (!this.enabled)
return;

@@ -155,7 +154,7 @@ define([
}
},
mouse: {
mouseDown: function(e) {
mouseDown: function (e) {
var el = $(e.target);
if ((!el.hasClass('ui-container')) || (el.hasClass('blocking')))
return;
@@ -167,7 +166,7 @@ define([

events.emit('mouseDown', this.mouse);
},
mouseUp: function(e) {
mouseUp: function (e) {
var el = $(e.target);
if ((!el.hasClass('ui-container')) || (el.hasClass('blocking')))
return;
@@ -178,7 +177,7 @@ define([

events.emit('mouseUp', this.mouse);
},
mouseMove: function(e) {
mouseMove: function (e) {
if (e)
this.mouseRaw = e;
else
@@ -199,4 +198,4 @@ define([
}
}
};
});
});

+ 10
- 10
src/client/js/main.js Parādīt failu

@@ -21,7 +21,7 @@ define([
'ui/templates/tooltips/tooltips',
'ui/templates/reputation/reputation',
'ui/templates/death/death'
], function(
], function (
client,
uiFactory,
renderer,
@@ -35,11 +35,11 @@ define([
return {
hasFocus: true,

init: function() {
init: function () {
client.init(this.onClientReady.bind(this));
},

onClientReady: function() {
onClientReady: function () {
client.request({
module: 'clientConfig',
method: 'getResourcesList',
@@ -47,16 +47,16 @@ define([
});
},

onGetResourceList: function(list) {
onGetResourceList: function (list) {
resources.init(list);

events.on('onResourcesLoaded', this.start.bind(this));
},

start: function() {
start: function () {
window.onfocus = this.onFocus.bind(this, true);
window.onblur = this.onFocus.bind(this, false);
$(window).on('contextmenu', function(e) {
$(window).on('contextmenu', function (e) {
e.preventDefault();
return false;
});
@@ -74,7 +74,7 @@ define([
this.render();
},

onFocus: function(hasFocus) {
onFocus: function (hasFocus) {
//Hack: Later we might want to make it not render when out of focus
this.hasFocus = true;

@@ -82,14 +82,14 @@ define([
input.resetKeys();
},

render: function() {
render: function () {
numbers.render();

renderer.render();

requestAnimationFrame(this.render.bind(this));
},
update: function() {
update: function () {
objects.update();
renderer.update();
uiFactory.update();
@@ -97,4 +97,4 @@ define([
setTimeout(this.update.bind(this), 16);
}
};
});
});

+ 17
- 15
src/client/js/system/client.js Parādīt failu

@@ -1,20 +1,20 @@
define([
'socket',
'js/system/events'
], function(
], function (
io,
events
) {
var client = {
doneConnect: false,

init: function(onReady) {
init: function (onReady) {
var tType = 'websocket';
if (window.location.href.indexOf('polling') > -1)
tType = 'polling';

this.socket = io({
transports: [ tType ]
transports: [tType]
});

this.socket.on('connect', this.onConnected.bind(this, onReady));
@@ -23,7 +23,7 @@ define([
this.socket.on('events', this.onEvents.bind(this));
this.socket.on('dc', this.onDisconnect.bind(this));
},
onConnected: function(onReady) {
onConnected: function (onReady) {
if (this.doneConnect)
this.onDisconnect();
else
@@ -32,30 +32,32 @@ define([
if (onReady)
onReady();
},
onDisconnect: function() {
onDisconnect: function () {
window.location = window.location;
},
onHandshake: function() {
onHandshake: function () {
events.emit('onHandshake');
this.socket.emit('handshake');
},
request: function(msg) {
request: function (msg) {
this.socket.emit('request', msg, msg.callback);
},
onEvent: function(response) {
onEvent: function (response) {
events.emit(response.event, response.data);
},
onEvents: function(response) {
onEvents: function (response) {
//If we get objects, self needs to be first
// otherwise we might create the object (setting his position or attack animation)
// before instantiating it
var oList = response.onGetObject;
if (oList) {
var prepend = oList.filter(function(o) {
var prepend = oList.filter(function (o) {
return o.self;
});
oList.spliceWhere(function(o) {
return prepend.some(function(p) { return p == o; });
oList.spliceWhere(function (o) {
return prepend.some(function (p) {
return p == o;
});
});
oList.unshift.apply(oList, prepend);
}
@@ -64,7 +66,7 @@ define([
var r = response[e];

//Certain messages expect to be performed last (because the object they act on hasn't been greated when they get queued)
r.sort(function(a, b) {
r.sort(function (a, b) {
if (a.performLast)
return 1;
else if (b.performLast)
@@ -73,7 +75,7 @@ define([
return 0;
});

r.forEach(function(o) {
r.forEach(function (o) {
events.emit(e, o);
});
}
@@ -81,4 +83,4 @@ define([
};

return client;
});
});

+ 25
- 1
src/server/components/trade.js Parādīt failu

@@ -293,9 +293,33 @@ define([

this.target = target;

var reputation = this.obj.reputation;

this.obj.syncer.set(true, 'trade', 'sellList', {
markup: target.trade.markup.buy,
items: this.obj.inventory.items.filter(i => ((i.worth > 0) && (!i.eq)))
items: this.obj.inventory.items
.filter(i => ((i.worth > 0) && (!i.eq)))
.map(function (i) {
if (i.factions) {
i.factions = i.factions.map(function (f) {
var faction = reputation.getBlueprint(f.id);
var factionTier = reputation.getTier(f.id);

var noEquip = null;
if (factionTier < f.tier)
noEquip = true;

return {
name: faction.name,
tier: f.tier,
tierName: ['Hated', 'Hostile', 'Unfriendly', 'Neutral', 'Friendly', 'Honored', 'Revered', 'Exalted'][f.tier],
noEquip: noEquip
};
}, this);
}

return i;
})
});
},



Notiek ielāde…
Atcelt
Saglabāt