placeObject2 method
void
placeObject2({})
PlaceObject2(タグ26)。指定depthにキャラクターを配置または既存インスタンスを更新する。
characterIdを渡すとPlaceFlagHasCharacter(0x02)を立てUI16のcharacterIdを書き込み、
キャラクターを新規配置する。characterIdを省略した場合はPlaceFlagMove(0x01)を立て、
同depthの既存インスタンスを移動する呼び出しとして扱う。
translateXPx・translateYPxのいずれかを渡すとPlaceFlagHasMatrix(0x04)を立て、
px→twips換算した平行移動のみの行列(拡大縮小・回転なし)を書き込む。
nameを渡すとPlaceFlagHasName(0x20)を立て、SJISのnull終端文字列としてインスタンス名を
書き込む。ボディの並びはflags(UI8) → depth(UI16) → characterId(UI16) →
行列 → name(STRING)。
Implementation
void placeObject2({
required int depth,
int? characterId,
int? translateXPx,
int? translateYPx,
String? name,
}) {
final hasCharacter = characterId != null;
final hasMatrix = translateXPx != null || translateYPx != null;
final hasName = name != null;
final move = !hasCharacter;
var flags = 0;
if (move) flags |= 0x01;
if (hasCharacter) flags |= 0x02;
if (hasMatrix) flags |= 0x04;
if (hasName) flags |= 0x20;
final bw = BitWriter();
bw.writeUI8(flags);
bw.writeUI16(depth);
if (hasCharacter) bw.writeUI16(characterId);
if (hasMatrix) {
_writeMatrixTranslateOnly(
bw,
(translateXPx ?? 0) * _twipsPerPixel,
(translateYPx ?? 0) * _twipsPerPixel,
);
}
if (hasName) _writeSjisString(bw, name);
_writeTag(TagCode.placeObject2, bw.toBytes());
}