Skip to content

Commit

Permalink
Merge pull request #29 from penev92/paletteFixes
Browse files Browse the repository at this point in the history
Fixed some things the palettes implementation missed
penev92 authored Oct 22, 2022
2 parents e1aed4b + c88dc10 commit acdda22
Showing 3 changed files with 32 additions and 6 deletions.
Original file line number Diff line number Diff line change
@@ -34,7 +34,7 @@ public class TextDocumentCompletionHandler : BaseRpcMessageHandler
CommitCharacters = new[] { ":" }
};

readonly CompletionItem defaultsCompletionItem = new()
readonly CompletionItem defaultsCompletionItem = new ()
{
Label = "Defaults",
Kind = CompletionItemKind.Constructor,
@@ -262,7 +262,6 @@ protected override IEnumerable<CompletionItem> HandleRulesValue(CursorTarget cur
var tempWeaponNames = weaponNames;
var tempConditionNames = conditionNames;
var tempCursorNames = cursorNames;
var tempPaletteNames = paletteNames;

MapManifest mapManifest = default;
if (cursorTarget.FileType == FileType.MapRules)
@@ -276,7 +275,7 @@ protected override IEnumerable<CompletionItem> HandleRulesValue(CursorTarget cur
tempActorNames = tempActorNames.Union(mapSymbols.ActorDefinitions.Select(x => x.First().ToCompletionItem()));
tempWeaponNames = tempWeaponNames.Union(mapSymbols.WeaponDefinitions.Select(x => x.First().ToCompletionItem()));
tempConditionNames = tempConditionNames.Union(mapSymbols.ConditionDefinitions.Select(x => x.First().ToCompletionItem()));
tempPaletteNames = tempPaletteNames.Union(mapSymbols.PaletteDefinitions.Select(x => x.First().ToCompletionItem()));
paletteNames = paletteNames.Union(mapSymbols.PaletteDefinitions.Select(x => x.First().ToCompletionItem()));
spriteSequenceImageNames = spriteSequenceImageNames.Union(
mapSymbols.SpriteSequenceImageDefinitions.Select(x => x.First().ToCompletionItem()));
}
@@ -298,7 +297,7 @@ protected override IEnumerable<CompletionItem> HandleRulesValue(CursorTarget cur
return tempCursorNames;

if (fieldInfo.OtherAttributes.Any(x => x.Name == "PaletteReference"))
return tempPaletteNames.Where(x => !string.IsNullOrEmpty(x.Label));
return paletteNames.Where(x => !string.IsNullOrEmpty(x.Label));

// Pretend there is such a thing as a "SequenceImageReferenceAttribute" until we add it in OpenRA one day.
// NOTE: This will improve if/when we add the attribute.
@@ -431,11 +430,15 @@ protected override IEnumerable<CompletionItem> HandleWeaponValue(CursorTarget cu

if (mapManifest.MapReference != null && symbolCache.Maps.TryGetValue(mapManifest.MapReference, out var mapSymbols))
{
paletteNames = paletteNames.Union(mapSymbols.PaletteDefinitions.Select(x => x.First().ToCompletionItem()));
spriteSequenceImageNames = spriteSequenceImageNames.Union(
mapSymbols.SpriteSequenceImageDefinitions.Select(x => x.First().ToCompletionItem()));
}
}

if (fieldInfo.OtherAttributes.Any(x => x.Name == "PaletteReference"))
return paletteNames.Where(x => !string.IsNullOrEmpty(x.Label));

// Pretend there is such a thing as a "SequenceImageReferenceAttribute" until we add it in OpenRA one day.
// NOTE: This will improve if/when we add the attribute.
if (fieldInfos.Any(x => x.OtherAttributes.Any(y => y.Name == "SequenceReference"
Original file line number Diff line number Diff line change
@@ -157,6 +157,7 @@ protected override IEnumerable<Location> HandleRulesValue(CursorTarget cursorTar
actorDefinitions = actorDefinitions.Union(mapSymbols.ActorDefinitions[cursorTarget.TargetString]);
weaponDefinitions = weaponDefinitions.Union(mapSymbols.WeaponDefinitions[cursorTarget.TargetString]);
conditionDefinitions = conditionDefinitions.Union(mapSymbols.ConditionDefinitions[cursorTarget.TargetString]);
paletteDefinitions = paletteDefinitions.Union(mapSymbols.PaletteDefinitions[cursorTarget.TargetString]);

spriteSequenceImageDefinitions = spriteSequenceImageDefinitions
.SelectMany(x => x)
@@ -333,6 +334,7 @@ protected override IEnumerable<Location> HandleWeaponValue(CursorTarget cursorTa
}
}

var paletteDefinitions = modSymbols.PaletteDefinitions[cursorTarget.TargetString];
var spriteSequenceImageDefinitions = symbolCache[cursorTarget.ModId].ModSymbols.SpriteSequenceImageDefinitions;

MapManifest mapManifest = default;
@@ -344,13 +346,17 @@ protected override IEnumerable<Location> HandleWeaponValue(CursorTarget cursorTa
if (mapManifest.MapReference != null && symbolCache.Maps.TryGetValue(mapManifest.MapReference, out var mapSymbols))
{
// Merge mod symbols with map symbols.
paletteDefinitions = paletteDefinitions.Union(mapSymbols.PaletteDefinitions[cursorTarget.TargetString]);
spriteSequenceImageDefinitions = spriteSequenceImageDefinitions
.SelectMany(x => x)
.Union(mapSymbols.SpriteSequenceImageDefinitions.SelectMany(x => x))
.ToLookup(x => x.Name, y => y);
}
}

if (fieldInfo.OtherAttributes.Any(x => x.Name == "PaletteReference"))
return paletteDefinitions.Select(x => x.Location.ToLspLocation(x.Type.Length));

// Pretend there is such a thing as a "SequenceImageReferenceAttribute" until we add it in OpenRA one day.
// NOTE: This will improve if/when we add the attribute.
if (fieldInfos.Any(x => x.OtherAttributes.Any(y => y.Name == "SequenceReference"
Original file line number Diff line number Diff line change
@@ -181,7 +181,7 @@ protected override Hover HandleRulesValue(CursorTarget cursorTarget)
var weaponDefinitions = modSymbols.WeaponDefinitions.Select(x => x.Key);
var conditionDefinitions = modSymbols.ConditionDefinitions.Select(x => x.Key);
var cursorDefinitions = modSymbols.CursorDefinitions.Select(x => x.Key);
var paletteDefinitions = modSymbols.PaletteDefinitions.Select(x => x.Key);
var paletteDefinitions = modSymbols.PaletteDefinitions;
var spriteSequenceImageDefinitions = modSymbols.SpriteSequenceImageDefinitions;

MapManifest mapManifest = default;
@@ -195,6 +195,12 @@ protected override Hover HandleRulesValue(CursorTarget cursorTarget)
actorDefinitions = actorDefinitions.Union(mapSymbols.ActorDefinitions.Select(x => x.Key));
weaponDefinitions = weaponDefinitions.Union(mapSymbols.WeaponDefinitions.Select(x => x.Key));
conditionDefinitions = conditionDefinitions.Union(mapSymbols.ConditionDefinitions.Select(x => x.Key));

// Merge mod symbols with map symbols.
paletteDefinitions = paletteDefinitions
.SelectMany(x => x)
.Union(mapSymbols.PaletteDefinitions.SelectMany(x => x))
.ToLookup(x => x.Name, y => y);
spriteSequenceImageDefinitions = spriteSequenceImageDefinitions
.SelectMany(x => x)
.Union(mapSymbols.SpriteSequenceImageDefinitions.SelectMany(x => x))
@@ -223,7 +229,7 @@ protected override Hover HandleRulesValue(CursorTarget cursorTarget)

if (fieldInfo.OtherAttributes.Any(x => x.Name == "PaletteReference") && paletteDefinitions.Contains(cursorTarget.TargetString))
{
var palette = modSymbols.PaletteDefinitions[cursorTarget.TargetString].First();
var palette = paletteDefinitions[cursorTarget.TargetString].First();
return HoverFromHoverInfo(palette.ToMarkdownInfoString(), range);
}

@@ -444,6 +450,7 @@ protected override Hover HandleWeaponValue(CursorTarget cursorTarget)
}
}

var paletteDefinitions = modSymbols.PaletteDefinitions;
var spriteSequenceImageDefinitions = modSymbols.SpriteSequenceImageDefinitions;

MapManifest mapManifest = default;
@@ -455,13 +462,23 @@ protected override Hover HandleWeaponValue(CursorTarget cursorTarget)
if (mapManifest.MapReference != null && symbolCache.Maps.TryGetValue(mapManifest.MapReference, out var mapSymbols))
{
// Merge mod symbols with map symbols.
paletteDefinitions = paletteDefinitions
.SelectMany(x => x)
.Union(mapSymbols.PaletteDefinitions.SelectMany(x => x))
.ToLookup(x => x.Name, y => y);
spriteSequenceImageDefinitions = spriteSequenceImageDefinitions
.SelectMany(x => x)
.Union(mapSymbols.SpriteSequenceImageDefinitions.SelectMany(x => x))
.ToLookup(x => x.Name, y => y);
}
}

if (fieldInfo.OtherAttributes.Any(x => x.Name == "PaletteReference") && paletteDefinitions.Contains(cursorTarget.TargetString))
{
var palette = paletteDefinitions[cursorTarget.TargetString].First();
return HoverFromHoverInfo(palette.ToMarkdownInfoString(), range);
}

// Pretend there is such a thing as a "SequenceImageReferenceAttribute" until we add it in OpenRA one day.
// NOTE: This will improve if/when we add the attribute.
if (fieldInfos.Any(x => x.OtherAttributes.Any(y => y.Name == "SequenceReference"

0 comments on commit acdda22

Please sign in to comment.