Skip to content

Commit

Permalink
Fixed avatar loader. Bumped version to 1.1.2
Browse files Browse the repository at this point in the history
  • Loading branch information
SandroHc committed Feb 26, 2017
1 parent b293f5a commit efc32f7
Show file tree
Hide file tree
Showing 8 changed files with 97 additions and 37 deletions.
1 change: 1 addition & 0 deletions src/assets/js/actors.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ add_actor = (selected = CONFIG.default_actor) ->

select_actor = document.createElement 'select'
select_actor.id = 'actor_' + id + '_edit'
select_actor.className = 'actor_select'
select_actor.dataset.actor = id

label = document.createElement 'label'
Expand Down
2 changes: 1 addition & 1 deletion src/assets/js/config.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ regions = [
]

CONFIG =
version: '1.1.1'
version: '1.1.2'
default_lang: 'pt'
lang: this.default_lang
default_region: '0' # Brazil
Expand Down
44 changes: 34 additions & 10 deletions src/assets/js/functions.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -51,17 +51,24 @@ get_player_info = (username, callback) ->
if !username
callback(null)

timestamp = Date.now().toString()
message = [
'anonymous' # Private key
'GET' # HTTP method
'http://api2.' + regions[CONFIG.region].link + '/v2/profile/find/' + username
timestamp
]
hash = CryptoJS.HmacSHA1(message.join('+'), 'anonymous')

$.ajax
# API: http://api2.amordoce.com/v2/profile/find/username
# API: http://api2.amordoce.com/v2/profile/find/username
url: "https://mcl.sandrohc.net/" + regions[CONFIG.region].id + "/v2/profile/find/" + username,
headers:
"X-Beemoov-Application": 'anonymous',
# FIXME Credentials only accepted on the BR server. You don't have to be logged in to see profiles, so there must be a way to bypass this
"X-Beemoov-Signature": 'e33b9ed89eeee95172d6db8a8143d660c9568aa9',
"X-Beemoov-Timestamp": '1487082505641'
"X-Beemoov-Signature": hash,
"X-Beemoov-Timestamp": timestamp
error: (jqXHR, textStatus, errorThrown) ->
console.log "Error while fetching player info"
console.log errorThrown
console.warn "Unable to fetch player info"
callback(null)
success: (data) ->
callback(data.data)
Expand Down Expand Up @@ -111,9 +118,17 @@ draw_avatar = (is_portrait, dest) ->
site = 'http://assets.' + regions[CONFIG.region].link + '/'
type = if is_portrait then 'portrait' else 'normal'
bg = ''
avatar = CONFIG.player.avatar

add_comma = false
add_clothes = (data, color, clothe_type) ->
if data.category == 'Skin'
avatar.avatar.bodyType = data
avatar.avatar.bodyType.category = 'CUSTOM'
return
if data.category == 'Wig'
avatar.avatar.hairType.category = 'CUSTOM'

if add_comma
bg += ','
add_comma = true
Expand All @@ -123,17 +138,26 @@ draw_avatar = (is_portrait, dest) ->
bg += '_' + color.id + '-' + color.security
bg += '.png)'

avatar = CONFIG.player.avatar

# TODO Better handle special cases, like Skin and Wig
for i in [avatar.clothes.length-1 .. 0]
add_clothes(avatar.clothes[i], null, 'clothe')

add_clothes(avatar.avatar.headAccessory, null, 'avatarpart')
add_clothes(avatar.avatar.mouthType, null, 'avatarpart')
add_clothes(avatar.avatar.eyebrowsType, avatar.avatar.hairColor, 'avatarpart')
add_clothes(avatar.avatar.eyeType, avatar.avatar.eyeColor, 'avatarpart')
add_clothes(avatar.avatar.hairType, avatar.avatar.hairColor, 'avatarpart')
add_clothes(avatar.avatar.bodyType, null, 'avatarpart')

if avatar.avatar.hairType.category == 'CUSTOM'
console.debug 'Custom hair'
else
add_clothes(avatar.avatar.hairType, avatar.avatar.hairColor, 'avatarpart')

if avatar.avatar.bodyType.category == 'CUSTOM'
console.debug 'Custom body'
add_clothes(avatar.avatar.bodyType, null, 'clothe')
else
add_clothes(avatar.avatar.bodyType, null, 'avatarpart')


dest.src = 'assets/img/' + (if is_portrait then 'face' else 'body') + '_placeholder.png'
dest.style.backgroundImage = bg
Expand Down
10 changes: 3 additions & 7 deletions src/assets/js/functions_events.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -55,13 +55,9 @@ update_username_btn = ->

eventChange = new Event 'change'

query = document.getElementById('actor1_edit')
if query.options[query.selectedIndex].text == '[Docete]'
query.dispatchEvent eventChange

query = document.getElementById('actor2_edit')
if query.options[query.selectedIndex].text == '[Docete]'
query.dispatchEvent eventChange
for el in document.getElementsByClassName('actor_select')
if el.options && el.options[el.selectedIndex].text == '[Docete]'
el.dispatchEvent eventChange

query = document.getElementById('avatar_edit')
if query.options[query.selectedIndex].text == '[Docete]'
Expand Down
52 changes: 36 additions & 16 deletions src/dist/js/bundle.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ regions = [
];

