Sync daemon authority migration
This commit is contained in:
parent
030b4b5d74
commit
39a0dc8737
295 changed files with 25121 additions and 7360 deletions
|
|
@ -2,8 +2,9 @@ using System;
|
|||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using GameCult.Aetheria.EveRuntime;
|
||||
using GameCult.Aetheria.State.Unity;
|
||||
using GameCult.Eve.Surface;
|
||||
using GameCult.Eve.UnityUIToolkit;
|
||||
using UniRx;
|
||||
using UnityEngine;
|
||||
using UnityEngine.EventSystems;
|
||||
|
|
@ -15,13 +16,6 @@ using float2 = Unity.Mathematics.float2;
|
|||
|
||||
public class SectorRenderer : MonoBehaviour, IBeginDragHandler, IDragHandler, IScrollHandler
|
||||
{
|
||||
private const string ZoneDetailsSurfaceType = "surface-state";
|
||||
private const string ZoneDetailsSurfaceSchema = "gamecult.eve.surface.v1";
|
||||
private const string ZoneDetailsSurfaceProviderId = "aetheria";
|
||||
private const string ZoneDetailsSurfaceProviderKind = "sector.map";
|
||||
private const string ZoneDetailsSurfaceId = "aetheria.sector_map.zone_details";
|
||||
private const string CloseZoneDetailsCommand = "aetheria.sector_map.zone_details.close";
|
||||
|
||||
public ClickRaycaster Raycaster;
|
||||
public Canvas Canvas;
|
||||
public SectorMap Map;
|
||||
|
|
@ -51,6 +45,19 @@ public class SectorRenderer : MonoBehaviour, IBeginDragHandler, IDragHandler, IS
|
|||
private float _sectorBackgroundDepth;
|
||||
private float _sectorCameraDepth;
|
||||
private UIDocument _zoneDetailsSurfaceDocument;
|
||||
private readonly AetheriaEveUnitySurfaceChrome _zoneDetailsSurfaceChrome = new AetheriaEveUnitySurfaceChrome
|
||||
{
|
||||
RootAlignItems = Align.FlexEnd,
|
||||
RootPaddingTop = 24f,
|
||||
RootPaddingRight = 24f,
|
||||
Width = 360f,
|
||||
MinWidth = 0f,
|
||||
MaxWidth = 420f,
|
||||
PaddingLeft = 18f,
|
||||
PaddingRight = 18f,
|
||||
PaddingTop = 18f,
|
||||
PaddingBottom = 18f
|
||||
};
|
||||
|
||||
private float2 _position = float2(0.5f);
|
||||
private float _viewSize = .5f;
|
||||
|
|
@ -86,59 +93,30 @@ public class SectorRenderer : MonoBehaviour, IBeginDragHandler, IDragHandler, IS
|
|||
|
||||
private void RenderZoneDetailsSurface(GalaxyZone zone)
|
||||
{
|
||||
var document = ResolveZoneDetailsSurfaceDocument();
|
||||
document.gameObject.SetActive(true);
|
||||
|
||||
var root = document.rootVisualElement;
|
||||
root.Clear();
|
||||
root.style.flexGrow = 1;
|
||||
root.style.position = Position.Absolute;
|
||||
root.style.left = 0;
|
||||
root.style.top = 0;
|
||||
root.style.right = 0;
|
||||
root.style.bottom = 0;
|
||||
root.style.alignItems = Align.FlexEnd;
|
||||
root.style.justifyContent = Justify.FlexStart;
|
||||
root.style.paddingTop = 24;
|
||||
root.style.paddingRight = 24;
|
||||
root.pickingMode = PickingMode.Ignore;
|
||||
|
||||
var shell = new VisualElement();
|
||||
shell.style.width = 360;
|
||||
shell.style.maxWidth = 420;
|
||||
shell.style.backgroundColor = new Color(0.08f, 0.1f, 0.14f, 0.94f);
|
||||
shell.style.borderTopLeftRadius = 8;
|
||||
shell.style.borderTopRightRadius = 8;
|
||||
shell.style.borderBottomLeftRadius = 8;
|
||||
shell.style.borderBottomRightRadius = 8;
|
||||
shell.style.paddingLeft = 18;
|
||||
shell.style.paddingRight = 18;
|
||||
shell.style.paddingTop = 18;
|
||||
shell.style.paddingBottom = 18;
|
||||
shell.style.borderLeftWidth = 1;
|
||||
shell.style.borderRightWidth = 1;
|
||||
shell.style.borderTopWidth = 1;
|
||||
shell.style.borderBottomWidth = 1;
|
||||
shell.style.borderLeftColor = new Color(0.3f, 0.47f, 0.71f, 0.8f);
|
||||
shell.style.borderRightColor = new Color(0.3f, 0.47f, 0.71f, 0.8f);
|
||||
shell.style.borderTopColor = new Color(0.3f, 0.47f, 0.71f, 0.8f);
|
||||
shell.style.borderBottomColor = new Color(0.3f, 0.47f, 0.71f, 0.8f);
|
||||
shell.pickingMode = PickingMode.Position;
|
||||
root.Add(shell);
|
||||
|
||||
var lowerer = new EveUiToolkitSurfaceLowerer();
|
||||
shell.Add(lowerer.Lower(BuildZoneDetailsSurfaceDefinition(zone), HandleZoneDetailsSurfaceCommand));
|
||||
_zoneDetailsSurfaceDocument = AetheriaEveUnitySurfaceHost.RenderRuntime(
|
||||
transform,
|
||||
_zoneDetailsSurfaceDocument,
|
||||
"Aetheria Sector Zone Details Surface",
|
||||
AetheriaRuntimeZoneDetailsSurfaceBuilder.Build(ProjectZoneDetailsSurfaceState(zone)),
|
||||
HandleZoneDetailsSurfaceCommand,
|
||||
_zoneDetailsSurfaceChrome);
|
||||
}
|
||||
|
||||
private void HandleZoneDetailsSurfaceCommand(EveSurfaceCommandRequest request)
|
||||
{
|
||||
if (string.Equals(request.Command, CloseZoneDetailsCommand, StringComparison.Ordinal))
|
||||
if (!AetheriaRuntimeZoneDetailsSurfaceCommands.TryRead(request, out var command))
|
||||
{
|
||||
Debug.LogWarning($"Unknown sector-map zone details command: {request?.Command}");
|
||||
return;
|
||||
}
|
||||
|
||||
if (command.Kind == AetheriaRuntimeZoneDetailsCommandKind.Close)
|
||||
{
|
||||
HideZoneDetailsSurface();
|
||||
return;
|
||||
}
|
||||
|
||||
Debug.LogWarning($"Unknown sector-map zone details command: {request.Command}");
|
||||
Debug.LogWarning($"Unknown sector-map zone details command: {request?.Command}");
|
||||
}
|
||||
|
||||
private void HideZoneDetailsSurface()
|
||||
|
|
@ -146,27 +124,12 @@ public class SectorRenderer : MonoBehaviour, IBeginDragHandler, IDragHandler, IS
|
|||
if (_zoneDetailsSurfaceDocument == null)
|
||||
return;
|
||||
|
||||
_zoneDetailsSurfaceDocument.rootVisualElement.Clear();
|
||||
_zoneDetailsSurfaceDocument.gameObject.SetActive(false);
|
||||
AetheriaEveUnitySurfaceHost.Hide(_zoneDetailsSurfaceDocument);
|
||||
}
|
||||
|
||||
private UIDocument ResolveZoneDetailsSurfaceDocument()
|
||||
private AetheriaRuntimeZoneDetailsSurfaceState ProjectZoneDetailsSurfaceState(GalaxyZone zone)
|
||||
{
|
||||
if (_zoneDetailsSurfaceDocument != null)
|
||||
return _zoneDetailsSurfaceDocument;
|
||||
|
||||
var host = new GameObject("Aetheria Sector Zone Details Surface");
|
||||
host.transform.SetParent(transform, false);
|
||||
var document = host.AddComponent<UIDocument>();
|
||||
document.sortingOrder = 1000;
|
||||
host.SetActive(false);
|
||||
_zoneDetailsSurfaceDocument = document;
|
||||
return document;
|
||||
}
|
||||
|
||||
private EveSurfaceDocument BuildZoneDetailsSurfaceDefinition(GalaxyZone zone)
|
||||
{
|
||||
var density = saturate(ActionGameManager.CurrentGalaxy.Background.CloudDensity(zone.Position) / 2);
|
||||
var density = saturate(ActionGameManager.ObservedGalaxy.Background.CloudDensity(zone.Position) / 2);
|
||||
var radius = GameManager.Settings.ZoneSettings.ZoneRadius.Evaluate(density);
|
||||
var mass = GameManager.Settings.ZoneSettings.ZoneMass.Evaluate(density);
|
||||
var otherFactions = zone.Factions
|
||||
|
|
@ -175,135 +138,44 @@ public class SectorRenderer : MonoBehaviour, IBeginDragHandler, IDragHandler, IS
|
|||
.Where(name => !string.IsNullOrWhiteSpace(name))
|
||||
.ToArray();
|
||||
|
||||
var children = new List<EveSurfaceComponent>
|
||||
{
|
||||
Card(
|
||||
$"{ZoneDetailsSurfaceId}.card",
|
||||
zone.Name,
|
||||
Metric($"{ZoneDetailsSurfaceId}.owner", "Owner", zone.Owner?.Name ?? "None"),
|
||||
Metric($"{ZoneDetailsSurfaceId}.mass", "Mass", ActionGameManager.RuntimePlayerSettings.Format(mass)),
|
||||
Metric($"{ZoneDetailsSurfaceId}.radius", "Radius", ActionGameManager.RuntimePlayerSettings.Format(radius)))
|
||||
};
|
||||
|
||||
if (otherFactions.Length > 0)
|
||||
{
|
||||
children.Add(Text(
|
||||
$"{ZoneDetailsSurfaceId}.factions",
|
||||
$"Factions Present: {string.Join(", ", otherFactions)}"));
|
||||
}
|
||||
|
||||
if (zone.Contents == null)
|
||||
{
|
||||
children.Add(Text(
|
||||
$"{ZoneDetailsSurfaceId}.unvisited",
|
||||
"Has not been visited."));
|
||||
}
|
||||
else
|
||||
{
|
||||
var runtimeZone = zone.Contents;
|
||||
children.Add(Card(
|
||||
$"{ZoneDetailsSurfaceId}.contents",
|
||||
"Contents",
|
||||
Metric(
|
||||
$"{ZoneDetailsSurfaceId}.planets",
|
||||
"Planets",
|
||||
runtimeZone.PlanetInstances.Values.Count(body => !(body is GasGiant)).ToString()),
|
||||
Metric(
|
||||
$"{ZoneDetailsSurfaceId}.belts",
|
||||
"Asteroid Belts",
|
||||
runtimeZone.AsteroidBelts.Count.ToString()),
|
||||
Metric(
|
||||
$"{ZoneDetailsSurfaceId}.giants",
|
||||
"Gas Giants",
|
||||
runtimeZone.PlanetInstances.Values.Count(body => body is GasGiant && !(body is Sun)).ToString()),
|
||||
Metric(
|
||||
$"{ZoneDetailsSurfaceId}.stars",
|
||||
"Stars",
|
||||
runtimeZone.PlanetInstances.Values.Count(body => body is Sun).ToString()),
|
||||
Metric(
|
||||
$"{ZoneDetailsSurfaceId}.stations",
|
||||
"Stations",
|
||||
runtimeZone.Entities.Count(entity => HasHullType(entity, HullType.Station)).ToString()),
|
||||
Metric(
|
||||
$"{ZoneDetailsSurfaceId}.turrets",
|
||||
"Turrets",
|
||||
runtimeZone.Entities.Count(entity => HasHullType(entity, HullType.Turret)).ToString()),
|
||||
Metric(
|
||||
$"{ZoneDetailsSurfaceId}.ships",
|
||||
"Ships",
|
||||
runtimeZone.Entities.Count(entity => HasHullType(entity, HullType.Ship)).ToString())));
|
||||
return new AetheriaRuntimeZoneDetailsSurfaceState(
|
||||
zone.Name,
|
||||
zone.Owner?.Name ?? "None",
|
||||
ActionGameManager.RuntimePlayerSettings.Format(mass),
|
||||
ActionGameManager.RuntimePlayerSettings.Format(radius),
|
||||
otherFactions,
|
||||
hasContents: false,
|
||||
planets: "",
|
||||
asteroidBelts: "",
|
||||
gasGiants: "",
|
||||
stars: "",
|
||||
stations: "",
|
||||
turrets: "",
|
||||
ships: "",
|
||||
updatedAtUtc: DateTime.UtcNow.ToString("O"));
|
||||
}
|
||||
|
||||
children.Add(ButtonRow(
|
||||
$"{ZoneDetailsSurfaceId}.actions",
|
||||
Button($"{ZoneDetailsSurfaceId}.close", "Close", CloseZoneDetailsCommand)));
|
||||
|
||||
return new EveSurfaceDocument(
|
||||
ZoneDetailsSurfaceType,
|
||||
ZoneDetailsSurfaceSchema,
|
||||
ZoneDetailsSurfaceProviderId,
|
||||
ZoneDetailsSurfaceProviderKind,
|
||||
var runtimeZone = zone.Contents;
|
||||
return new AetheriaRuntimeZoneDetailsSurfaceState(
|
||||
zone.Name,
|
||||
version: 1,
|
||||
DateTime.UtcNow.ToString("O"),
|
||||
new EveSurfaceTree(
|
||||
ZoneDetailsSurfaceId,
|
||||
Node(
|
||||
$"{ZoneDetailsSurfaceId}.root",
|
||||
"surface",
|
||||
Array.Empty<(string Key, string Value)>(),
|
||||
children.ToArray()),
|
||||
Array.Empty<EveStyleToken>()),
|
||||
new[]
|
||||
{
|
||||
new EveCommandTemplate(CloseZoneDetailsCommand, "Close", "unity-uitoolkit")
|
||||
});
|
||||
zone.Owner?.Name ?? "None",
|
||||
ActionGameManager.RuntimePlayerSettings.Format(mass),
|
||||
ActionGameManager.RuntimePlayerSettings.Format(radius),
|
||||
otherFactions,
|
||||
hasContents: true,
|
||||
planets: runtimeZone.PlanetInstances.Values.Count(body => !(body is GasGiant)).ToString(),
|
||||
asteroidBelts: runtimeZone.AsteroidBelts.Count.ToString(),
|
||||
gasGiants: runtimeZone.PlanetInstances.Values.Count(body => body is GasGiant && !(body is Sun)).ToString(),
|
||||
stars: runtimeZone.PlanetInstances.Values.Count(body => body is Sun).ToString(),
|
||||
stations: runtimeZone.Entities.Count(entity => HasHullType(entity, HullType.Station)).ToString(),
|
||||
turrets: runtimeZone.Entities.Count(entity => HasHullType(entity, HullType.Turret)).ToString(),
|
||||
ships: runtimeZone.Entities.Count(entity => HasHullType(entity, HullType.Ship)).ToString(),
|
||||
updatedAtUtc: DateTime.UtcNow.ToString("O"));
|
||||
}
|
||||
|
||||
private static EveSurfaceComponent Card(
|
||||
string id,
|
||||
string title,
|
||||
params EveSurfaceComponent[] children)
|
||||
{
|
||||
return Node(id, "card", new[] { ("title", title) }, children);
|
||||
}
|
||||
|
||||
private static EveSurfaceComponent Metric(string id, string label, string value)
|
||||
{
|
||||
return Node(id, "metric", new[] { ("label", label), ("value", value) });
|
||||
}
|
||||
|
||||
private static EveSurfaceComponent Text(string id, string value)
|
||||
{
|
||||
return Node(id, "text", new[] { ("value", value) });
|
||||
}
|
||||
|
||||
private static EveSurfaceComponent Button(string id, string label, string command)
|
||||
{
|
||||
return Node(id, "control.button", new[] { ("label", label), ("command", command) });
|
||||
}
|
||||
|
||||
private static EveSurfaceComponent ButtonRow(
|
||||
string id,
|
||||
params EveSurfaceComponent[] children)
|
||||
{
|
||||
return Node(id, "row", Array.Empty<(string Key, string Value)>(), children);
|
||||
}
|
||||
|
||||
private static EveSurfaceComponent Node(
|
||||
string id,
|
||||
string kind,
|
||||
IEnumerable<(string Key, string Value)> props,
|
||||
params EveSurfaceComponent[] children)
|
||||
{
|
||||
return new EveSurfaceComponent(
|
||||
id,
|
||||
kind,
|
||||
props.ToDictionary(prop => prop.Key, prop => prop.Value, StringComparer.Ordinal),
|
||||
children ?? Array.Empty<EveSurfaceComponent>());
|
||||
}
|
||||
|
||||
// private IEnumerator AnimatePath()
|
||||
// private IEnumerator AnimatePath()
|
||||
// {
|
||||
// var pathZones = ActionGameManager.CurrentSector.ExitPath;
|
||||
// LegendPanel.SetActive(false);
|
||||
|
|
@ -358,7 +230,7 @@ public class SectorRenderer : MonoBehaviour, IBeginDragHandler, IDragHandler, IS
|
|||
{
|
||||
if (_zoneDetailsSurfaceDocument != null)
|
||||
{
|
||||
Destroy(_zoneDetailsSurfaceDocument.gameObject);
|
||||
AetheriaEveUnitySurfaceHost.DestroyDocument(_zoneDetailsSurfaceDocument);
|
||||
_zoneDetailsSurfaceDocument = null;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue