Skip to content

Commit

Permalink
Properly create uids for new items (Closes #5).
Browse files Browse the repository at this point in the history
  • Loading branch information
crunchyintheory committed Nov 30, 2024
1 parent 537876c commit 5d6eccf
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 7 deletions.
6 changes: 3 additions & 3 deletions src/app/item-service.service.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Injectable } from '@angular/core';
import { Item } from './item';
import { Item, StashedItem } from './item';
import { HttpClient } from '@angular/common/http';
import { Templates } from './templates';
import { Property, PropertyType } from './property';
Expand All @@ -15,7 +15,7 @@ export class ItemService {

constructor(private http: HttpClient) {
let item = Array.from(Templates.values())[Math.floor(Math.random() * Templates.size)];
this.item = item;
this.item = StashedItem.From(item);
this.defaultMaxWidth = item.width;
}

Expand All @@ -27,7 +27,7 @@ export class ItemService {
// My desperate plea for a proper deep copy method in this accursed language.
let template = Templates.get('Tabula Rasa, Simple Robe')!;
let item = ItemService.DeepCopy(template);
this.item = item;
this.item = StashedItem.From(item, true);

if (this.item.properties.length == 0 && Math.random() > 0.9) {
this.item.properties = [{
Expand Down
4 changes: 2 additions & 2 deletions src/app/item.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,9 +76,9 @@ export class Item {
export class StashedItem extends Item {
public uid?: string;

public static From(item: Item): StashedItem {
public static From(item: Item, forceRegenerate = false): StashedItem {
let i = item as StashedItem;
if(!i.uid) i.uid = crypto.randomUUID();
if(!i.uid || forceRegenerate) i.uid = crypto.randomUUID();
return i;
}
}
4 changes: 2 additions & 2 deletions src/app/stash.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,12 +83,12 @@ export class StashService {
type: AlertType.ModalConfirm,
status: AlertStatus.Warning,
title: "Confirm Overwrite",
text: `Would you like to overwrite the existing item ${existing.name} in your stash, or save into a new slot?`,
text: `Would you like to overwrite the existing item ${existing.name} ${existing.base} in your stash, or save into a new slot?`,
lifetime: 1000,
button1: "Overwrite",
button2: "Save as a Copy",
confirmCallback: async () => await this.replaceInStash(stash, i, existingIndex, autosave),
cancelCallback: async () => await this.finalizeStashAdd(stash, i, autosave)
cancelCallback: async () => await this.finalizeStashAdd(stash, StashedItem.From(item, true), autosave)
}));
}
else {
Expand Down

0 comments on commit 5d6eccf

Please sign in to comment.