Skip to content

Commit

Permalink
Implement timestamp logic
Browse files Browse the repository at this point in the history
  • Loading branch information
xpdota committed Sep 30, 2024
1 parent 45cc081 commit c97d5cf
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 2 deletions.
9 changes: 9 additions & 0 deletions packages/core/src/sheet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,7 @@ export class GearPlanSheet {
// General sheet properties
_sheetName: string;
_description: string;
lastModified: Date;
readonly classJobName: JobName;
readonly level: SupportedLevel;
readonly ilvlSync: number | undefined;
Expand Down Expand Up @@ -198,6 +199,12 @@ export class GearPlanSheet {
this.classJobName = importedData.job ?? 'WHM';
this.ilvlSync = importedData.ilvlSync;
this._description = importedData.description;
if (importedData.timestamp) {
this.lastModified = new Date(importedData.timestamp);
}
else {
this.lastModified = new Date(Date.now());
}
if (importedData.itemDisplaySettings) {
Object.assign(this._itemDisplaySettings, importedData.itemDisplaySettings);
}
Expand Down Expand Up @@ -338,6 +345,7 @@ export class GearPlanSheet {
}
if (this.saveKey) {
console.log("Saving sheet " + this.sheetName);
this.lastModified = new Date(Date.now());
const fullExport = this.exportSheet(false);
localStorage.setItem(this.saveKey, JSON.stringify(fullExport));
}
Expand Down Expand Up @@ -440,6 +448,7 @@ export class GearPlanSheet {
description: this.description,
customItems: this._customItems.map(ci => ci.export()),
customFoods: this._customFoods.map(cf => cf.export()),
timestamp: this.lastModified.getTime(),
};
if (!external) {
out.saveKey = this._saveKey;
Expand Down
11 changes: 9 additions & 2 deletions packages/xivmath/src/geartypes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -593,6 +593,13 @@ export interface SimExport {
name?: string
}

/**
* Represents fields injected by the shortlink server
*/
export type ApiInjectedValues = {
timestamp?: number
}

// TODO: further split this up. API vs Local should have different types.
/**
* Represents an exported set. Many of the fields fill the same role as the fields
Expand All @@ -601,7 +608,7 @@ export interface SimExport {
* Some of the fields are only relevant for local saves, while others are only relevant
* for external (API) saves.
*/
export interface SheetExport {
export type SheetExport = ApiInjectedValues & {
/**
* Name of the sheet.
*/
Expand Down Expand Up @@ -697,7 +704,7 @@ export interface SheetStatsExport extends SheetExport {
* If it is an individual sheet export, then several of the properties that would normally live at the sheet level
* will instead be here (such as job and level).
*/
export interface SetExport {
export type SetExport = ApiInjectedValues & {
/**
* Name of the gear set.
*/
Expand Down

0 comments on commit c97d5cf

Please sign in to comment.