NMV 0.8.0 - Big refactor and linting fixes

This commit is contained in:
Casper Warden
2025-01-17 23:37:54 +00:00
parent 3870861b0a
commit 53659008ac
210 changed files with 17588 additions and 18300 deletions

View File

@@ -1,96 +1,132 @@
import { InventoryItem } from './InventoryItem';
import { Material } from './public/Material';
import { UUID } from './UUID';
import type { InventoryItem } from './InventoryItem';
import type { AssetType } from '../enums/AssetType';
export class AssetMap
export interface AssetData<T = InventoryItem>
{
mesh: {
[key: string]: {
name: string,
description: string,
item: InventoryItem | null
}
} = {};
textures: {
[key: string]: {
name?: string,
description?: string,
item: InventoryItem | null
}
} = {};
materials: {
[key: string]: Material | null
} = {};
animations: {
[key: string]: {
name?: string,
description?: string,
item: InventoryItem | null
}
} = {};
sounds: {
[key: string]: {
name?: string,
description?: string,
item: InventoryItem | null
}
} = {};
gestures: {
[key: string]: {
name?: string,
description?: string,
item: InventoryItem | null
}
} = {};
callingcards: {
[key: string]: {
name?: string,
description?: string,
item: InventoryItem | null
}
} = {};
scripts: {
[key: string]: {
name?: string,
description?: string,
item: InventoryItem | null
}
} = {};
clothing: {
[key: string]: {
name?: string,
description?: string,
item: InventoryItem | null
}
} = {};
settings: {
[key: string]: {
name?: string,
description?: string,
item: InventoryItem | null
}
} = {};
notecards: {
[key: string]: {
name?: string,
description?: string,
item: InventoryItem | null
}
} = {};
bodyparts: {
[key: string]: {
name?: string,
description?: string,
item: InventoryItem | null
}
} = {};
objects: {
[key: string]: InventoryItem | null
} = {};
temporaryInventory: {
[key: string]: InventoryItem
} = {};
byUUID: {
[key: string]: InventoryItem
} = {};
pending: { [key: string]: boolean } = {};
name?: string;
description?: string;
assetType?: AssetType;
item?: T
}
export class AssetMap<T = InventoryItem>
{
private readonly map = new Map<string, AssetData<T>>();
private readonly pending = new Map<string, number>();
public get(uuid: UUID | string): AssetData<T> | undefined
{
if (uuid instanceof UUID)
{
uuid = uuid.toString();
}
return this.map.get(uuid);
}
public request(uuid: UUID | string, metadata?: AssetData<T>): void
{
if (uuid instanceof UUID)
{
uuid = uuid.toString();
}
const mapItem = this.map.get(uuid);
if (mapItem === undefined)
{
if (metadata === undefined)
{
metadata = {};
}
this.map.set(uuid, metadata);
}
let pending = this.pending.get(uuid);
if (pending === undefined)
{
pending = 0;
}
this.pending.set(uuid, ++pending);
}
public delete(uuid: UUID | string): void
{
if (uuid instanceof UUID)
{
uuid = uuid.toString();
}
this.map.delete(uuid);
this.pending.delete(uuid);
}
public getFetchList(): string[]
{
const list: string[] = [];
for(const k of this.map.keys())
{
let p = this.pending.get(k);
if (p === undefined)
{
continue;
}
if (p > 0)
{
const data = this.map.get(k);
if (data === undefined)
{
continue;
}
if (data.item === undefined)
{
this.pending.set(k, --p);
list.push(k);
}
}
}
return list;
}
public setItem(uuid: UUID | string, item: T): void
{
if (uuid instanceof UUID)
{
uuid = uuid.toString();
}
let entry = this.map.get(uuid);
if (entry === undefined)
{
entry = {
item: item
};
}
else
{
entry.item = item;
}
this.map.set(uuid, entry);
}
public doneFetch(list: string[]): void
{
for(const item of list)
{
const i = this.map.get(item);
if (i === undefined)
{
continue;
}
if (i.item === undefined)
{
let pending = this.pending.get(item)
if (pending === undefined)
{
pending = 0;
}
this.pending.set(item, ++pending);
}
else
{
this.pending.delete(item);
}
}
}
}