Skip to content

Commit

Permalink
Update for playtest-20230731 engine.
Browse files Browse the repository at this point in the history
  • Loading branch information
pchote committed Jul 31, 2023
1 parent 4c04c6f commit 6c7f7ac
Show file tree
Hide file tree
Showing 24 changed files with 1,185 additions and 373 deletions.
818 changes: 752 additions & 66 deletions .editorconfig

Large diffs are not rendered by default.

5 changes: 4 additions & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ on:
push:
pull_request:

permissions:
contents: read # to fetch code (actions/checkout)

jobs:
linux:
name: Linux (.NET 6.0)
Expand Down Expand Up @@ -80,7 +83,7 @@ jobs:
- name: Check Mods
run: |
chocolatey install lua --version 5.1.5.52
choco install lua --version 5.1.5.52
$ENV:Path = $ENV:Path + ";C:\Program Files (x86)\Lua\5.1\"
.\make.ps1 check-scripts
.\make.ps1 test
3 changes: 3 additions & 0 deletions .github/workflows/packaging.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ on:
tags:
- '*'

permissions:
contents: write # for release creation (svenstaro/upload-release-action)

jobs:
linux:
name: Linux AppImages
Expand Down
3 changes: 2 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -182,9 +182,10 @@ ifneq ("$(MOD_SOLUTION_FILES)","")
@echo "Compiling in Debug mode..."
ifeq ($(RUNTIME), mono)
# Enabling EnforceCodeStyleInBuild and GenerateDocumentationFile as a workaround for some code style rules (in particular IDE0005) being bugged and not reporting warnings/errors otherwise.
@$(MSBUILD) -t:build -restore -p:Configuration=Debug -warnaserror -p:TargetPlatform=$(TARGETPLATFORM) -p:Mono=true -p:EnforceCodeStyleInBuild=true -p:GenerateDocumentationFile=true
@$(MSBUILD) -t:clean\;build -restore -p:Configuration=Debug -warnaserror -p:TargetPlatform=$(TARGETPLATFORM) -p:Mono=true -p:EnforceCodeStyleInBuild=true -p:GenerateDocumentationFile=true
else
# Enabling EnforceCodeStyleInBuild and GenerateDocumentationFile as a workaround for some code style rules (in particular IDE0005) being bugged and not reporting warnings/errors otherwise.
@$(DOTNET) clean -c Debug --nologo --verbosity minimal
@$(DOTNET) build -c Debug -nologo -warnaserror -p:TargetPlatform=$(TARGETPLATFORM) -p:EnforceCodeStyleInBuild=true -p:GenerateDocumentationFile=true
endif
endif
Expand Down
2 changes: 1 addition & 1 deletion OpenRA.Mods.Mobius/RemasterPackages.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public sealed class RemasterModContent : IGlobalModData
public readonly Dictionary<string, string> Packages;

[FieldLoader.Ignore]
readonly Dictionary<string, ModContent.ModSource> sources = new Dictionary<string, ModContent.ModSource>();
readonly Dictionary<string, ModContent.ModSource> sources = new();

public RemasterModContent(MiniYaml yaml)
{
Expand Down
312 changes: 107 additions & 205 deletions OpenRA.Mods.Mobius/RemasterSpriteSequence.cs

Large diffs are not rendered by default.

8 changes: 4 additions & 4 deletions OpenRA.Mods.Mobius/Terrain/RemasterTerrain.cs
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ public class RemasterTerrain : ITemplatedTerrainInfo, ITerrainInfoNotifyMapCreat

[FieldLoader.Ignore]
public readonly TerrainTypeInfo[] TerrainInfo;
readonly Dictionary<string, byte> terrainIndexByType = new Dictionary<string, byte>();
readonly Dictionary<string, byte> terrainIndexByType = new();
readonly byte defaultWalkableTerrainIndex;

public RemasterTerrain(IReadOnlyFileSystem fileSystem, string filepath)
Expand All @@ -82,7 +82,7 @@ public RemasterTerrain(IReadOnlyFileSystem fileSystem, string filepath)
var tt = TerrainInfo[i].Type;

if (terrainIndexByType.ContainsKey(tt))
throw new YamlException("Duplicate terrain type '{0}' in '{1}'.".F(tt, filepath));
throw new YamlException($"Duplicate terrain type '{tt}' in '{filepath}'.");

terrainIndexByType.Add(tt, i);
}
Expand All @@ -104,7 +104,7 @@ public byte GetTerrainIndex(string type)
if (terrainIndexByType.TryGetValue(type, out var index))
return index;

