mirror of
https://github.com/EDCD/coriolis.git
synced 2025-12-10 07:05:35 +00:00
Fixes for serialization
This commit is contained in:
@@ -33,6 +33,15 @@ export default class ModificationsMenu extends TranslatedComponent {
|
|||||||
*/
|
*/
|
||||||
_updateValue(value) {
|
_updateValue(value) {
|
||||||
let scaledValue = Math.floor(Number(value) * 100) / 10000;
|
let scaledValue = Math.floor(Number(value) * 100) / 10000;
|
||||||
|
// Limit to +1000% / -100%
|
||||||
|
if (scaledValue > 10) {
|
||||||
|
scaledValue = 10;
|
||||||
|
value = 1000;
|
||||||
|
}
|
||||||
|
if (scaledValue < -1) {
|
||||||
|
scaledValue = -1;
|
||||||
|
value = -100;
|
||||||
|
}
|
||||||
let m = this.props.m;
|
let m = this.props.m;
|
||||||
let name = this.props.name;
|
let name = this.props.name;
|
||||||
let ship = this.props.ship;
|
let ship = this.props.ship;
|
||||||
|
|||||||
@@ -24,7 +24,7 @@ function standardToSchema(standard) {
|
|||||||
o.name = standard.m.name;
|
o.name = standard.m.name;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (standard.m.mods && standard.m.mods != {}) {
|
if (standard.m.mods && Object.keys(standard.m.mods).length > 0) {
|
||||||
o.modifications = standard.m.mods;
|
o.modifications = standard.m.mods;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -57,7 +57,7 @@ function slotToSchema(slot) {
|
|||||||
if (slot.m.missile) {
|
if (slot.m.missile) {
|
||||||
o.missile = slot.m.missile;
|
o.missile = slot.m.missile;
|
||||||
}
|
}
|
||||||
if (slot.m.mods && slot.m.mods != {}) {
|
if (slot.m.mods && Object.keys(slot.m.mods).length > 0) {
|
||||||
o.modifications = slot.m.mods;
|
o.modifications = slot.m.mods;
|
||||||
}
|
}
|
||||||
return o;
|
return o;
|
||||||
@@ -115,12 +115,27 @@ export function toDetailedBuild(buildName, ship) {
|
|||||||
return data;
|
return data;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
export function fromDetailedBuild(detailedBuild) {
|
||||||
|
let shipId = Object.keys(Ships).find((shipId) => Ships[shipId].properties.name.toLowerCase() == detailedBuild.ship.toLowerCase());
|
||||||
|
|
||||||
|
if (!shipId) {
|
||||||
|
throw 'No such ship: ' + detailedBuild.ship;
|
||||||
|
}
|
||||||
|
|
||||||
|
let comps = detailedBuild.components;
|
||||||
|
let stn = comps.standard;
|
||||||
|
let shipData = Ships[shipId];
|
||||||
|
let ship = new Ship(shipId, shipData.properties, shipData.slots);
|
||||||
|
|
||||||
|
return ship.buildFrom(detailedBuild.references[0].code);
|
||||||
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Instantiates a ship from a ship-loadout object
|
* Instantiates a ship from a ship-loadout object
|
||||||
* @param {Object} detailedBuild ship-loadout object
|
* @param {Object} detailedBuild ship-loadout object
|
||||||
* @return {Ship} Ship instance
|
* @return {Ship} Ship instance
|
||||||
*/
|
*/
|
||||||
export function fromDetailedBuild(detailedBuild) {
|
export function oldfromDetailedBuild(detailedBuild) {
|
||||||
let shipId = Object.keys(Ships).find((shipId) => Ships[shipId].properties.name.toLowerCase() == detailedBuild.ship.toLowerCase());
|
let shipId = Object.keys(Ships).find((shipId) => Ships[shipId].properties.name.toLowerCase() == detailedBuild.ship.toLowerCase());
|
||||||
|
|
||||||
if (!shipId) {
|
if (!shipId) {
|
||||||
|
|||||||
@@ -1116,7 +1116,7 @@ export default class Ship {
|
|||||||
let bufsize = 0;
|
let bufsize = 0;
|
||||||
for (let slot of slots) {
|
for (let slot of slots) {
|
||||||
if (slot.length > 0) {
|
if (slot.length > 0) {
|
||||||
bufsize = bufsize + 1 + (3 * slot.length) + 1; //
|
bufsize = bufsize + 1 + (5 * slot.length) + 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1131,8 +1131,8 @@ export default class Ship {
|
|||||||
buffer.writeInt8(i, curpos++);
|
buffer.writeInt8(i, curpos++);
|
||||||
for (let slotMod of slot) {
|
for (let slotMod of slot) {
|
||||||
buffer.writeInt8(slotMod.id, curpos++);
|
buffer.writeInt8(slotMod.id, curpos++);
|
||||||
buffer.writeInt16BE(slotMod.value, curpos);
|
buffer.writeInt32LE(slotMod.value, curpos);
|
||||||
curpos += 2;
|
curpos += 4;
|
||||||
}
|
}
|
||||||
buffer.writeInt8(-1, curpos++);
|
buffer.writeInt8(-1, curpos++);
|
||||||
}
|
}
|
||||||
@@ -1157,18 +1157,18 @@ export default class Ship {
|
|||||||
*/
|
*/
|
||||||
decodeModificationsStruct(buffer, arr) {
|
decodeModificationsStruct(buffer, arr) {
|
||||||
let curpos = 0;
|
let curpos = 0;
|
||||||
let module = buffer.readInt8(curpos++);
|
let slot = buffer.readInt8(curpos++);
|
||||||
while (module != -1) {
|
while (slot != -1) {
|
||||||
let modifications = {};
|
let modifications = {};
|
||||||
let modificationId = buffer.readInt8(curpos++);
|
let modificationId = buffer.readInt8(curpos++);
|
||||||
while (modificationId != -1) {
|
while (modificationId != -1) {
|
||||||
let modificationValue = buffer.readInt16BE(curpos);
|
let modificationValue = buffer.readInt32LE(curpos);
|
||||||
curpos += 2;
|
curpos += 4;
|
||||||
modifications[Modifications.modifiers[modificationId]] = modificationValue;
|
modifications[Modifications.modifiers[modificationId]] = modificationValue;
|
||||||
modificationId = buffer.readInt8(curpos++);
|
modificationId = buffer.readInt8(curpos++);
|
||||||
}
|
}
|
||||||
arr[module] = modifications;
|
arr[slot] = modifications;
|
||||||
module = buffer.readInt8(curpos++);
|
slot = buffer.readInt8(curpos++);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user