Skip to content

Commit daf0cc3

Browse files
authored
Merge pull request #188 from spg-stany/shared-stash
load constants from d2s lib
2 parents e7aa19f + 4565bb3 commit daf0cc3

File tree

6 files changed

+46
-45
lines changed

6 files changed

+46
-45
lines changed

public/d2/constants_96.bundle.min.js

Lines changed: 0 additions & 1 deletion
This file was deleted.

public/d2/constants_99.bundle.min.js

Lines changed: 0 additions & 1 deletion
This file was deleted.

public/index.html

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,11 @@
2929
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/select2.min.js"></script>
3030

3131

32+
<!--
3233
<script src="./d2/constants_96.bundle.min.js"></script>
3334
<script src="./d2/constants_99.bundle.min.js"></script>
34-
<script src="https://github.com/dschu012/d2s/releases/latest/download/d2s.bundle.min.js"></script>
35+
<script src="https://github.com/dschu012/d2s/releases/latest/download/d2s.bundle.min.js"></script>
36+
-->
3537

3638
<div id="app"></div>
3739
</body>

src/components/App.vue

Lines changed: 26 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -383,6 +383,8 @@
383383
384384
import * as d2s from '@dschu012/d2s';
385385
import * as d2stash from '@dschu012/d2s/lib/d2/stash';
386+
import { constants as constants96 } from '@dschu012/d2s/lib/data/versions/96_constant_data';
387+
import { constants as constants99 } from '@dschu012/d2s/lib/data/versions/99_constant_data';
386388
387389
export default {
388390
components: {
@@ -438,15 +440,14 @@
438440
this.grid = JSON.parse(localStorage.getItem('grid'));
439441
}
440442
443+
d2s.setConstantData(96, constants96);
444+
d2s.setConstantData(97, constants96);
445+
d2s.setConstantData(98, constants96);
446+
d2s.setConstantData(99, constants99);
441447
442-
d2s.setConstantData(96, window.constants_96.constants);
443-
d2s.setConstantData(97, window.constants_96.constants);
444-
d2s.setConstantData(98, window.constants_96.constants);
445-
d2s.setConstantData(99, window.constants_99.constants);
446-
447-
window.constants = window.constants_99;
448-
this.addItemsPackBases(window.constants_99.constants.weapon_items, "Weapons");
449-
this.addItemsPackBases(window.constants_99.constants.armor_items, "Armor");
448+
window.constants = constants99;
449+
this.addItemsPackBases(window.constants.weapon_items, "Weapons");
450+
this.addItemsPackBases(window.constants.armor_items, "Armor");
450451
},
451452
filters: {
452453
},
@@ -578,7 +579,7 @@
578579
this.clipboard = JSON.parse(JSON.stringify(e.item));
579580
navigator.clipboard.writeText(JSON.stringify(e.item));
580581
} else if(e.type == 'update') {
581-
d2s.enhanceItems([e.item], window.constants.constants);
582+
d2s.enhanceItems([e.item], window.constants);
582583
this.setPropertiesOnItem(e.item);
583584
} else if(e.type == 'delete') {
584585
let idx = this.findIndex(this.save.items, e.item);
@@ -795,35 +796,35 @@
795796
this.readBuffer(event.target.result, event.target.filename);
796797
},
797798
readBuffer(bytes, filename) {
798-
let that = this;
799+
//console.log(filename);
800+
//let that = this;
799801
this.save = null;
800802
this.selected = null;
801803
//this.stashData = null;
802804
803805
if (filename) {
804806
if (filename.includes(".d2s")) {
805807
d2s.read(bytes).then(response => {
806-
that.save = response;
807-
that.save.header.name = filename.split('.')[0];
808-
that.setPropertiesOnSave();
808+
this.save = response;
809+
this.save.header.name = filename.split('.')[0];
810+
this.setPropertiesOnSave();
809811
});
810-
}
811-
else if (filename.includes("SharedStash")) {
812-
that.stashData = null;
812+
} else if (filename.includes("SharedStash")) {
813+
this.stashData = null;
813814
d2stash.read(bytes).then(response => {
814-
that.stashData = response;
815-
for (var i = 0; i < that.stashData.pageCount; i++) {
816-
[... that.stashData.pages[i].items].forEach(item => {
817-
that.setPropertiesOnItem(item);
815+
this.stashData = response;
816+
for (var i = 0; i < this.stashData.pageCount; i++) {
817+
[... this.stashData.pages[i].items].forEach(item => {
818+
this.setPropertiesOnItem(item);
818819
});
819820
}
820821
});
821822
}
822823
} else {
823-
that.stashData = null;
824+
this.stashData = null;
824825
d2s.read(bytes).then(response => {
825-
that.save = response;
826-
that.setPropertiesOnSave();
826+
this.save = response;
827+
this.setPropertiesOnSave();
827828
});
828829
}
829830
@@ -972,9 +973,9 @@
972973
newItems.push(newItem);
973974
}
974975
}
975-
d2s.enhanceItems(newItems, window.constants.constants);
976+
d2s.enhanceItems(newItems, window.constants);
976977
for (const item of newItems) {
977-
let bytes = await d2s.writeItem(item, 0x63, window.constants.constants);
978+
let bytes = await d2s.writeItem(item, 0x63, window.constants);
978979
let base64 = utils.arrayBufferToBase64(bytes);
979980
let category = item.categories[0];
980981
this.itempack.push({

src/components/Stats.vue

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@
134134
},
135135
data() {
136136
return {
137-
stats: window.constants.constants.magical_properties,
137+
stats: window.constants.magical_properties,
138138
}
139139
},
140140
watch: {
@@ -145,8 +145,8 @@
145145
const newLevel = level - s;
146146
this.save.attributes.unused_stats = (this.save.attributes.unused_stats ?? 0) + (newLevel * 5);
147147
this.save.attributes.unused_skill_points = (this.save.attributes.unused_skill_points ?? 0) + newLevel;
148-
for(const cCode in constants.constants.classes) {
149-
const stat = constants.constants.classes[cCode];
148+
for(const cCode in window.constants.classes) {
149+
const stat = window.constants.classes[cCode];
150150
if(stat.n === this.save.header.class) {
151151
this.save.attributes.max_hp += newLevel * stat.s.lpl / 4;
152152
this.save.attributes.current_hp += newLevel * stat.s.lpl / 4;
@@ -162,8 +162,8 @@
162162
},
163163
"save.attributes.vitality": function(val, old) {
164164
const change = val-old;
165-
for (const cCode in window.constants.constants.classes) {
166-
const stat = window.constants.constants.classes[cCode];
165+
for (const cCode in window.constants.classes) {
166+
const stat = window.constants.classes[cCode];
167167
if (window.stat.n === this.save.header.class) {
168168
this.save.attributes.max_hp += change * stat.s.lpv / 4;
169169
this.save.attributes.current_hp += change * stat.s.lpv / 4;
@@ -176,8 +176,8 @@
176176
},
177177
"save.attributes.energy": function(val, old) {
178178
const change = val-old;
179-
for (const cCode in window.constants.constants.classes) {
180-
const stat = window.constants.constants.classes[cCode];
179+
for (const cCode in window.constants.classes) {
180+
const stat = window.constants.classes[cCode];
181181
if (window.stat.n === this.save.header.class) {
182182
this.save.attributes.max_mana += change * stat.s.mpe / 4;
183183
this.save.attributes.current_mana += change * stat.s.mpe / 4;

src/components/inventory/ItemEditor.vue

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -152,14 +152,14 @@ export default {
152152
locations: [{ key: 0, value: 'Stored' }, { key: 1, value: 'Equipped' }, { key: 4, value: 'Cursor' }],
153153
equipped_locations: [{ key: 1, value: 'Head' }, { key: 2, value: 'Neck' }, { key: 3, value: 'Torso' }, { key: 4, value: 'Right Hand' }, { key: 5, value: 'Left Hand' }, { key: 6, value: 'Right Finger' }, { key: 7, value: 'Left Finger' }, { key: 8, value: 'Waist' }, { key: 9, value: 'Boots' }, { key: 10, value: 'Gloves' }, { key: 11, value: 'Alternate Right Hand' }, { key: 12, value: 'Alternate Left Hand' }],
154154
storage_pages: [{ key: 1, value: 'Inventory' }, { key: 4, value: 'Cube' }, { key: 5, value: 'Stash' }],
155-
prefixes: window.constants.constants.magic_prefixes.map((e,i)=> { return { i:i, v:e }}).filter(e => e.v != null && e.v.n != null),
156-
suffixes: window.constants.constants.magic_suffixes.map((e,i)=> { return { i:i, v:e }}).filter(e => e.v != null && e.v.n != null),
157-
rare_names: window.constants.constants.rare_names.map((e,i)=> { return { i:i, v:e }}).filter(e => e.v != null && e.v.n != null),
158-
unq_items: window.constants.constants.unq_items.map((e,i)=> { return { i:i, v:e }}).filter(e => e.v != null && e.v.n != null),
159-
set_items: window.constants.constants.set_items.map((e,i)=> { return { i:i, v:e }}).filter(e => e.v != null && e.v.n != null),
160-
armor_items: Object.entries(window.constants.constants.armor_items).filter(e => e[1].n != null),
161-
weapon_items: Object.entries(window.constants.constants.weapon_items).filter(e => e[1].n != null),
162-
other_items: Object.entries(window.constants.constants.other_items).filter(e => e[1].n != null),
155+
prefixes: window.constants.magic_prefixes.map((e,i)=> { return { i:i, v:e }}).filter(e => e.v != null && e.v.n != null),
156+
suffixes: window.constants.magic_suffixes.map((e,i)=> { return { i:i, v:e }}).filter(e => e.v != null && e.v.n != null),
157+
rare_names: window.constants.rare_names.map((e,i)=> { return { i:i, v:e }}).filter(e => e.v != null && e.v.n != null),
158+
unq_items: window.constants.unq_items.map((e,i)=> { return { i:i, v:e }}).filter(e => e.v != null && e.v.n != null),
159+
set_items: window.constants.set_items.map((e,i)=> { return { i:i, v:e }}).filter(e => e.v != null && e.v.n != null),
160+
armor_items: Object.entries(window.constants.armor_items).filter(e => e[1].n != null),
161+
weapon_items: Object.entries(window.constants.weapon_items).filter(e => e[1].n != null),
162+
other_items: Object.entries(window.constants.other_items).filter(e => e[1].n != null),
163163
};
164164
},
165165
methods: {
@@ -194,9 +194,9 @@ export default {
194194
},
195195
getBases(code) {
196196
if (this.item.type_id == 3) {
197-
return this.findBasesInConstants(code, window.constants.constants.weapon_items);
197+
return this.findBasesInConstants(code, window.constants.weapon_items);
198198
} else if (this.item.type_id == 1) {
199-
return this.findBasesInConstants(code, window.constants.constants.armor_items);
199+
return this.findBasesInConstants(code, window.constants.armor_items);
200200
} else if (this.item.type_id == 4) {
201201
return this.other_items
202202
} else {

0 commit comments

Comments
 (0)