throw new InvalidDataException("Tileset '{0}' lacks terrain type '{1}'".F(Id, type));
throw new InvalidDataException($"Tileset '{Id}' lacks terrain type '{type}'");
}

public byte GetTerrainIndex(TerrainTile r)
Expand Down Expand Up @@ -147,7 +147,7 @@ public bool TryGetTileInfo(TerrainTile r, out TerrainTileInfo info)
IEnumerable<Color> ITerrainInfo.RestrictedPlayerColors { get { return TerrainInfo.Where(ti => ti.RestrictPlayerColor).Select(ti => ti.Color); } }
float ITerrainInfo.MinHeightColorBrightness => 1.0f;
float ITerrainInfo.MaxHeightColorBrightness => 1.0f;
TerrainTile ITerrainInfo.DefaultTerrainTile => new TerrainTile(Templates.First().Key, 0);
TerrainTile ITerrainInfo.DefaultTerrainTile => new(Templates.First().Key, 0);

string[] ITemplatedTerrainInfo.EditorTemplateOrder => EditorTemplateOrder;
IReadOnlyDictionary<ushort, TerrainTemplateInfo> ITemplatedTerrainInfo.Templates => Templates;
Expand Down
34 changes: 16 additions & 18 deletions OpenRA.Mods.Mobius/Terrain/RemasterTileCache.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,18 +20,16 @@ public sealed class RemasterTileCache : IDisposable
{
static readonly int[] FirstFrame = { 0 };

readonly Dictionary<ushort, Dictionary<int, Sprite[]>> sprites = new Dictionary<ushort, Dictionary<int, Sprite[]>>();
readonly Dictionary<ushort, float> scale = new Dictionary<ushort, float>();
readonly SpriteCache spriteCache;
readonly Sprite blankSprite;

public SpriteCache SpriteCache => spriteCache;
readonly Dictionary<ushort, Dictionary<int, Sprite[]>> sprites = new();
readonly Dictionary<ushort, float> scale = new();
public SpriteCache SpriteCache { get; }
Sprite BlankSprite { get; }

public RemasterTileCache(RemasterTerrain terrainInfo)
{
spriteCache = new SpriteCache(Game.ModData.DefaultFileSystem, Game.ModData.SpriteLoaders, terrainInfo.BgraSheetSize, terrainInfo.IndexedSheetSize, 0);
SpriteCache = new SpriteCache(Game.ModData.DefaultFileSystem, Game.ModData.SpriteLoaders, terrainInfo.BgraSheetSize, terrainInfo.IndexedSheetSize, 0);

var blankToken = spriteCache.ReserveSprites(terrainInfo.BlankTile, FirstFrame, default);
var blankToken = SpriteCache.ReserveSprites(terrainInfo.BlankTile, FirstFrame, default);

var remasteredSpriteReservations = new Dictionary<ushort, Dictionary<int, int[]>>();
foreach (var t in terrainInfo.Templates)
Expand All @@ -43,7 +41,7 @@ public RemasterTileCache(RemasterTerrain terrainInfo)
{
foreach (var kv in templateInfo.RemasteredFilenames)
templateTokens[kv.Key] = kv.Value
.Select(f => spriteCache.ReserveSprites(f, FirstFrame, default))
.Select(f => SpriteCache.ReserveSprites(f, FirstFrame, default))
.ToArray();
scale[t.Key] = 1f;
}
Expand All @@ -54,7 +52,7 @@ public RemasterTileCache(RemasterTerrain terrainInfo)
if (t.Value[i] == null)
continue;

templateTokens[i] = new[] { spriteCache.ReserveSprites(templateInfo.Filename, new[] { i }, default) };
templateTokens[i] = new[] { SpriteCache.ReserveSprites(templateInfo.Filename, new[] { i }, default) };
}

scale[t.Key] = terrainInfo.ClassicUpscaleFactor;
Expand All @@ -63,31 +61,31 @@ public RemasterTileCache(RemasterTerrain terrainInfo)
remasteredSpriteReservations[t.Key] = templateTokens;
}