CONFIG = {
version: '1.1.1',
version: '1.1.2',
default_lang: 'pt',
lang: this.default_lang,
default_region: '0',
Expand Down Expand Up @@ -5639,19 +5639,22 @@ load_username = function() {
};

get_player_info = function(username, callback) {
var hash, message, timestamp;
if (!username) {
callback(null);
}
timestamp = Date.now().toString();
message = ['anonymous', 'GET', 'http://api2.' + regions[CONFIG.region].link + '/v2/profile/find/' + username, timestamp];
hash = CryptoJS.HmacSHA1(message.join('+'), 'anonymous');
$.ajax({
url: "https://mcl.sandrohc.net/" + regions[CONFIG.region].id + "/v2/profile/find/" + username,
headers: {
"X-Beemoov-Application": 'anonymous',
"X-Beemoov-Signature": 'e33b9ed89eeee95172d6db8a8143d660c9568aa9',
"X-Beemoov-Timestamp": '1487082505641'
"X-Beemoov-Signature": hash,
"X-Beemoov-Timestamp": timestamp
},
error: function(jqXHR, textStatus, errorThrown) {
console.log("Error while fetching player info");
console.log(errorThrown);
console.warn("Unable to fetch player info");
return callback(null);
},
success: function(data) {
Expand Down Expand Up @@ -5703,8 +5706,17 @@ draw_avatar = function(is_portrait, dest) {
site = 'http://assets.' + regions[CONFIG.region].link + '/';
type = is_portrait ? 'portrait' : 'normal';
bg = '';
avatar = CONFIG.player.avatar;
add_comma = false;
add_clothes = function(data, color, clothe_type) {
if (data.category === 'Skin') {
avatar.avatar.bodyType = data;
avatar.avatar.bodyType.category = 'CUSTOM';
return;
}
if (data.category === 'Wig') {
avatar.avatar.hairType.category = 'CUSTOM';
}
if (add_comma) {
bg += ',';
}
Expand All @@ -5715,16 +5727,24 @@ draw_avatar = function(is_portrait, dest) {
}
return bg += '.png)';
};
avatar = CONFIG.player.avatar;
for (i = j = ref = avatar.clothes.length - 1; ref <= 0 ? j <= 0 : j >= 0; i = ref <= 0 ? ++j : --j) {
add_clothes(avatar.clothes[i], null, 'clothe');
}
add_clothes(avatar.avatar.headAccessory, null, 'avatarpart');
add_clothes(avatar.avatar.mouthType, null, 'avatarpart');
add_clothes(avatar.avatar.eyebrowsType, avatar.avatar.hairColor, 'avatarpart');
add_clothes(avatar.avatar.eyeType, avatar.avatar.eyeColor, 'avatarpart');
add_clothes(avatar.avatar.hairType, avatar.avatar.hairColor, 'avatarpart');
add_clothes(avatar.avatar.bodyType, null, 'avatarpart');
if (avatar.avatar.hairType.category === 'CUSTOM') {
console.debug('Custom hair');
} else {
add_clothes(avatar.avatar.hairType, avatar.avatar.hairColor, 'avatarpart');
}
if (avatar.avatar.bodyType.category === 'CUSTOM') {
console.debug('Custom body');
add_clothes(avatar.avatar.bodyType, null, 'clothe');
} else {
add_clothes(avatar.avatar.bodyType, null, 'avatarpart');
}
dest.src = 'assets/img/' + (is_portrait ? 'face' : 'body') + '_placeholder.png';
dest.style.backgroundImage = bg;
};
Expand Down Expand Up @@ -5822,6 +5842,7 @@ add_actor = function(selected) {
div.classList.add('input-field', 'col', 's12', 'm5', 'actor_' + id);
select_actor = document.createElement('select');
select_actor.id = 'actor_' + id + '_edit';
select_actor.className = 'actor_select';
select_actor.dataset.actor = id;
label = document.createElement('label');
label["for"] = 'actor_' + id + '_edit';
Expand Down Expand Up @@ -6007,19 +6028,18 @@ update_username_btn = function() {
set_config('username', CONFIG.player.username);
set_config('region', CONFIG.region);
return get_player_info(CONFIG.player.username, function(data) {
var eventChange, query;
var el, eventChange, i, len, query, ref;
CONFIG.player.info = data;
if (CONFIG.player.info) {
CONFIG.player.id = CONFIG.player.info.player.id;
}
eventChange = new Event('change');
query = document.getElementById('actor1_edit');
if (query.options[query.selectedIndex].text === '[Docete]') {
query.dispatchEvent(eventChange);
}
query = document.getElementById('actor2_edit');
if (query.options[query.selectedIndex].text === '[Docete]') {
query.dispatchEvent(eventChange);
ref = document.getElementsByClassName('actor_select');
for (i = 0, len = ref.length; i < len; i++) {
el = ref[i];
if (el.options && el.options[el.selectedIndex].text === '[Docete]') {
el.dispatchEvent(eventChange);
}
}
query = document.getElementById('avatar_edit');
if (query.options[query.selectedIndex].text === '[Docete]') {
Expand Down
6 changes: 3 additions & 3 deletions src/dist/js/bundle.min.js

Large diffs are not rendered by default.

17 changes: 17 additions & 0 deletions src/dist/js/libs/CryptoJS-hmac-sha1.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions src/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,8 @@
<!-- CDN: http://code.interactjs.io/v1.2.6/interact.min.js -->
<script src="dist/js/libs/interact.min.js" onload="init_drag()" async defer></script>

<script src="dist/js/libs/CryptoJS-hmac-sha1.js"></script>

<script src="dist/js/bundle.min.js"></script>
</body>
</html>

0 comments on commit efc32f7

Please sign in to comment.