カスタムコンポーネントのレコード&配列プロパティ
最もリクエストされていた機能の一つ、カスタムTypeScriptとJavaScriptコンポーネント用のレコードおよび配列プロパティタイプがついに登場しました。
これらを使用して出てくる素晴らしい体験を見るのが待ちきれません!
レコード
プロパティをrecord
プロパティを使ってJavaScriptクラスにグループ化できます:
1import {Component, Property} from '@wonderlandengine/api';
2
3class PlayerSettings {
4 static Properties = {
5 speed: Property.float(10.0),
6 name: Property.string('Hero')
7 };
8}
9
10export class PlayerManager extends Component {
11 static TypeName = 'player-manager';
12
13 static Properties = {
14 settings: Property.record(PlayerSettings)
15 };
16
17 start() {
18 console.log(this.settings); // Player(10.0, 'Hero')を出力
19 console.log(this.settings instanceof PlayerSettings); // true
20 }
21}

PlayerSettings
クラスを定義する際のスタイルに注意してください。プロパティはレコードやコンポーネントの場合も同じように宣言されます。
配列
array
プロパティを使用してプロパティのリストを作成することも可能になりました:
1import {Component, Property} from '@wonderlandengine/api';
2
3export class Downloader extends Component {
4 static TypeName = 'downloader';
5
6 static Properties = {
7 urls: Property.array(Property.string())
8 };
9
10 start() {
11 for(const url of this.urls) {
12 // `url`が指すファイルをダウンロードする。
13 }
14 }
15}
Property.string()
は配列要素のタイプを表します。配列は一度に単一のタイプの要素しか保持できません。
record
プロパティと組み合わせることで、複雑なタイプを実現できます:
1import {Component, Property} from '@wonderlandengine/api';
2
3class Zombie {
4 static Properties = {
5 name: Property.string(),
6 maxHealth: Property.float(100.0),
7 mesh: Property.mesh(),
8 };
9}
10
11export class ZombieSpawner extends Component {
12 static TypeName = 'zombie-spawner';
13
14 static Properties = {
15 enemies: Property.array(Property.record(Zombie))
16 };
17
18 start() {
19 for(const zombie of this.enemies) {
20 const name = zombie.name;
21 const health = zombie.maxHealth;
22 // 恐ろしいゾンビをスポーンさせよう!
23 }
24 }
25}

APIではネストされた配列プロパティ(配列の配列)もサポートしています:
1import {Component, Property} from '@wonderlandengine/api';
2
3export class LevelGenerator extends Component {
4 static TypeName = 'level-generator';
5
6 static Properties = {
7 mapPiecesPerLevel: Property.array(Property.array(Property.string())),
8 };
9
10 start() {
11 // 次のようなものを出力します:
12 // [
13 // ['level_1_forest.map', 'level_1_mountains.map'],
14 // ['level_2_beach.map', 'level_2_ocean.map', 'level_2_desert.map'],
15 // ['level_3_underwater.map'],
16 // ]
17 console.log(this.mapPiecesPerLevel);
18 }
19}
TypeScript
TypeScriptユーザーにとって、新しいrecord
およびarray
プロパティデコレータにより、複雑なコンポーネントプロパティの宣言が非常にコンパクトで直感的になりました:
1import {Component, property, Property} from '@wonderlandengine/api';
2
3class Zombie {
4 @property.string()
5 name!: string;
6
7 @property.float(100)
8 maxHealth!: number;
9
10 @property.float(10)
11 damage!: number;
12}
13
14export class ZombieManager extends Component {
15 static TypeName = 'zombie-manager';
16
17 @property.array(Property.record(Zombie))
18 zombies!: Zombie[];
19}
Last Update: May 12, 2025