spriteCache.LoadReservations(Game.ModData);
SpriteCache.LoadReservations(Game.ModData);

blankSprite = spriteCache.ResolveSprites(blankToken).First(s => s != null);
BlankSprite = SpriteCache.ResolveSprites(blankToken).First(s => s != null);
foreach (var kv in remasteredSpriteReservations)
{
sprites[kv.Key] = new Dictionary<int, Sprite[]>();
foreach (var tokens in kv.Value)
sprites[kv.Key][tokens.Key] = tokens.Value
.Select(t => spriteCache.ResolveSprites(t).FirstOrDefault(s => s != null))
.Select(t => SpriteCache.ResolveSprites(t).FirstOrDefault(s => s != null))
.ToArray();
}
}

public bool HasTileSprite(TerrainTile r, int frame)
{
return TileSprite(r, frame) != blankSprite;
return TileSprite(r, frame) != BlankSprite;
}

public Sprite TileSprite(TerrainTile r, int frame)
{
if (!sprites.TryGetValue(r.Type, out var templateSprites))
return blankSprite;
return BlankSprite;

if (!templateSprites.TryGetValue(r.Index, out var tileSprites))
return blankSprite;
return BlankSprite;

return tileSprites[frame % tileSprites.Length];
}
Expand All @@ -100,11 +98,11 @@ public float TileScale(TerrainTile r)
return templateScale;
}

public Sprite MissingTile => blankSprite;
public Sprite MissingTile => BlankSprite;

public void Dispose()
{
spriteCache.Dispose();
SpriteCache.Dispose();
}
}
}
32 changes: 22 additions & 10 deletions OpenRA.Mods.Mobius/Traits/Palettes/ColorPickerColorShift.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,37 +37,49 @@ class ColorPickerColorShiftInfo : TraitInfo
[Desc("Saturation reference for the color shift.")]
public readonly float ReferenceSaturation = 0.925f;

[Desc("Value reference for the color shift.")]
public readonly float ReferenceValue = 0.95f;

public override object Create(ActorInitializer init) { return new ColorPickerColorShift(this); }
}

class ColorPickerColorShift : ILoadsPalettes, ITickRender
{
readonly ColorPickerColorShiftInfo info;
readonly ColorPickerManagerInfo colorManager;
Color color;
Color preferredColor;

public ColorPickerColorShift(ColorPickerColorShiftInfo info)
{
// All users need to use the same TraitInfo instance, chosen as the default mod rules
colorManager = Game.ModData.DefaultRules.Actors[SystemActors.World].TraitInfo<ColorPickerManagerInfo>();
this.info = info;

// All users need to use the same TraitInfo instance, chosen as the default mod rules
var colorManager = Game.ModData.DefaultRules.Actors[SystemActors.World].TraitInfo<IColorPickerManagerInfo>();
colorManager.OnColorPickerColorUpdate += c => preferredColor = c;
preferredColor = Game.Settings.Player.Color;
}

void ILoadsPalettes.LoadPalettes(WorldRenderer wr)
{
color = colorManager.Color;
var (_, h, s, _) = color.ToAhsv();
wr.SetPaletteColorShift(info.BasePalette, h - info.ReferenceHue, s - info.ReferenceSaturation, info.MinHue, info.MaxHue);
color = preferredColor;
var (r, g, b) = color.ToLinear();
var (h, s, v) = Color.RgbToHsv(r, g, b);
wr.SetPaletteColorShift(info.BasePalette,
h - info.ReferenceHue, s - info.ReferenceSaturation, v / info.ReferenceValue,
info.MinHue, info.MaxHue);
}

void ITickRender.TickRender(WorldRenderer wr, Actor self)
{
if (color == colorManager.Color)
if (color == preferredColor)
return;

color = colorManager.Color;
var (_, h, s, _) = color.ToAhsv();
wr.SetPaletteColorShift(info.BasePalette, h - info.ReferenceHue, s - info.ReferenceSaturation, info.MinHue, info.MaxHue);
color = preferredColor;
var (r, g, b) = color.ToLinear();
var (h, s, v) = Color.RgbToHsv(r, g, b);
wr.SetPaletteColorShift(info.BasePalette,
h - info.ReferenceHue, s - info.ReferenceSaturation, v / info.ReferenceValue,
info.MinHue, info.MaxHue);
}
}
}
10 changes: 8 additions & 2 deletions OpenRA.Mods.Mobius/Traits/Palettes/FixedColorShift.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,9 @@ public class FixedColorShiftInfo : TraitInfo
[Desc("Saturation reference for the color shift.")]
public readonly float ReferenceSaturation = 0.925f;

