Skip to content

Commit

Permalink
Added missing support for palettes in weapon files
Browse files Browse the repository at this point in the history
  • Loading branch information
penev92 committed Oct 21, 2022
1 parent 6d69048 commit c88dc10
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public class TextDocumentCompletionHandler : BaseRpcMessageHandler
CommitCharacters = new[] { ":" }
};

readonly CompletionItem defaultsCompletionItem = new()
readonly CompletionItem defaultsCompletionItem = new ()
{
Label = "Defaults",
Kind = CompletionItemKind.Constructor,
Expand Down Expand Up @@ -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)
Expand All @@ -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()));
}
Expand All @@ -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.
Expand Down Expand Up @@ -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"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -334,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;
Expand All @@ -345,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"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -450,6 +450,7 @@ protected override Hover HandleWeaponValue(CursorTarget cursorTarget)
}
}

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

MapManifest mapManifest = default;
Expand All @@ -461,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"
Expand Down

0 comments on commit c88dc10

Please sign in to comment.