Skip to content

Commit

Permalink
Use version 1.1.101 for output blueprint string
Browse files Browse the repository at this point in the history
  • Loading branch information
joelverhagen committed Oct 26, 2024
1 parent ed60f85 commit ef09956
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ int GetEntityNumber(GridEntity entity)

var blueprint = new Blueprint
{
Icons = context.InputBlueprint.Icons ?? new[]
Icons = new[]
{
new Icon
{
Expand All @@ -164,14 +164,32 @@ int GetEntityNumber(GridEntity entity)
}
}
},
Version = context.InputBlueprint.Version,
Item = context.InputBlueprint.Item ?? ItemNames.Vanilla.Blueprint,
Version = FormatVersion(1, 1, 101, 1),
Item = ItemNames.Vanilla.Blueprint,
Entities = entities.ToArray(),
};

return SerializeBlueprint(blueprint, addFbeOffset);
}

/// <summary>
/// Source: https://wiki.factorio.com/Version_string_format
/// </summary>
public static (ushort major, ushort minor, ushort patch, ushort developer) ParseVersion(ulong version)
{
return (
(ushort)((version >> 48) & 0xFFFF),
(ushort)((version >> 32) & 0xFFFF),
(ushort)((version >> 16) & 0xFFFF),
(ushort)(version & 0xFFFF)
);
}

public static ulong FormatVersion(ushort major, ushort minor, ushort patch, ushort developer)
{
return ((ulong)major << 48) | ((ulong)minor << 32) | ((ulong)patch << 16) | developer;
}

public static string SerializeBlueprint(Blueprint blueprint, bool addFbeOffset)
{
// FBE applies some offset to the blueprint coordinates. This makes it hard to compare the grid used in memory
Expand Down
2 changes: 1 addition & 1 deletion src/FactorioTools/Data/Blueprint.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,5 @@ public class Blueprint
public string Item { get; set; } = null!;

[JsonPropertyName("version")]
public long Version { get; set; }
public ulong Version { get; set; }
}
1 change: 0 additions & 1 deletion src/FactorioTools/OilField/Planner.cs
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,6 @@ public static PlannerResult ExecuteSample()
}
},
Item = ItemNames.Vanilla.Blueprint,
Version = 0,
};

return Execute(options, inputBlueprint);
Expand Down
1 change: 0 additions & 1 deletion src/FactorioTools/OilField/Steps/CleanBlueprint.cs
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@ public static Blueprint Execute(Blueprint blueprint)
}
},
Item = ItemNames.Vanilla.Blueprint,
Version = 0,
};
}
}
1 change: 0 additions & 1 deletion src/FactorioTools/OilField/Steps/InitializeContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ public static Context GetEmpty(OilFieldOptions options, int width, int height)
},
},
Item = ItemNames.Vanilla.Blueprint,
Version = 1,
};

return Execute(options, blueprint, Array.Empty<AvoidLocation>(), width, height);
Expand Down

0 comments on commit ef09956

Please sign in to comment.