[Desc("Value reference for the color shift.")]
public readonly float ReferenceValue = 0.95f;

public override object Create(ActorInitializer init) { return new FixedColorShift(this); }
}

Expand All @@ -53,8 +56,11 @@ public FixedColorShift(FixedColorShiftInfo info)

public void LoadPalettes(WorldRenderer wr)
{
var (_, h, s, _) = info.Color.ToAhsv();
wr.SetPaletteColorShift(info.BasePalette, h - info.ReferenceHue, s - info.ReferenceSaturation, info.MinHue, info.MaxHue);
var (r, g, b) = info.Color.ToLinear();
var (h, s, v) = Color.RgbToHsv(r, g, b);
wr.SetPaletteColorShift(info.BasePalette,
h - info.ReferenceHue, s - info.ReferenceSaturation, v / info.ReferenceValue,
info.MinHue, info.MaxHue);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public FixedPlayerColorShift(FixedPlayerColorShiftInfo info)
public void LoadPlayerPalettes(WorldRenderer wr, string playerName, Color color, bool replaceExisting)
{
if (info.PlayerIndex.TryGetValue(playerName, out var shift))
wr.SetPaletteColorShift(info.BasePalette + playerName, shift[0], shift[1], shift[2], shift[3]);
wr.SetPaletteColorShift(info.BasePalette + playerName, shift[0], shift[1], shift[2], shift[3], shift[4]);
}
}
}
10 changes: 8 additions & 2 deletions OpenRA.Mods.Mobius/Traits/Palettes/PlayerColorShift.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,9 @@ public class PlayerColorShiftInfo : TraitInfo
[Desc("Saturation reference for the color shift.")]
public readonly float ReferenceSaturation = 0.925f;

[Desc("Value reference for the color shift.")]
public readonly float ReferenceValue = 0.95f;

public override object Create(ActorInitializer init) { return new PlayerColorShift(this); }
}

Expand All @@ -50,8 +53,11 @@ public PlayerColorShift(PlayerColorShiftInfo info)

