Build typed Aetheria client surfaces
This commit is contained in:
parent
74b3b3d72a
commit
2e96660d48
246 changed files with 37893 additions and 6728 deletions
151
Assets/Scripts/ServerShared/AetheriaRuntimeLoadoutProjector.cs
Normal file
151
Assets/Scripts/ServerShared/AetheriaRuntimeLoadoutProjector.cs
Normal file
|
|
@ -0,0 +1,151 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using GameCult.Aetheria.State.Verse;
|
||||
using Unity.Mathematics;
|
||||
|
||||
public static class AetheriaRuntimeLoadoutProjector
|
||||
{
|
||||
public static AetheriaRuntimeLoadoutTemplateCommit ProjectLoadoutTemplate(EntityConstructionBlueprint blueprint)
|
||||
{
|
||||
return new AetheriaRuntimeLoadoutTemplateCommit
|
||||
{
|
||||
Name = blueprint?.Name ?? "",
|
||||
OwnerPlayerKey = "global:aetheria.player_settings.v1",
|
||||
RootEntity = ProjectEntityLoadout(blueprint)
|
||||
};
|
||||
}
|
||||
|
||||
public static AetheriaRuntimeLoadoutTemplateCommit ProjectLoadoutTemplate(Entity entity)
|
||||
{
|
||||
return new AetheriaRuntimeLoadoutTemplateCommit
|
||||
{
|
||||
Name = entity?.Name ?? "",
|
||||
OwnerPlayerKey = "global:aetheria.player_settings.v1",
|
||||
RootEntity = ProjectEntityLoadout(entity)
|
||||
};
|
||||
}
|
||||
|
||||
private static AetheriaRuntimeEntityLoadoutCommit ProjectEntityLoadout(EntityConstructionBlueprint blueprint)
|
||||
{
|
||||
return new AetheriaRuntimeEntityLoadoutCommit
|
||||
{
|
||||
Name = blueprint?.Name ?? "",
|
||||
Kind = blueprint is ShipConstructionBlueprint ? "ship" : blueprint is OrbitalEntityConstructionBlueprint ? "orbital" : "entity",
|
||||
FactionKey = blueprint?.FactionKey ?? "",
|
||||
Hull = ProjectLoadoutItem(blueprint?.Hull),
|
||||
Equipment = ProjectSlots(blueprint?.Equipment),
|
||||
CargoBays = ProjectSlots(blueprint?.CargoBays),
|
||||
DockingBays = ProjectSlots(blueprint?.DockingBays),
|
||||
CargoContents = ProjectCargoBays(blueprint?.CargoContents),
|
||||
DockingBayContents = ProjectCargoBays(blueprint?.DockingBayContents),
|
||||
DockingBayAssignments = blueprint?.DockingBayAssignments ?? Array.Empty<int>(),
|
||||
WeaponGroups = blueprint?.WeaponGroups?.Select(group => (IReadOnlyList<int>)group).ToArray() ?? Array.Empty<IReadOnlyList<int>>(),
|
||||
Children = blueprint?.Children?.Select(ProjectEntityLoadout).ToArray() ?? Array.Empty<AetheriaRuntimeEntityLoadoutCommit>()
|
||||
};
|
||||
}
|
||||
|
||||
private static AetheriaRuntimeEntityLoadoutCommit ProjectEntityLoadout(Entity entity)
|
||||
{
|
||||
return new AetheriaRuntimeEntityLoadoutCommit
|
||||
{
|
||||
Name = entity?.Name ?? "",
|
||||
Kind = entity is Ship ? "ship" : entity is OrbitalEntity ? "orbital" : "entity",
|
||||
FactionKey = entity?.Faction?.FactionKey ?? "",
|
||||
Hull = ProjectLoadoutItem(entity?.Hull),
|
||||
Equipment = ProjectSlots(entity?.Equipment),
|
||||
CargoBays = ProjectSlots(entity?.CargoBays),
|
||||
DockingBays = ProjectSlots(entity?.DockingBays),
|
||||
CargoContents = ProjectCargoBays(entity?.CargoBays),
|
||||
DockingBayContents = ProjectCargoBays(entity?.DockingBays),
|
||||
DockingBayAssignments = entity?.DockingBays?
|
||||
.Select(dockingBay => entity.Children.IndexOf(dockingBay.DockedShip))
|
||||
.ToArray() ?? Array.Empty<int>(),
|
||||
WeaponGroups = entity?.WeaponGroups?
|
||||
.Select(group => (IReadOnlyList<int>)group.items
|
||||
.Select(item => entity.Equipment.IndexOf(item))
|
||||
.ToArray())
|
||||
.ToArray() ?? Array.Empty<IReadOnlyList<int>>(),
|
||||
Children = entity?.Children?
|
||||
.Select(ProjectEntityLoadout)
|
||||
.ToArray() ?? Array.Empty<AetheriaRuntimeEntityLoadoutCommit>()
|
||||
};
|
||||
}
|
||||
|
||||
private static AetheriaRuntimeLoadoutItemSlotCommit[] ProjectSlots((int2 position, EquippableItem item)[] slots)
|
||||
{
|
||||
return slots?
|
||||
.Select(slot => new AetheriaRuntimeLoadoutItemSlotCommit
|
||||
{
|
||||
X = slot.position.x,
|
||||
Y = slot.position.y,
|
||||
Item = ProjectLoadoutItem(slot.item)
|
||||
})
|
||||
.ToArray() ?? Array.Empty<AetheriaRuntimeLoadoutItemSlotCommit>();
|
||||
}
|
||||
|
||||
private static AetheriaRuntimeLoadoutItemSlotCommit[] ProjectSlots(IEnumerable<EquippedItem> slots)
|
||||
{
|
||||
return slots?
|
||||
.Select(slot => new AetheriaRuntimeLoadoutItemSlotCommit
|
||||
{
|
||||
X = slot.Position.x,
|
||||
Y = slot.Position.y,
|
||||
Item = ProjectLoadoutItem(slot.EquippableItem, slot.Temperature)
|
||||
})
|
||||
.ToArray() ?? Array.Empty<AetheriaRuntimeLoadoutItemSlotCommit>();
|
||||
}
|
||||
|
||||
private static AetheriaRuntimeCargoBayLoadoutCommit[] ProjectCargoBays((int2 position, ItemInstance item)[][] bays)
|
||||
{
|
||||
return bays?
|
||||
.Select(bay => new AetheriaRuntimeCargoBayLoadoutCommit
|
||||
{
|
||||
Items = bay?
|
||||
.Select(slot => new AetheriaRuntimeLoadoutItemSlotCommit
|
||||
{
|
||||
X = slot.position.x,
|
||||
Y = slot.position.y,
|
||||
Item = ProjectLoadoutItem(slot.item)
|
||||
})
|
||||
.ToArray() ?? Array.Empty<AetheriaRuntimeLoadoutItemSlotCommit>()
|
||||
})
|
||||
.ToArray() ?? Array.Empty<AetheriaRuntimeCargoBayLoadoutCommit>();
|
||||
}
|
||||
|
||||
private static AetheriaRuntimeCargoBayLoadoutCommit[] ProjectCargoBays(IEnumerable<EquippedCargoBay> bays)
|
||||
{
|
||||
return bays?
|
||||
.Select(bay => new AetheriaRuntimeCargoBayLoadoutCommit
|
||||
{
|
||||
Items = bay.Cargo?
|
||||
.Select(slot => new AetheriaRuntimeLoadoutItemSlotCommit
|
||||
{
|
||||
X = slot.Value.x,
|
||||
Y = slot.Value.y,
|
||||
Item = ProjectLoadoutItem(slot.Key)
|
||||
})
|
||||
.ToArray() ?? Array.Empty<AetheriaRuntimeLoadoutItemSlotCommit>()
|
||||
})
|
||||
.ToArray() ?? Array.Empty<AetheriaRuntimeCargoBayLoadoutCommit>();
|
||||
}
|
||||
|
||||
private static AetheriaRuntimeLoadoutItemCommit ProjectLoadoutItem(
|
||||
ItemInstance item,
|
||||
double temperature = 0)
|
||||
{
|
||||
if (item == null)
|
||||
return new AetheriaRuntimeLoadoutItemCommit();
|
||||
|
||||
return new AetheriaRuntimeLoadoutItemCommit
|
||||
{
|
||||
ItemKey = item.ItemKey,
|
||||
Quality = item is CraftedItemInstance crafted ? crafted.Quality : 1.0,
|
||||
Durability = item is EquippableItem equippable ? equippable.Durability : 1.0,
|
||||
Quantity = item is SimpleCommodity commodity ? commodity.Quantity : 1,
|
||||
Enabled = true,
|
||||
OverrideShutdown = item is EquippableItem overrideable && overrideable.OverrideShutdown,
|
||||
Temperature = temperature
|
||||
};
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,2 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 59812ba0964c83444ba4389689548195
|
||||
|
|
@ -91,6 +91,15 @@ public class Galaxy
|
|||
if(progressCallback!=null) Thread.Sleep(500); // Inserting Delay to make it seem like it's doing more work lmao
|
||||
}
|
||||
|
||||
public static Galaxy ProjectObservedSectorMap(
|
||||
AetheriaRuntimeSectorMapDocument sectorMap,
|
||||
SectorBackgroundSettings background,
|
||||
AetheriaRuntimeCatalogSnapshot runtimeCatalog,
|
||||
Action<string> log)
|
||||
{
|
||||
return new Galaxy(sectorMap, background, runtimeCatalog, log);
|
||||
}
|
||||
|
||||
public static Galaxy ProjectObservedDaemonRun(
|
||||
AetheriaRuntimeRunCheckpointCommit run,
|
||||
SectorBackgroundSettings background,
|
||||
|
|
@ -115,9 +124,9 @@ public class Galaxy
|
|||
Log = log;
|
||||
GenerationSeed = run.GenerationSeed;
|
||||
NameGeneratorSettings = null;
|
||||
Factions = ResolveDaemonFactions(run);
|
||||
Factions = ResolveRunFactions(run);
|
||||
foreach (var faction in Factions)
|
||||
FactionRelationships[faction] = ResolveDaemonFactionRelationship(run, faction);
|
||||
FactionRelationships[faction] = ResolveRunFactionRelationship(run, faction);
|
||||
|
||||
Zones = (run.Zones ?? Array.Empty<AetheriaRuntimeZoneSnapshotCommit>())
|
||||
.Where(zone => zone != null && zone.ZoneIndex >= 0)
|
||||
|
|
@ -127,8 +136,8 @@ public class Galaxy
|
|||
ZoneIndex = zone.ZoneIndex,
|
||||
Name = string.IsNullOrWhiteSpace(zone.Name) ? $"Daemon Zone {zone.ZoneIndex}" : zone.Name,
|
||||
Position = new float2((float)zone.PositionX, (float)zone.PositionY),
|
||||
Factions = ResolveDaemonZoneFactions(zone),
|
||||
Owner = ResolveDaemonFactionByIndex(zone.OwnerFactionIndex),
|
||||
Factions = ResolveRunZoneFactions(zone),
|
||||
Owner = ResolveFactionByIndex(zone.OwnerFactionIndex),
|
||||
NamedZone = !string.IsNullOrWhiteSpace(zone.Name)
|
||||
})
|
||||
.ToArray();
|
||||
|
|
@ -154,11 +163,13 @@ public class Galaxy
|
|||
}
|
||||
}
|
||||
|
||||
Entrance = ResolveDaemonZone(run.EntranceZoneIndex) ?? ResolveDaemonZone(run.CurrentZoneIndex) ?? Zones.FirstOrDefault();
|
||||
Exit = ResolveDaemonZone(run.ExitZoneIndex);
|
||||
Entrance = ResolveRunZone(run.EntranceZoneIndex) ??
|
||||
ResolveRunZone(run.CurrentZoneIndex) ??
|
||||
Zones.FirstOrDefault();
|
||||
Exit = ResolveRunZone(run.ExitZoneIndex);
|
||||
foreach (var zone in run.DiscoveredZoneIndices ?? Array.Empty<int>())
|
||||
{
|
||||
var discovered = ResolveDaemonZone(zone);
|
||||
var discovered = ResolveRunZone(zone);
|
||||
if (discovered != null)
|
||||
DiscoveredZones.Add(discovered);
|
||||
}
|
||||
|
|
@ -167,13 +178,128 @@ public class Galaxy
|
|||
|
||||
CalculateDistanceMatrix();
|
||||
|
||||
GalaxyZone ResolveDaemonZone(int zoneIndex)
|
||||
GalaxyZone ResolveRunZone(int zoneIndex)
|
||||
{
|
||||
return zonesByIndex.TryGetValue(zoneIndex, out var zone) ? zone : null;
|
||||
}
|
||||
}
|
||||
|
||||
private Faction[] ResolveDaemonFactions(AetheriaRuntimeRunCheckpointCommit run)
|
||||
private Galaxy(
|
||||
AetheriaRuntimeSectorMapDocument sectorMap,
|
||||
SectorBackgroundSettings background,
|
||||
AetheriaRuntimeCatalogSnapshot runtimeCatalog,
|
||||
Action<string> log)
|
||||
{
|
||||
if (sectorMap == null) throw new ArgumentNullException(nameof(sectorMap));
|
||||
|
||||
_runtimeCatalog = runtimeCatalog ?? throw new InvalidOperationException("Daemon-observed galaxy requires the typed Aetheria runtime catalog.");
|
||||
_allFactions = ProjectFactions(_runtimeCatalog);
|
||||
IsPrelude = sectorMap.IsTutorial;
|
||||
Background = background;
|
||||
Log = log;
|
||||
GenerationSeed = sectorMap.GenerationSeed;
|
||||
NameGeneratorSettings = null;
|
||||
Factions = ResolveSectorMapFactions(sectorMap);
|
||||
foreach (var faction in Factions)
|
||||
FactionRelationships[faction] = ResolveSectorMapFactionRelationship(sectorMap, faction);
|
||||
|
||||
Zones = (sectorMap.Zones ?? Array.Empty<AetheriaRuntimeSectorMapZone>())
|
||||
.Where(zone => zone != null && zone.ZoneIndex >= 0)
|
||||
.OrderBy(zone => zone.ZoneIndex)
|
||||
.Select(zone => new GalaxyZone
|
||||
{
|
||||
ZoneIndex = zone.ZoneIndex,
|
||||
Name = string.IsNullOrWhiteSpace(zone.Name) ? $"Daemon Zone {zone.ZoneIndex}" : zone.Name,
|
||||
Position = new float2((float)zone.X, (float)zone.Y),
|
||||
Factions = ResolveSectorMapZoneFactions(zone),
|
||||
Owner = ResolveFactionByIndex(zone.OwnerFactionIndex),
|
||||
NamedZone = !string.IsNullOrWhiteSpace(zone.Name)
|
||||
})
|
||||
.ToArray();
|
||||
|
||||
var zonesByIndex = (sectorMap.Zones ?? Array.Empty<AetheriaRuntimeSectorMapZone>())
|
||||
.Where(zone => zone != null && zone.ZoneIndex >= 0)
|
||||
.OrderBy(zone => zone.ZoneIndex)
|
||||
.Select((zone, ordinal) => new { zone.ZoneIndex, Zone = Zones[ordinal] })
|
||||
.ToDictionary(pair => pair.ZoneIndex, pair => pair.Zone);
|
||||
|
||||
foreach (var link in sectorMap.Links ?? Array.Empty<AetheriaRuntimeSectorMapLink>())
|
||||
{
|
||||
if (link == null ||
|
||||
!zonesByIndex.TryGetValue(link.FromZoneIndex, out var from) ||
|
||||
!zonesByIndex.TryGetValue(link.ToZoneIndex, out var to))
|
||||
continue;
|
||||
|
||||
if (!from.AdjacentZones.Contains(to))
|
||||
from.AdjacentZones.Add(to);
|
||||
if (!to.AdjacentZones.Contains(from))
|
||||
to.AdjacentZones.Add(from);
|
||||
}
|
||||
|
||||
foreach (var source in sectorMap.Zones ?? Array.Empty<AetheriaRuntimeSectorMapZone>())
|
||||
{
|
||||
if (source == null || !zonesByIndex.TryGetValue(source.ZoneIndex, out var sourceZone))
|
||||
continue;
|
||||
|
||||
foreach (var adjacentIndex in source.AdjacentZoneIndices ?? Array.Empty<int>())
|
||||
{
|
||||
if (zonesByIndex.TryGetValue(adjacentIndex, out var adjacentZone) &&
|
||||
!sourceZone.AdjacentZones.Contains(adjacentZone))
|
||||
{
|
||||
sourceZone.AdjacentZones.Add(adjacentZone);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Entrance = ResolveSectorMapZone(sectorMap.EntranceZoneIndex) ??
|
||||
ResolveSectorMapZone(sectorMap.CurrentZoneIndex) ??
|
||||
Zones.FirstOrDefault();
|
||||
Exit = ResolveSectorMapZone(sectorMap.ExitZoneIndex);
|
||||
foreach (var zone in sectorMap.DiscoveredZoneIndices ?? Array.Empty<int>())
|
||||
{
|
||||
var discovered = ResolveSectorMapZone(zone);
|
||||
if (discovered != null)
|
||||
DiscoveredZones.Add(discovered);
|
||||
}
|
||||
if (DiscoveredZones.Count == 0 && Entrance != null)
|
||||
DiscoveredZones.Add(Entrance);
|
||||
|
||||
CalculateDistanceMatrix();
|
||||
|
||||
GalaxyZone ResolveSectorMapZone(int zoneIndex)
|
||||
{
|
||||
return zonesByIndex.TryGetValue(zoneIndex, out var zone) ? zone : null;
|
||||
}
|
||||
}
|
||||
|
||||
private Faction[] ResolveSectorMapFactions(AetheriaRuntimeSectorMapDocument sectorMap)
|
||||
{
|
||||
var factionKeys = new HashSet<string>(
|
||||
(sectorMap.FactionRelationships ?? Array.Empty<AetheriaRuntimeFactionRelationshipCommit>())
|
||||
.Select(relationship => relationship?.FactionKey)
|
||||
.Where(key => !string.IsNullOrWhiteSpace(key)),
|
||||
StringComparer.OrdinalIgnoreCase);
|
||||
|
||||
var factionIndices = (sectorMap.Zones ?? Array.Empty<AetheriaRuntimeSectorMapZone>())
|
||||
.Where(zone => zone != null)
|
||||
.SelectMany(zone => (zone.FactionIndices ?? Array.Empty<int>()).Concat(new[] { zone.OwnerFactionIndex }))
|
||||
.Where(index => index >= 0)
|
||||
.Distinct()
|
||||
.ToArray();
|
||||
|
||||
foreach (var index in factionIndices)
|
||||
{
|
||||
if (index >= 0 && index < _allFactions.Length)
|
||||
factionKeys.Add(_allFactions[index].FactionKey);
|
||||
}
|
||||
|
||||
var factions = _allFactions
|
||||
.Where(faction => factionKeys.Contains(faction.FactionKey))
|
||||
.ToArray();
|
||||
return factions.Length == 0 ? _allFactions : factions;
|
||||
}
|
||||
|
||||
private Faction[] ResolveRunFactions(AetheriaRuntimeRunCheckpointCommit run)
|
||||
{
|
||||
var factionKeys = new HashSet<string>(
|
||||
(run.FactionRelationships ?? Array.Empty<AetheriaRuntimeFactionRelationshipCommit>())
|
||||
|
|
@ -200,20 +326,39 @@ public class Galaxy
|
|||
return factions.Length == 0 ? _allFactions : factions;
|
||||
}
|
||||
|
||||
private Faction[] ResolveDaemonZoneFactions(AetheriaRuntimeZoneSnapshotCommit zone)
|
||||
private Faction[] ResolveSectorMapZoneFactions(AetheriaRuntimeSectorMapZone zone)
|
||||
{
|
||||
return (zone.FactionIndices ?? Array.Empty<int>())
|
||||
.Select(ResolveDaemonFactionByIndex)
|
||||
.Select(ResolveFactionByIndex)
|
||||
.Where(faction => faction != null)
|
||||
.ToArray();
|
||||
}
|
||||
|
||||
private Faction ResolveDaemonFactionByIndex(int index)
|
||||
private Faction[] ResolveRunZoneFactions(AetheriaRuntimeZoneSnapshotCommit zone)
|
||||
{
|
||||
return (zone.FactionIndices ?? Array.Empty<int>())
|
||||
.Select(ResolveFactionByIndex)
|
||||
.Where(faction => faction != null)
|
||||
.ToArray();
|
||||
}
|
||||
|
||||
private Faction ResolveFactionByIndex(int index)
|
||||
{
|
||||
return index >= 0 && index < _allFactions.Length ? _allFactions[index] : null;
|
||||
}
|
||||
|
||||
private FactionRelationship ResolveDaemonFactionRelationship(
|
||||
private FactionRelationship ResolveSectorMapFactionRelationship(
|
||||
AetheriaRuntimeSectorMapDocument sectorMap,
|
||||
Faction faction)
|
||||
{
|
||||
var relationship = (sectorMap.FactionRelationships ?? Array.Empty<AetheriaRuntimeFactionRelationshipCommit>())
|
||||
.FirstOrDefault(candidate => string.Equals(candidate?.FactionKey ?? "", faction?.FactionKey ?? "", StringComparison.OrdinalIgnoreCase));
|
||||
return Enum.TryParse<FactionRelationship>(relationship?.Relationship ?? "", out var parsed)
|
||||
? parsed
|
||||
: FactionRelationship.Neutral;
|
||||
}
|
||||
|
||||
private FactionRelationship ResolveRunFactionRelationship(
|
||||
AetheriaRuntimeRunCheckpointCommit run,
|
||||
Faction faction)
|
||||
{
|
||||
|
|
|
|||
Loading…
Reference in a new issue