Skip to content

Commit

Permalink
Editor: added design-time FaceDirectionRatio properties
Browse files Browse the repository at this point in the history
  • Loading branch information
ivan-mogilko committed Jan 22, 2024
1 parent e3b83d0 commit e68f64a
Show file tree
Hide file tree
Showing 8 changed files with 110 additions and 4 deletions.
6 changes: 6 additions & 0 deletions Common/game/main_game_file.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -525,6 +525,12 @@ HError GameDataExtReader::ReadBlock(int /*block_id*/, const String &ext_id,
_in->Seek(sizeof(int32_t) * 11);
}
}
else if (ext_id.CompareNoCase("v400_gameopts") == 0)
{
_ents.Game.faceDirectionRatio = _in->ReadFloat32();
// reserve few more 32-bit values (for a total of 10)
_in->Seek(sizeof(int32_t) * 9);
}
else
{
return new MainGameFileError(kMGFErr_ExtUnknown, String::FromFormat("Type: %s", ext_id.GetCStr()));
Expand Down
54 changes: 52 additions & 2 deletions Common/game/room_file.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -326,6 +326,31 @@ HError ReadExt399(RoomStruct *room, Stream *in, RoomFileVersion data_ver)
return HError::None();
}

// Extended walkable areas and related room properties
HError ReadExt_400_WalkOpts(RoomStruct *room, Stream *in, RoomFileVersion data_ver)
{
// New room properties
room->Options.FaceDirectionRatio = in->ReadFloat32();
// reserve few more 32-bit values (for a total of 4)
in->ReadInt32();
in->ReadInt32();
in->ReadInt32();

size_t wa_count = in->ReadInt32();
if (wa_count != room->WalkAreaCount)
return new Error(String::FromFormat("Mismatching number of walkable areas: read %zu expected %zu", wa_count, room->WalkAreaCount));
for (size_t i = 0; i < wa_count; ++i)
{
auto &wa = room->WalkAreas[i];
wa.FaceDirectionRatio = in->ReadFloat32();
// reserve few more 32-bit values (for a total of 4)
in->ReadInt32();
in->ReadInt32();
in->ReadInt32();
}
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 @@ -366,12 +391,15 @@ HError ReadRoomBlock(RoomStruct *room, Stream *in, RoomFileBlock block, const St
StrUtil::ReadStringMap(room->StrOptions, in);
return HError::None();
}

// Early development version of "ags4"
if (ext_id.CompareNoCase("ext_ags399") == 0)
else if (ext_id.CompareNoCase("ext_ags399") == 0)
{
return ReadExt399(room, in, data_ver);
}
else if (ext_id.CompareNoCase("v400_walkopts") == 0)
{
return ReadExt_400_WalkOpts(room, in, data_ver);
}

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

void WriteExt_400_WalkareaOpts(const RoomStruct *room, Stream *out)
{
// New room properties
out->WriteFloat32(room->Options.FaceDirectionRatio);
// reserve few more 32-bit values (for a total of 4)
out->WriteInt32(0);
out->WriteInt32(0);
out->WriteInt32(0);

out->WriteInt32(room->WalkAreaCount);
for (size_t i = 0; i < room->WalkAreaCount; ++i)
{
const auto &wa = room->WalkAreas[i];
out->WriteFloat32(wa.FaceDirectionRatio);
// reserve few more 32-bit values (for a total of 4)
out->WriteInt32(0);
out->WriteInt32(0);
out->WriteInt32(0);
}
}

HRoomFileError WriteRoomData(const RoomStruct *room, Stream *out, RoomFileVersion data_ver)
{
if (data_ver < kRoomVersion_Current)
Expand Down Expand Up @@ -643,6 +692,7 @@ HRoomFileError WriteRoomData(const RoomStruct *room, Stream *out, RoomFileVersio

// Early development version of "ags4"
WriteRoomBlock(room, "ext_ags399", WriteExt399, out);
WriteRoomBlock(room, "v400_walkopts", WriteExt_400_WalkareaOpts, out);

// Write end of room file
out->WriteByte(kRoomFile_EOF);
Expand Down
3 changes: 2 additions & 1 deletion Editor/AGS.Editor/AGSEditor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -110,9 +110,10 @@ public class AGSEditor : IAGSEditorDirectories
* 3.99.99.01 - Open rooms
* 3.99.99.07 - PO translations
* 4.00.00.00 - Raised for org purposes without project changes
* 4.00.00.03 - FaceDirectionRatio
*
*/
public const int LATEST_XML_VERSION_INDEX = 4000000;
public const int LATEST_XML_VERSION_INDEX = 4000003;
/// <summary>
/// XML version index on the release of AGS 4.0.0, this constant be used to determine
/// if upgrade of Rooms/Sprites/etc. to new format have been performed.
Expand Down
9 changes: 9 additions & 0 deletions Editor/AGS.Editor/DataFileWriter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1718,6 +1718,7 @@ public static bool SaveThisGameToFile(string fileName, Game game, CompileMessage
WriteExtension("v360_cursors", WriteExt_360Cursors, writer, game, errors);
WriteExtension("v361_objnames", WriteExt_361ObjNames, writer, game, errors);
WriteExtension("ext_ags399", WriteExt_Ags399, writer, game, errors);
WriteExtension("v400_gameopts", WriteExt_400GameOpts, writer, game, errors);

// End of extensions list
writer.Write((byte)0xff);
Expand Down Expand Up @@ -1816,6 +1817,14 @@ private static void WriteExt_Ags399(BinaryWriter writer, Game game, CompileMessa
}
}

private static void WriteExt_400GameOpts(BinaryWriter writer, Game game, CompileMessages errors)
{
writer.Write((float)game.Settings.FaceDirectionRatio);
// reserve more 32-bit values for a total of 10
for (int i = 0; i < 9; ++i)
writer.Write((int)0);
}

private delegate void WriteExtensionProc(BinaryWriter writer, Game game, CompileMessages errors);

private static void WriteExtension(string ext_id, WriteExtensionProc proc, BinaryWriter writer, Game game, CompileMessages errors)
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 @@ -2839,6 +2839,7 @@ void convert_room_from_native(const RoomStruct &rs, Room ^room, System::Text::En
RoomWalkableArea ^area = room->WalkableAreas[i];
area->ID = i;
area->AreaSpecificView = rs.WalkAreas[i].PlayerView;
area->FaceDirectionRatio = rs.WalkAreas[i].FaceDirectionRatio;
area->UseContinuousScaling = !(rs.WalkAreas[i].ScalingNear == NOT_VECTOR_SCALED);
area->ScalingLevel = rs.WalkAreas[i].ScalingFar + 100;
area->MinScalingLevel = rs.WalkAreas[i].ScalingFar + 100;
Expand Down Expand Up @@ -2949,7 +2950,8 @@ void convert_room_to_native(Room ^room, RoomStruct &rs)
{
RoomWalkableArea ^area = room->WalkableAreas[i];
rs.WalkAreas[i].PlayerView = area->AreaSpecificView;

rs.WalkAreas[i].FaceDirectionRatio = area->FaceDirectionRatio;

if (area->UseContinuousScaling)
{
rs.WalkAreas[i].ScalingFar = area->MinScalingLevel - 100;
Expand Down
10 changes: 10 additions & 0 deletions Editor/AGS.Types/Room.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ public class Room : UnloadedRoom, IChangeNotification, ILoadedRoom
private int _bottomEdgeY;
private bool _showPlayerCharacter = true;
private int _playerCharacterView;
private float _faceDirectionRatio = 0.0f;
private int _maskResolution = 1;
private int _colorDepth;
private int _width;
Expand Down Expand Up @@ -313,6 +314,15 @@ public int PlayerCharacterView
set { _playerCharacterView = value; }
}

[Description("INPUT DESCRIPTION HERE: Y / X ratio, override for this room only")]
[DefaultValue(0.0f)]
[Category("Settings")]
public float FaceDirectionRatio
{
get { return _faceDirectionRatio; }
set { _faceDirectionRatio = value; }
}

[Obsolete]
[Browsable(false)]
public int MusicVolumeAdjustment { get; }
Expand Down
10 changes: 10 additions & 0 deletions Editor/AGS.Types/RoomWalkableArea.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ public class RoomWalkableArea : ICustomTypeDescriptor, IToXml
{
private int _id;
private int _areaSpecificView;
private float _faceDirectionRatio = 0.0f;
private int _scalingLevel = 100;
private bool _useContinuousScaling;
private int _scalingLevelMin = 100;
Expand Down Expand Up @@ -46,6 +47,15 @@ public int AreaSpecificView
set { _areaSpecificView = value; }
}

[Description("INPUT DESCRIPTION HERE: Y / X ratio, override for this area only")]
[DefaultValue(0.0f)]
[Category("Design")]
public float FaceDirectionRatio
{
get { return _faceDirectionRatio; }
set { _faceDirectionRatio = value; }
}

[Description("Enables this area to have a graduated scaling level from the top to bottom, rather than a fixed scaling.")]
[Category("Scaling")]
[DefaultValue(false)]
Expand Down
18 changes: 18 additions & 0 deletions Editor/AGS.Types/Settings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ public Settings()
private ScriptAPIVersion _scriptCompatLevelReal = Utilities.GetActualAPI(ScriptAPIVersion.Highest);
private bool _oldKeyHandling = false;
private bool _scaleCharacterSpriteOffsets = true;
private float _faceDirectionRatio = 1.0f;
private int _dialogOptionsGUI = 0;
private int _dialogOptionsGap = 0;
private int _dialogBulletImage = 0;
Expand Down Expand Up @@ -531,6 +532,23 @@ public bool ScaleCharacterSpriteOffsets
set { _scaleCharacterSpriteOffsets = value; }
}

[DisplayName("Face direction ratio")]
[Description("INPUT DESCRIPTION HERE: Y / X ratio")]
[DefaultValue(1.0f)]
[Category("Character behavior")]
public float FaceDirectionRatio
{
get { return _faceDirectionRatio; }
set
{
if (value <= 0.0f || float.IsInfinity(value) || float.IsNaN(value))
{
throw new ArgumentException("Face direction ratio must be a valid positive value.");
}
_faceDirectionRatio = value;
}
}

[DisplayName("Enable Debug Mode")]
[Description("Enable various debugging keys that help you while developing your game")]
[DefaultValue(true)]
Expand Down

0 comments on commit e68f64a

Please sign in to comment.