public void LoadPlayerPalettes(WorldRenderer wr, string playerName, Color color, bool replaceExisting)
{
var (_, h, s, _) = color.ToAhsv();
wr.SetPaletteColorShift(info.BasePalette + playerName, h - info.ReferenceHue, s - info.ReferenceSaturation, info.MinHue, info.MaxHue);
var (r, g, b) = color.ToLinear();
var (h, s, v) = Color.RgbToHsv(r, g, b);
wr.SetPaletteColorShift(info.BasePalette + playerName,
h - info.ReferenceHue, s - info.ReferenceSaturation, v / info.ReferenceValue,
info.MinHue, info.MaxHue);
}
}
}
11 changes: 5 additions & 6 deletions OpenRA.Mods.Mobius/Traits/World/RemasterTerrainRenderer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ bool ITiledTerrainRendererInfo.ValidateTileSprites(ITemplatedTerrainInfo terrain
{
if (!tileCache.HasTileSprite(new TerrainTile(t.Key, (byte)kv.Key), i))
{
onError("\tTemplate `{0}` tile {1} references sprite `{2}` that does not exist.".F(t.Key, kv.Key, templateInfo.RemasteredFilenames[i]));
onError($"\tTemplate `{t.Key}` tile {kv.Key} references sprite `{templateInfo.RemasteredFilenames[i]}` that does not exist.");
failed = true;
}
}
Expand Down Expand Up @@ -147,7 +147,7 @@ Rectangle ITiledTerrainRenderer.TemplateBounds(TerrainTemplateInfo template)
{
for (var x = 0; x < template.Size.X; x++)
{
var tile = new TerrainTile(template.Id, (byte)(i++));
var tile = new TerrainTile(template.Id, (byte)i++);
if (!terrainInfo.TryGetTileInfo(tile, out var tileInfo))
continue;

Expand All @@ -165,12 +165,12 @@ Rectangle ITiledTerrainRenderer.TemplateBounds(TerrainTemplateInfo template)
}
}

return templateRect.HasValue ? templateRect.Value : Rectangle.Empty;
return templateRect ?? Rectangle.Empty;
}

IEnumerable<IRenderable> ITiledTerrainRenderer.RenderUIPreview(WorldRenderer wr, TerrainTemplateInfo t, int2 origin, float scale)
{
if (!(t is RemasterTerrainTemplateInfo template))
if (t is not RemasterTerrainTemplateInfo template)
yield break;

var ts = map.Grid.TileSize;
Expand Down Expand Up @@ -202,8 +202,7 @@ IEnumerable<IRenderable> ITiledTerrainRenderer.RenderUIPreview(WorldRenderer wr,

IEnumerable<IRenderable> ITiledTerrainRenderer.RenderPreview(WorldRenderer wr, TerrainTemplateInfo t, WPos origin)
{
var template = t as RemasterTerrainTemplateInfo;
if (template == null)
if (t is not RemasterTerrainTemplateInfo template)
yield break;

var i = 0;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ void IUtilityCommand.Run(Utility utility, string[] args)
var config = new MegV3Loader.MegFile(ffs, args[2]);

// e.g. TD_TERRAIN_TEMPERATE.XML, TD_TERRAIN_DESERT.XML, TD_TERRAIN_WINTER.XML
mapping.Load(config.GetStream("DATA\\XML\\TILESETS\\{0}".F(args[3])));
mapping.Load(config.GetStream($"DATA\\XML\\TILESETS\\{args[3]}"));
}

var rootTexturePath = mapping.SelectSingleNode("//RootTexturePath").InnerText.ToUpperInvariant();
Expand All @@ -52,7 +52,7 @@ void IUtilityCommand.Run(Utility utility, string[] args)
var legacy = template.LastChildMatching("Images").Value.Value;
var code = Path.GetFileNameWithoutExtension(legacy).ToUpperInvariant();

var tileNodes = mapping.DocumentElement.SelectNodes("//Tile[Key/Name = '{0}']".F(code));
var tileNodes = mapping.DocumentElement.SelectNodes($"//Tile[Key/Name = '{code}']");

if (tileNodes == null)
{
Expand All @@ -69,7 +69,10 @@ void IUtilityCommand.Run(Utility utility, string[] args)
var index = tileNode.SelectSingleNode("Key/Shape").InnerText;
var frames = new List<string>();
foreach (var f in tileNode.SelectNodes("Value/Frames/Frame"))
frames.Add("DATA\\ART\\TEXTURES\\SRGB\\{0}\\{1}".F(rootTexturePath, Path.ChangeExtension(((XmlNode)f).InnerText, ".DDS").ToUpperInvariant()));
{
var path = Path.ChangeExtension(((XmlNode)f).InnerText, ".DDS").ToUpperInvariant();
frames.Add($"DATA\\ART\\TEXTURES\\SRGB\\{rootTexturePath}\\{path}");
}

imageNode.AddNode(index, FieldSaver.FormatValue(frames));
}
Expand Down
Loading

0 comments on commit 6c7f7ac

Please sign in to comment.