Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
151 changes: 149 additions & 2 deletions docs/documentation.md
Original file line number Diff line number Diff line change
Expand Up @@ -349,6 +349,7 @@ export function onCommand(
    [function Room.listenCharEvent](#function-room-listencharevent)
    [function Room.listenExit](#function-room-listenexit)
    [function Room.privateDescribe](#function-room-privatedescribe)
    [function Room.profileIterator](#function-room-profileiterator)
    [function Room.removeCommand](#function-room-removecommand)
    [function Room.setExit](#function-room-setexit)
    [function Room.setRoom](#function-room-setroom)
Expand All @@ -375,6 +376,14 @@ export function onCommand(
        [method close](#method-room-exititerator-close)
        [method getExit](#method-room-exititerator-getexit)
    [class Room.MoveMsgs](#class-room-movemsgs)
    [class Room.Profile](#class-room-profile)
    [class Room.ProfileIterator](#class-room-profileiterator)
        [method next](#method-room-profileiterator-next)
        [method rewind](#method-room-profileiterator-rewind)
        [method getID](#method-room-profileiterator-getid)
        [method isValid](#method-room-profileiterator-isvalid)
        [method close](#method-room-profileiterator-close)
        [method getProfile](#method-room-profileiterator-getprofile)
    [class Room.RoomDetails](#class-room-roomdetails)

<h3 id="namespace-script">Script namespace</h3>
Expand Down Expand Up @@ -2629,6 +2638,21 @@ targeted characters.
* `targetCharIds` <i>(Array&lt;[ID](#type-id)&gt;)</i>


---

<h3 id="function-room-profileiterator">function Room.profileIterator</h3>

```ts
Room.profileIterator(): ProfileIterator
```

Gets an iterator for the profiles for the room. Order is undefined.

<h4>Returns</h4>

* <i>([Room.ProfileIterator](#class-room-profileiterator))</i>


---

<h3 id="function-room-removecommand">function Room.removeCommand</h3>
Expand Down Expand Up @@ -2840,7 +2864,7 @@ Room character.

<h4 id="class-room-char-properties">class Room.Char properties</h4>

* `id` <i>(string)</i>: Character ID.
* `id` <i>([ID](#type-id))</i>: Character ID.
* `name` <i>(string)</i>: Character name.
* `surname` <i>(string)</i>: Character surname.
* `avatar` <i>([ID](#type-id))</i>: Character avatar.
Expand Down Expand Up @@ -2969,7 +2993,7 @@ Room exit.

<h4 id="class-room-exit-properties">class Room.Exit properties</h4>

* `id` <i>(string)</i>: Exit ID.
* `id` <i>([ID](#type-id))</i>: Exit ID.
* `keys` <i>(Array&lt;string&gt;)</i>: Exit keys.
* `name` <i>(string)</i>: Exit name.
* `icon` <i>([ExitIcon](#enum-exiticon))</i>: Exit icon.
Expand Down Expand Up @@ -3105,6 +3129,129 @@ Move messages used when entering or leaving a room.
* `travelMsg` <i>(string)</i>


---

<h3 id="class-room-profile">class Room.Profile</h3>

Room profile.

<h4 id="class-room-profile-properties">class Room.Profile properties</h4>

* `id` <i>([ID](#type-id))</i>: Profile ID.
* `name` <i>(string)</i>: Profile name.
* `key` <i>(string)</i>: Profile key.
* `desc` <i>(string)</i>: Profile desc.
* `image` <i>([ID](#type-id))</i>: Profile image.


---

<h3 id="class-room-profileiterator">class Room.ProfileIterator</h3>



```ts
new Room.ProfileIterator(iterator: i32)
```

Constructor of the Iterator instance.

<h4>Parameters</h4>

* `iterator` <i>(i32)</i>


<h4 id="class-room-profileiterator-properties">class Room.ProfileIterator properties</h4>

* `iterator` <i>(i32)</i>


---

<h3 id="method-room-profileiterator-next">method Room.ProfileIterator.next</h3>

```ts
next(): void
```

Advances the iterator by one. Always check isValid() after a next()
to ensure have not reached the end of the iterator.


---

<h3 id="method-room-profileiterator-rewind">method Room.ProfileIterator.rewind</h3>

```ts
rewind(): void
```

Rewinds the iterator cursor all the way back to first position, which
would be the smallest key, or greatest key if inReverse() was called.

Any iterator prefix passed to withPrefix() will be used on rewind.
The iterator is rewound by default.


---

<h3 id="method-room-profileiterator-getid">method Room.ProfileIterator.getID</h3>

```ts
getID(): ID
```

Returns the key string of the current key-value pair. It will abort
if the cursor has reached the end of the iterator.

<h4>Returns</h4>

* <i>([ID](#type-id))</i>


---

<h3 id="method-room-profileiterator-isvalid">method Room.ProfileIterator.isValid</h3>

```ts
isValid(): boolean
```

Returns false when the cursor is at the end of the iterator.

<h4>Returns</h4>

* <i>(boolean)</i>


---

<h3 id="method-room-profileiterator-close">method Room.ProfileIterator.close</h3>

```ts
close(): void
```

Closes the iterator. Any further calls to the iterator will cause an
error. May be called multiple times.


---

<h3 id="method-room-profileiterator-getprofile">method Room.ProfileIterator.getProfile</h3>

```ts
getProfile(): Profile
```

Returns the current profile. It will abort if the cursor has reached the
end of the iterator.

<h4>Returns</h4>

* <i>([Room.Profile](#class-room-profile))</i>


---

<h3 id="class-room-roomdetails">class Room.RoomDetails</h3>
Expand Down
3 changes: 3 additions & 0 deletions lib/env.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,9 @@ export declare namespace Room {

@external("env", "room.removeCommand")
export function removeCommand(key: string): boolean

@external("env", "room.profileIterator")
export function profileIterator(): i32
}

export declare namespace Script {
Expand Down
39 changes: 37 additions & 2 deletions lib/host.ts
Original file line number Diff line number Diff line change
Expand Up @@ -932,7 +932,7 @@ export namespace Room {
@json
export class Char {
/** Character ID. */
id: string = "";
id: ID = "";
/** Character name. */
name: string = "";
/** Character surname. */
Expand Down Expand Up @@ -961,7 +961,7 @@ export namespace Room {
@json
export class Exit {
/** Exit ID. */
id: string = "";
id: ID = "";
/** Exit keys. */
keys: string[] = [];
/** Exit name. */
Expand All @@ -988,6 +988,23 @@ export namespace Room {
transparent: boolean = false;
}

/**
* Room profile.
*/
@json
export class Profile {
/** Profile ID. */
id: ID = "";
/** Profile name. */
name: string = "";
/** Profile key. */
key: string = "";
/** Profile desc. */
desc: string = "";
/** Profile image. */
image: ID = "";
}

/**
* Starts listening to room events on the current instance. If `instance` is
* set, it starts listening for events in that specific instance, or null
Expand Down Expand Up @@ -1169,6 +1186,13 @@ export namespace Room {
return new ExitIterator(room_binding.exitIterator());
}

/**
* Gets an iterator for the profiles for the room. Order is undefined.
*/
export function profileIterator(): ProfileIterator {
return new ProfileIterator(room_binding.profileIterator());
}

/**
* Gets a character in the room by ID.
* @param charId - Character ID.
Expand Down Expand Up @@ -1299,6 +1323,17 @@ export namespace Room {
return JSON.parse<Exit>(String.UTF8.decode(iterator_binding.value(super.iterator)));
}
}

export class ProfileIterator extends BaseIterator {
/**
* Returns the current profile. It will abort if the cursor has reached the
* end of the iterator.
*/
getProfile(): Profile {
// @ts-expect-error
return JSON.parse<Profile>(String.UTF8.decode(iterator_binding.value(super.iterator)));
}
}
}

/**
Expand Down
30 changes: 28 additions & 2 deletions lib/types/host/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -620,7 +620,7 @@ declare namespace Room {
*/
class Char {
/** Character ID. */
id: string;
id: ID;
/** Character name. */
name: string;
/** Character surname. */
Expand All @@ -647,7 +647,7 @@ declare namespace Room {
*/
class Exit {
/** Exit ID. */
id: string;
id: ID;
/** Exit keys. */
keys: string[];
/** Exit name. */
Expand All @@ -673,6 +673,21 @@ declare namespace Room {
/** Is transparent flag. */
transparent: boolean;
}
/**
* Room profile.
*/
class Profile {
/** Profile ID. */
id: ID;
/** Profile name. */
name: string;
/** Profile key. */
key: string;
/** Profile desc. */
desc: string;
/** Profile image. */
image: ID;
}
/**
* Starts listening to room events on the current instance. If `instance` is
* set, it starts listening for events in that specific instance, or null
Expand Down Expand Up @@ -806,6 +821,10 @@ declare namespace Room {
* Gets an iterator for the exits in the room. Order is undefined.
*/
function exitIterator(): ExitIterator;
/**
* Gets an iterator for the profiles for the room. Order is undefined.
*/
function profileIterator(): ProfileIterator;
/**
* Gets a character in the room by ID.
* @param charId - Character ID.
Expand Down Expand Up @@ -895,6 +914,13 @@ declare namespace Room {
*/
getExit(): Exit;
}
class ProfileIterator extends BaseIterator {
/**
* Returns the current profile. It will abort if the cursor has reached the
* end of the iterator.
*/
getProfile(): Profile;
}
}
/**
* Script API functions.
Expand Down