Skip to content

Commit

Permalink
Revert "replace lastCharCode with nextCharCode"
Browse files Browse the repository at this point in the history
This reverts commit d979a1c.
  • Loading branch information
3vorp committed Jun 18, 2024
1 parent e0191e0 commit 192a397
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 9 deletions.
2 changes: 1 addition & 1 deletion src/v2/interfaces/uses.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ export interface UseRepository {
getUsesByIdsAndEdition(idArr: number[], edition: GalleryEdition): Promise<Uses>;
getRaw(): Promise<Record<string, Use>>;
getUseByIdOrName(idOrName: string): Promise<Uses | Use>;
nextCharCode(textureID: string): Promise<number>;
lastCharCode(textureID: string): Promise<number>;
deleteUse(id: string): Promise<WriteConfirmation[]>;
set(use: Use): Promise<Use>;
setMultiple(uses: Uses): Promise<Uses>;
Expand Down
6 changes: 3 additions & 3 deletions src/v2/repository/use.repository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ export default class UseFirestormRepository implements UseRepository {
);
}

async nextCharCode(textureID: string): Promise<number> {
async lastCharCode(textureID: string): Promise<number> {
const foundUses = await uses.search([
{
field: "texture",
Expand All @@ -58,8 +58,8 @@ export default class UseFirestormRepository implements UseRepository {

if (curCode > best) return curCode;
return best;
}, // start at a and work upwards
"a".charCodeAt(0),
}, // subtract one since we're adding one later
"a".charCodeAt(0) - 1,
);
}

Expand Down
10 changes: 5 additions & 5 deletions src/v2/service/use.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,8 +75,8 @@ export default class UseService {
}

async appendUse(textureID: string, use: EntireUseToCreate): Promise<void> {
const nextCharCode = await this.repo.nextCharCode(textureID);
const nextLetter = String.fromCharCode(nextCharCode);
const lastCharCode = await this.repo.lastCharCode(textureID);
const nextLetter = String.fromCharCode(lastCharCode + 1);
const newUseID = `${textureID}${nextLetter}`;
const pathsWithUse: InputPath[] = use.paths.map((p) => ({ ...p, use: newUseID }));

Expand All @@ -92,11 +92,11 @@ export default class UseService {
}

async appendMultipleUses(textureID: string, uses: EntireUseToCreate[]): Promise<void> {
const nextCharCode = await this.repo.nextCharCode(textureID);
const lastCharCode = await this.repo.lastCharCode(textureID);
const pathsToCreate: InputPath[] = [];
const usesToCreate = uses.map((use, charOffset) => {
// get next letter for each use
const nextLetter = String.fromCharCode(nextCharCode + charOffset);
// add one to start after the previous letter
const nextLetter = String.fromCharCode(lastCharCode + 1 + charOffset);
const newUseID = `${textureID}${nextLetter}`;
// flat paths array to save requests
if (use.paths?.length) pathsToCreate.push(...use.paths.map((p) => ({ ...p, use: newUseID })));
Expand Down

0 comments on commit 192a397

Please sign in to comment.