Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- updateHistoryChanges() {
- const hisrotyAllChanges = this.getHistoryChanges();
- let sortingArray = this.getChangesAddTextures().map(changeTexture => {
- return {
- texture: changeTexture,
- groupChanges: [...(hisrotyAllChanges.filter(historyTextureChanges => {
- if (historyTextureChanges.cacheKeys && changeTexture.cacheKeys
- && historyTextureChanges.cacheKeys.find(k => changeTexture.cacheKeys.find(key => k == key))) {
- return true;
- } else if (changeTexture.mapId == _LIB.CONST.MAP_CHANGES.UPLOAD_BACKGROUND
- && !historyTextureChanges.cacheKeys) {
- return true;
- }
- return false;
- }))].map((t, index, arr) => {
- const findedHistoryByMapId = Object.entries(_LIB.CONST.MAP_CHANGES)
- .find(change => change[1] == t.mapId);
- return {
- id: t.timestamp,
- title: t.name || (findedHistoryByMapId ? findedHistoryByMapId[0] : 'Unknown'),
- ...(t.data && t.data.base64
- ? { image: t.data.base64 }
- : { icon: ["inch-filters-icon"] }),
- active: false,
- _id: t._id,
- mapId: t.mapId
- };
- }).sort((a, b) => (changeTexture.timestamp != a.id && a.id < b.id) ? -1 : 1)
- };
- }).sort((a, b) => a.texture.timestamp < b.texture.timestamp ? 1 : -1);
- const activeConfig = (sortingArray.reduce((arr, item, index) => {
- arr.push({
- max: item.groupChanges.reduce((max, value, index) => {
- if ((!max.num && max.num != 0) || max.num < value.id) {
- max = { num: value.id, index };
- }
- return max;
- }, {}),
- index: index
- });
- return arr;
- }, [])).reduce((obj, item, a, arr) => {
- console.log(arr);
- if ((!obj.num && obj.num != 0) || obj.num < item.max.num) {
- obj = {
- num: item.max.num,
- textureIndex: item.index,
- groupIndex: item.max.index
- };
- }
- return obj;
- }, {});
- if(sortingArray[activeConfig.textureIndex]) {
- sortingArray[activeConfig.textureIndex].groupChanges[activeConfig.groupIndex].active = true;
- }
- this.historyChanges = sortingArray;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement