arx-level-generator
Version:
A tool for creating Arx Fatalis maps
96 lines • 3.21 kB
JavaScript
import { ArxZoneAndPathPointType } from 'arx-convert/types';
import { Ambience } from './Ambience.js';
import { Color } from './Color.js';
import { Vector3 } from './Vector3.js';
import { Vectors } from './Vectors.js';
export class Zone {
name;
height;
points;
backgroundColor;
drawDistance;
ambience;
hasBackgroundColor() {
return typeof this.backgroundColor !== 'undefined';
}
hasAmbience() {
return typeof this.ambience !== 'undefined';
}
constructor(props) {
this.name = props.name;
this.height = props.height ?? Infinity;
this.backgroundColor = props.backgroundColor;
this.drawDistance = props.drawDistance;
this.ambience = props.ambience;
this.points = props.points;
}
clone() {
return new Zone({
name: this.name,
height: this.height,
backgroundColor: this.backgroundColor?.clone(),
drawDistance: this.drawDistance,
ambience: this.ambience?.clone(),
points: this.points.map((point) => {
return {
position: point.position.clone(),
type: point.type,
time: point.time,
};
}),
});
}
static fromArxZone(zone) {
return new Zone({
name: zone.name,
height: zone.height === -1 ? Infinity : zone.height,
backgroundColor: typeof zone.backgroundColor !== 'undefined' ? Color.fromArxColor(zone.backgroundColor) : undefined,
drawDistance: zone.drawDistance,
ambience: typeof zone.ambience !== 'undefined' && typeof zone.ambienceMaxVolume !== 'undefined'
? new Ambience({ name: zone.ambience, volume: zone.ambienceMaxVolume })
: undefined,
points: zone.points.map((point) => {
return {
position: Vector3.fromArxVector3(point.pos),
type: point.type,
time: point.time,
};
}),
});
}
static fromThreejsGeometry(obj, props) {
return new Zone({
...props,
points: Vectors.fromThreejsGeometry(obj)
.uniq()
.map((position) => ({
position,
type: ArxZoneAndPathPointType.Standard,
time: 0,
})),
});
}
toArxZone() {
return {
name: this.name,
backgroundColor: this.backgroundColor?.toArxColor(),
drawDistance: this.drawDistance,
height: this.height === Infinity ? -1 : this.height,
ambience: this.ambience?.name,
ambienceMaxVolume: this.ambience?.volume,
points: this.points.map((point) => {
return {
pos: point.position.toArxVector3(),
type: point.type,
time: point.time,
};
}),
};
}
move(offset) {
this.points.forEach((point) => {
point.position.add(offset);
});
}
}
//# sourceMappingURL=Zone.js.map