Skip to content

Commit

Permalink
Merge pull request #9 from mdingena/update-return-types
Browse files Browse the repository at this point in the history
Update return types
  • Loading branch information
mdingena authored Apr 12, 2024
2 parents 8d2b086 + f9276cb commit 308d19c
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 17 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "att-string-transcoder",
"version": "3.1.0",
"version": "3.1.1",
"description": "Trancode save strings for A Township Tale.",
"author": "Marc Dingena",
"repository": {
Expand Down
26 changes: 12 additions & 14 deletions src/Prefab.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ type PrefabHash<TPrefabName extends ATTPrefabName> = (typeof ATTPrefabs)[TPrefab

type PrefabName<TPrefabName extends ATTPrefabName> = (typeof ATTPrefabs)[TPrefabName]['name'];

type ToSaveStringOptions = {
export type ToSaveStringOptions = {
excludeComponentVersions?: boolean | undefined;
ignoreIndeterminateComponentVersions?: boolean | undefined;
};
Expand Down Expand Up @@ -295,7 +295,7 @@ export class Prefab<TPrefabName extends ATTPrefabName = ATTPrefabName> {
* // },
* // }`
*/
entities: PrefabEntities<PrefabName<TPrefabName>>;
entities: PrefabEntities<TPrefabName>;

/**
* An array of the stored child prefabs.
Expand Down Expand Up @@ -396,15 +396,15 @@ export class Prefab<TPrefabName extends ATTPrefabName = ATTPrefabName> {
*/
constructor(
prefabName: TPrefabName,
{ position, rotation, scale, components, entities, children }: PrefabProps<PrefabName<TPrefabName>> = {}
{ position, rotation, scale, components, entities, children }: PrefabProps<TPrefabName> = {}
) {
this.hash = ATTPrefabs[prefabName].hash;
this.name = prefabName;
this.position = position ?? { x: 0, y: 0, z: 0 };
this.rotation = rotation ?? { x: 0, y: 0, z: 0, w: 1 };
this.scale = scale ?? 1;
this.components = { ...components, Unknown: components?.Unknown ?? [] } as PrefabComponents;
this.entities = { ...entities } as PrefabEntities<PrefabName<TPrefabName>>;
this.entities = { ...entities } as PrefabEntities<TPrefabName>;
this.children = children ?? [];
}

Expand All @@ -424,7 +424,7 @@ export class Prefab<TPrefabName extends ATTPrefabName = ATTPrefabName> {
*
* parent.addChildPrefab('Slot_Large_SwordType_Craft_54356', child);
*/
addChildPrefab(parentKey: Exclude<EntityKey<PrefabName<TPrefabName>>, 'Unknown'> | null, childPrefab: Prefab): this {
addChildPrefab(parentKey: Exclude<EntityKey<TPrefabName>, 'Unknown'> | null, childPrefab: Prefab): this {
if (typeof parentKey === 'undefined' || typeof childPrefab === 'undefined') {
throw new Error(
'You must pass a parent prefab entity hash (or null) and a child prefab to add as a child to this prefab.'
Expand Down Expand Up @@ -578,8 +578,8 @@ export class Prefab<TPrefabName extends ATTPrefabName = ATTPrefabName> {
* const cloneMaterial = clone.getMaterial();
* // `cloneMaterial` is `56394` (Gold)
*/
clone(options: ToSaveStringOptions = {}): Prefab<PrefabName<TPrefabName>> {
return Prefab.fromSaveString<PrefabName<TPrefabName>>(this.toSaveString(options));
clone(options: ToSaveStringOptions = {}): Prefab<TPrefabName> {
return Prefab.fromSaveString<TPrefabName>(this.toSaveString(options));
}

/**
Expand All @@ -606,7 +606,7 @@ export class Prefab<TPrefabName extends ATTPrefabName = ATTPrefabName> {
static fromBinary<TPrefabName extends ATTPrefabName = ATTPrefabName>(
reader: BinaryReader,
componentVersions?: Map<number, number>
): Prefab<PrefabName<TPrefabName>> {
): Prefab<TPrefabName> {
const versions = componentVersions ?? constants.latestSupportedComponentVersions;

/**
Expand All @@ -618,9 +618,7 @@ export class Prefab<TPrefabName extends ATTPrefabName = ATTPrefabName> {

if (typeof name === 'undefined') throw new Error(`Cannot find ATT Prefab with hash ${hash}.`);

// const prefab = ATTPrefabs[name];

return new Prefab<PrefabName<TPrefabName>>(name as TPrefabName, {
return new Prefab<TPrefabName>(name as TPrefabName, {
/**
* @property {Position} position
*/
Expand Down Expand Up @@ -677,7 +675,7 @@ export class Prefab<TPrefabName extends ATTPrefabName = ATTPrefabName> {
static fromSaveString<TPrefabName extends ATTPrefabName = ATTPrefabName>(
saveString: string,
options?: BinaryDataOptions
): Prefab<PrefabName<TPrefabName>> {
): Prefab<TPrefabName> {
if (!BinaryData.isSaveString(saveString)) {
throw new Error('SaveString is malformed.');
}
Expand Down Expand Up @@ -777,14 +775,14 @@ export class Prefab<TPrefabName extends ATTPrefabName = ATTPrefabName> {
getChildPrefab<TChildPrefabName extends ATTPrefabName>(
prefabName: TChildPrefabName,
parentHash?: number
): Prefab<typeof prefabName> | undefined {
): Prefab<TChildPrefabName> | undefined {
const child = this.children.find(child =>
child.prefab.name === prefabName && typeof parentHash === 'undefined' ? true : child.parentHash === parentHash
);

if (typeof child === 'undefined') return undefined;

return child.prefab as Prefab<typeof prefabName>;
return child.prefab as Prefab<TChildPrefabName>;
}

/**
Expand Down
2 changes: 1 addition & 1 deletion src/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ export const latestSupportedComponentVersions = new Map([
[3764204299, 0], // BookPageInstance
[3801256786, 3], // BasicDecay
[3810525047, 0], // LogicValueSender`1
[3820454400, 4], // RepairBox
[3820454400, 5], // RepairBox
[3884278372, 0], // MovingLandmark
[3901697682, 1], // ButtonCounter
[3920618075, 1], // ColoredExplosive
Expand Down
2 changes: 1 addition & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/* Types */
export type { BinaryDataOptions, UnpackFloatOptions } from './BinaryData.js';
export type { EntityProps } from './Entity.js';
export type { PrefabProps } from './Prefab.js';
export type { PrefabProps, ToSaveStringOptions } from './Prefab.js';
export type { BasicDecayComponentProps } from './components/BasicDecayComponent.js';
export type { ComponentProps } from './components/Component.js';
export type { DurabilityModuleComponentProps } from './components/DurabilityModuleComponent.js';
Expand Down

0 comments on commit 308d19c

Please sign in to comment.