Skip to content

Commit

Permalink
Editor: serialize Room's description in a room file
Browse files Browse the repository at this point in the history
Also reserve "script name" field for the future.
  • Loading branch information
ivan-mogilko committed Dec 20, 2024
1 parent 75f52ea commit a9825ff
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 2 deletions.
18 changes: 18 additions & 0 deletions Common/game/room_file.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -381,6 +381,13 @@ HError ReadExt_400_CustomProps(RoomStruct *room, Stream *in, RoomFileVersion dat
return HError::None();
}

HError ReadExt_400_RoomNames(RoomStruct *room, Stream *in, RoomFileVersion data_ver)
{
room->ScriptName = StrUtil::ReadString(in);
room->Name = StrUtil::ReadString(in);
return HError::None();
}

HError ReadRoomBlock(RoomStruct *room, Stream *in, RoomFileBlock block, const String &ext_id,
soff_t block_len, RoomFileVersion data_ver)
{
Expand Down Expand Up @@ -434,6 +441,10 @@ HError ReadRoomBlock(RoomStruct *room, Stream *in, RoomFileBlock block, const St
{
return ReadExt_400_CustomProps(room, in, data_ver);
}
else if (ext_id.CompareNoCase("v400_roomnames") == 0)
{
return ReadExt_400_RoomNames(room, in, data_ver);
}

return new RoomFileError(kRoomFileErr_UnknownBlockType,
String::FromFormat("Type: %s", ext_id.GetCStr()));
Expand Down Expand Up @@ -724,6 +735,12 @@ void WriteExt_400_CustomProps(const RoomStruct *room, Stream *out)
}
}

void WriteExt_400_RoomNames(const RoomStruct *room, Stream *out)
{
StrUtil::WriteString(room->ScriptName, out);
StrUtil::WriteString(room->Name, out);
}

HRoomFileError WriteRoomData(const RoomStruct *room, Stream *out, RoomFileVersion data_ver)
{
if (data_ver < kRoomVersion_Current)
Expand Down Expand Up @@ -755,6 +772,7 @@ HRoomFileError WriteRoomData(const RoomStruct *room, Stream *out, RoomFileVersio
WriteRoomBlock(room, "ext_ags399", WriteExt399, out);
WriteRoomBlock(room, "v400_walkopts", WriteExt_400_WalkareaOpts, out);
WriteRoomBlock(room, "v400_customprops", WriteExt_400_CustomProps, out);
WriteRoomBlock(room, "v400_roomnames", WriteExt_400_RoomNames, out);

// Write end of room file
out->WriteByte(kRoomFile_EOF);
Expand Down
10 changes: 9 additions & 1 deletion Common/game/roomstruct.h
Original file line number Diff line number Diff line change
Expand Up @@ -246,6 +246,11 @@ class RoomStruct
// Init default room state
void InitDefaults();

// Gets this room's human-readable name (description)
const String &GetName() const { return Name; }
// Gets this room's script name
const String &GetScriptName() const { return ScriptName; }

// Gets bitmap of particular mask layer
Bitmap *GetMask(RoomAreaMask mask) const;
// Sets bitmap for the particular mask layer;
Expand Down Expand Up @@ -275,6 +280,10 @@ class RoomStruct
// the room must have behavior specific to certain version of AGS.
int32_t DataVersion;

// This room's name (description)
String Name;
// This room's scriptname. This is a reserved field atm.
String ScriptName;
// Room region masks resolution. Defines the relation between room and mask units.
// Mask point is calculated as roompt / MaskResolution. Must be >= 1.
int32_t MaskResolution;
Expand Down Expand Up @@ -319,7 +328,6 @@ class RoomStruct
PScript CompiledScript;
// Various extended options with string values, meta-data etc
StringMap StrOptions;

};


Expand Down
4 changes: 3 additions & 1 deletion Editor/AGS.Native/agsnative.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2954,8 +2954,10 @@ void convert_room_to_native(Room ^room, RoomStruct &rs)
// to be saved using native procedure.
//
TextConverter^ tcv = TextHelper::GetGameTextConverter();
rs.MaskResolution = room->MaskResolution;

rs.Name = tcv->ConvertTextProperty(room->Description);
rs.ScriptName = ""; // reserved
rs.MaskResolution = room->MaskResolution;
rs.GameID = room->GameID;
rs.Edges.Bottom = room->BottomEdgeY;
rs.Edges.Left = room->LeftEdgeX;
Expand Down

0 comments on commit a9825ff

Please sign in to comment.