Compare commits
No commits in common. "7e970940ae349bb418465dedb7f23c0bf20e0984" and "41c5f3dc6ed6959d559c2bbf79cd9bd17df803e6" have entirely different histories.
7e970940ae
...
41c5f3dc6e
|
@ -126,78 +126,30 @@ let addDecorationsAndSave = (userId, loadedImage, res, next) => {
|
|||
let ribbonPx = 598;
|
||||
let ribbonPy = 95;
|
||||
|
||||
AwardingModel.find({
|
||||
'userId': userId,
|
||||
'confirmed': 1
|
||||
}, ['decorationId', 'date']).populate('decorationId', ['isMedal', 'fraction'])
|
||||
AwardingModel.find({'userId': userId, 'confirmed': 1}, ['decorationId', 'date'],
|
||||
{sort: {date: 'asc'}}).populate('decorationId', ['isMedal'])
|
||||
.exec((err, awardings) => {
|
||||
if (err) {
|
||||
return next(err);
|
||||
}
|
||||
if (awardings.length > 0) {
|
||||
|
||||
//TODO: simplify this sorting hell
|
||||
awardings.sort((a1, a2) => {
|
||||
if (!a1.decorationId.isMedal && !a2.decorationId.isMedal) {
|
||||
if (a1.decorationId.fraction === a2.decorationId.fraction) {
|
||||
if (a1.date !== a2.date) {
|
||||
if (a1.date < a2.date) {
|
||||
return -1;
|
||||
}
|
||||
if (a1.date > a2.date) {
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
} else {
|
||||
if (a1.decorationId.fraction === 'GLOBAL' && a2.decorationId.fraction !== 'GLOBAL') {
|
||||
return -1;
|
||||
}
|
||||
if (a2.decorationId.fraction === 'GLOBAL' && a1.decorationId.fraction !== 'GLOBAL') {
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (a1.decorationId.isMedal !== a2.decorationId.isMedal) {
|
||||
if (a1.decorationId.isMedal && !a2.decorationId.isMedal) {
|
||||
return 1;
|
||||
}
|
||||
if (!a1.decorationId.isMedal && a2.decorationId.isMedal) {
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
if (a1.decorationId.isMedal && a2.decorationId.isMedal) {
|
||||
if (a1.date !== a2.date) {
|
||||
if (a1.date < a2.date) {
|
||||
return -1;
|
||||
}
|
||||
if (a1.date > a2.date) {
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
});
|
||||
|
||||
// use synchronized call to keep correct order of decorations
|
||||
async.eachSeries(awardings, (award, callback) => {
|
||||
jimp.read(resourceDir + 'decoration/' + award.decorationId._id + fileExt).then((decorationImage) => {
|
||||
|
||||
if (award.decorationId.isMedal) {
|
||||
decorationImage.resize(medalW, medalH);
|
||||
loadedImage.composite(decorationImage, medalPx, medalPy);
|
||||
if (medalPy === 5) {
|
||||
medalPx = medalPx - 1 - medalW;
|
||||
} else {
|
||||
medalPx = medalPx + 1 + medalW;
|
||||
}
|
||||
medalPx = medalPx - 1 - medalW;
|
||||
if (medalPx <= 300) {
|
||||
medalPy = medalPy + 3 + medalH;
|
||||
medalPx = 621;
|
||||
}
|
||||
} else {
|
||||
decorationImage.resize(ribbonW, ribbonH);
|
||||
loadedImage.composite(decorationImage, ribbonPx, ribbonPy);
|
||||
ribbonPx = ribbonPx - 2 - ribbonW;
|
||||
if (ribbonPx <= 154) {
|
||||
if (ribbonPx <= 174) {
|
||||
ribbonPy = ribbonPy - 3 - ribbonH;
|
||||
ribbonPx = 598;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue