From 913faf3c9f594d5d716be26cac7a0e42f7d7bc80 Mon Sep 17 00:00:00 2001 From: soul Date: Thu, 3 Dec 2026 21:34:24 +0100 Subject: [PATCH] Subtract dead Narrative subsystem and unused SavedStory --- .../Scripts/ServerShared/EntitySerializer.cs | 7 - Assets/Scripts/ServerShared/Narrative.meta | 3 - .../ServerShared/Narrative/StoryProcessor.cs | 244 ------------------ .../Narrative/StoryProcessor.cs.meta | 3 - .../ServerShared/Narrative/ZoneConstraints.cs | 89 ------- .../Narrative/ZoneConstraints.cs.meta | 3 - .../ServerShared/Narrative/ZoneSelectors.cs | 51 ---- .../Narrative/ZoneSelectors.cs.meta | 3 - 8 files changed, 403 deletions(-) delete mode 100644 Assets/Scripts/ServerShared/Narrative.meta delete mode 100644 Assets/Scripts/ServerShared/Narrative/StoryProcessor.cs delete mode 100644 Assets/Scripts/ServerShared/Narrative/StoryProcessor.cs.meta delete mode 100644 Assets/Scripts/ServerShared/Narrative/ZoneConstraints.cs delete mode 100644 Assets/Scripts/ServerShared/Narrative/ZoneConstraints.cs.meta delete mode 100644 Assets/Scripts/ServerShared/Narrative/ZoneSelectors.cs delete mode 100644 Assets/Scripts/ServerShared/Narrative/ZoneSelectors.cs.meta diff --git a/Assets/Scripts/ServerShared/EntitySerializer.cs b/Assets/Scripts/ServerShared/EntitySerializer.cs index 5495dee97..f201ed3ad 100644 --- a/Assets/Scripts/ServerShared/EntitySerializer.cs +++ b/Assets/Scripts/ServerShared/EntitySerializer.cs @@ -208,13 +208,6 @@ public static class EntitySerializer } } -[MessagePackObject] -public class SavedStory -{ - [Key(0)] public string StoryJson; - [Key(1)] public string StateJson; -} - [MessagePackObject] public class ShipPack : EntityPack { diff --git a/Assets/Scripts/ServerShared/Narrative.meta b/Assets/Scripts/ServerShared/Narrative.meta deleted file mode 100644 index 1722d6ee5..000000000 --- a/Assets/Scripts/ServerShared/Narrative.meta +++ /dev/null @@ -1,3 +0,0 @@ -fileFormatVersion: 2 -guid: 5ed144b07bdd45089df886ea901ea366 -timeCreated: 1619469268 \ No newline at end of file diff --git a/Assets/Scripts/ServerShared/Narrative/StoryProcessor.cs b/Assets/Scripts/ServerShared/Narrative/StoryProcessor.cs deleted file mode 100644 index e36545e38..000000000 --- a/Assets/Scripts/ServerShared/Narrative/StoryProcessor.cs +++ /dev/null @@ -1,244 +0,0 @@ - -using System; -using System.Collections.Generic; -using System.IO; -using System.Linq; -using Ink; -using Ink.Parsed; -using MessagePack; -using Path = System.IO.Path; -using Random = CultMath.Random; -using Story = Ink.Runtime.Story; - -public class StoryProcessor : IZoneResolver, IFactionResolver -{ - private class AetheriaInkFileHandler : IFileHandler { - private DirectoryInfo NarrativeRoot { get; } - - public AetheriaInkFileHandler(DirectoryInfo narrativeRoot) - { - NarrativeRoot = narrativeRoot; - } - - public string ResolveInkFilename (string includeName) => Path.Combine (NarrativeRoot.FullName, includeName); - - public string LoadInkFileContents (string fullFilename) => File.ReadAllText (fullFilename); - } - - private Dictionary _storyKnotPaths = new Dictionary(); - private Dictionary _placedStories = new Dictionary(); - private Dictionary _processedStories = new Dictionary(); - private DirectoryInfo _locationsPath; - private DirectoryInfo _questsPath; - private IFileHandler _inkFileHandler; - public DirectoryInfo NarrativeDirectory { get; } - private Random _random; - public Galaxy Galaxy { get; } - public PlayerSettings Settings { get; } - - private Action Log { get; } - - public StoryProcessor(PlayerSettings settings, DirectoryInfo narrativeDirectory, Galaxy galaxy, ref Random random, Action log) - { - NarrativeDirectory = narrativeDirectory; - Galaxy = galaxy; - _random = random; - Log = log; - Settings = settings; - - _inkFileHandler = new AetheriaInkFileHandler(narrativeDirectory); - - _locationsPath = narrativeDirectory.CreateSubdirectory("Locations"); - _questsPath = narrativeDirectory.CreateSubdirectory("Quests"); - } - - public void ProcessStories() - { - var locationFiles = _locationsPath.EnumerateFiles("*.ink"); - foreach(var inkFile in locationFiles) - { - Log($"Processing story file at {inkFile.FullName}"); - ProcessLocation(GetStory(inkFile), inkFile); - } - - var questFiles = _questsPath.EnumerateFiles("*ink"); - foreach(var inkFile in questFiles) ProcessQuest(GetStory(inkFile), inkFile); - } - - public GalaxyZone ResolveZone(string path) - { - // Handle special cases: "start" and "end" - if (path.Equals("start", StringComparison.InvariantCultureIgnoreCase)) - return Galaxy.Entrance; - if (path.Equals("end", StringComparison.InvariantCultureIgnoreCase)) - return Galaxy.Exit; - - // Handle faction home reference: format = "home." - if(path.StartsWith("home")) - { - var factionString = path.Substring(5); - var faction = ResolveFaction(factionString); - return !Galaxy.HomeZones.ContainsKey(faction) ? null : Galaxy.HomeZones[faction]; - } - - return ResolveLocation(path)?.Zone; - } - - public LocationStory ResolveLocation(string path) - { - var locationInkFile = new FileInfo(Path.Combine(_locationsPath.FullName, $"{path}.ink")); - if (!locationInkFile.Exists) return null; - - var story = GetStory(locationInkFile); - ProcessLocation(story, locationInkFile); - return _placedStories.ContainsKey(story) ? _placedStories[story] : null; - } - - public Faction ResolveFaction(string name) - { - return Galaxy.Factions.FirstOrDefault(f => f.Name.StartsWith(name, StringComparison.InvariantCultureIgnoreCase)); - } - - Story GetStory(FileInfo inkFile) - { - var fileName = Path.GetFileNameWithoutExtension(inkFile.FullName); - - // If the story has already been read / compiled, return it directly - if (_processedStories.ContainsKey(fileName)) return _processedStories[fileName]; - - var compiler = new Compiler(File.ReadAllText(inkFile.FullName), new Compiler.Options - { - countAllVisits = true, - fileHandler = _inkFileHandler - }); - var story = compiler.Compile(); - var knots = compiler.parsedStory.FindAll().Select(k=>k.runtimePath.ToString()).ToArray(); - _storyKnotPaths[story] = knots; - //File.WriteAllText(compiledFileName, story.ToJson()); - _processedStories[fileName] = story; - return story; - } - - public void ProcessQuest(Story story, FileInfo inkFile) - { - var fileName = Path.GetFileNameWithoutExtension(inkFile.FullName); - var quest = new GalaxyQuest(); - quest.Story = story; - foreach (var knot in _storyKnotPaths[story]) - { - var tags = story.TagsForContentAtPath(knot); - if(tags==null) continue; - var contentTags = GetContentTags(tags); - if (contentTags.ContainsKey("location")) - { - var locationName = contentTags["location"].First(); - var locationStory = ResolveLocation(locationName); - if (tags.Contains("required") && locationStory == null) - { - Log($"Quest \"{fileName}\" unable to find required location \"{locationName}\" for knot \"{knot}\""); - return; - } - quest.KnotLocations[knot] = locationStory; - } - } - - foreach (var x in quest.KnotLocations) - { - if (!x.Value.KnotQuests.ContainsKey(x.Key)) x.Value.KnotQuests[x.Key] = new List(); - x.Value.KnotQuests[x.Key].Add(quest); - } - } - - public void ProcessLocation(Story story, FileInfo inkFile) - { - if (_placedStories.ContainsKey(story)) return; // Don't place already placed stories, idiot! - _placedStories[story] = null; // Avoids potential for infinite loops when evaluating constraints - var fileName = Path.GetFileNameWithoutExtension(inkFile.FullName); - - var contentTags = GetContentTags(story.globalTags); - - var constraints = new List(); - if(contentTags.ContainsKey("constraint")) - foreach (var constraintString in contentTags["constraint"]) - { - var args = constraintString.Split(' '); - var flip = args[0] == "not"; - if (flip) args = args.Skip(1).ToArray(); - var constraintName = args[0]; - args = args.Skip(1).ToArray(); - ZoneConstraint constraint = constraintName switch - { - "DistanceFrom" => new DistanceConstraint(args, this) { Flip = flip }, - "FactionPresent" => new FactionPresenceConstraint(args, this) { Flip = flip }, - "FactionOwner" => new FactionOwnerConstraint(args, this) { Flip = flip }, - _ => null - }; - if(constraint!=null) constraints.Add(constraint); - } - - ZoneSelector selector; - if (contentTags.ContainsKey("select")) - { - var selectorString = contentTags["select"].First(); - var args = selectorString.Split(' '); - var flip = args[0] == "not"; - if (flip) args = args.Skip(1).ToArray(); - var selectorName = args[0]; - args = args.Skip(1).ToArray(); - selector = selectorName switch - { - "DistanceFrom" => new DistanceSelector(args, this) { Flip = flip }, - _ => new RandomSelector(ref _random) - }; - } - else - selector = new RandomSelector(ref _random); - - var zoneCandidates = new List(); - zoneCandidates.AddRange(Galaxy.Zones.Where(z=>!z.NamedZone && constraints.All(c=>c.Test(z)))); - - var zone = selector.SelectZone(zoneCandidates); - - var location = new LocationStory - { - Zone = zone, - FileName = fileName, - Name = contentTags.ContainsKey("name") ? contentTags["name"].First() : fileName, - Faction = contentTags.ContainsKey("faction") ? ResolveFaction(contentTags["faction"].First()) : zone.Owner, - Security = contentTags.ContainsKey("security") - ? (SecurityLevel) Enum.Parse(typeof(SecurityLevel), contentTags["security"].First(), true) - : SecurityLevel.Open, - Story = story, - Type = contentTags.ContainsKey("type") - ? (LocationType) Enum.Parse(typeof(LocationType), contentTags["type"].First(), true) - : LocationType.Station, - Turrets = contentTags.ContainsKey("turrets") ? int.Parse(contentTags["turrets"].First()) : 0 - }; - zone.Locations.Add(location); - - if (contentTags.ContainsKey("namezone")) - { - zone.Name = contentTags["namezone"].First(); - } - - _placedStories[story] = location; - } - - // Parse all tags of the format X:Y into a dictionary with a list of every Y for each X - public static Dictionary> GetContentTags(List tags) - { - var contentTags = new Dictionary>(); - foreach (var tag in tags) - { - if (tag.IndexOf(':') == -1) continue; - - var tokens = tag.Split(':'); - var leftSide = tokens[0].Trim().ToLowerInvariant(); - var rightSide = tokens[1].Trim(); - if (!contentTags.ContainsKey(leftSide)) contentTags[leftSide] = new List(); - contentTags[leftSide].Add(rightSide); - } - - return contentTags; - } -} \ No newline at end of file diff --git a/Assets/Scripts/ServerShared/Narrative/StoryProcessor.cs.meta b/Assets/Scripts/ServerShared/Narrative/StoryProcessor.cs.meta deleted file mode 100644 index 409e3c0eb..000000000 --- a/Assets/Scripts/ServerShared/Narrative/StoryProcessor.cs.meta +++ /dev/null @@ -1,3 +0,0 @@ -fileFormatVersion: 2 -guid: 40906e10d0c24af688d9f300548a3066 -timeCreated: 1619469326 \ No newline at end of file diff --git a/Assets/Scripts/ServerShared/Narrative/ZoneConstraints.cs b/Assets/Scripts/ServerShared/Narrative/ZoneConstraints.cs deleted file mode 100644 index 4c3d52688..000000000 --- a/Assets/Scripts/ServerShared/Narrative/ZoneConstraints.cs +++ /dev/null @@ -1,89 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; - -public interface IZoneResolver -{ - public GalaxyZone ResolveZone(string path); -} - -public interface IFactionResolver -{ - public Faction ResolveFaction(string name); -} - -public abstract class ZoneConstraint -{ - public bool Flip = false; - - public bool Test(GalaxyZone zone) - { - return Flip ^ TestZone(zone); - } - - protected abstract bool TestZone(GalaxyZone zone); -} - -public class FactionPresenceConstraint : ZoneConstraint -{ - private Faction TargetFaction { get; } - public FactionPresenceConstraint(string[] args, IFactionResolver resolver) - { - TargetFaction = resolver.ResolveFaction(args[0]); - } - - protected override bool TestZone(GalaxyZone zone) - { - return zone.Factions.Any(f => f == TargetFaction); - } -} - -public class FactionOwnerConstraint : ZoneConstraint -{ - private Faction TargetFaction { get; } - - public FactionOwnerConstraint(string[] args, IFactionResolver resolver) - { - TargetFaction = resolver.ResolveFaction(args[0]); - } - - protected override bool TestZone(GalaxyZone zone) - { - return TargetFaction != null && zone.Owner == TargetFaction; - } -} - -public class DistanceConstraint : ZoneConstraint -{ - private GalaxyZone _targetZone; - private Predicate _test; - - public DistanceConstraint(string[] args, IZoneResolver zoneResolver) - { - if (args.Length == 3) - { - _targetZone = zoneResolver.ResolveZone(args[0].Trim()); - if (!int.TryParse(args[2], out var v)) _test = _ => false; - else - { - var trimmed = args[1].Trim(); - _test = trimmed switch - { - "<" => i => i < v, - ">" => i => i > v, - "=" => i => i == v, - _ => _ => false - }; - } - } - else - { - _test = _ => false; - } - } - - protected override bool TestZone(GalaxyZone zone) - { - return _targetZone != null && _test(zone.Distance[_targetZone]); - } -} diff --git a/Assets/Scripts/ServerShared/Narrative/ZoneConstraints.cs.meta b/Assets/Scripts/ServerShared/Narrative/ZoneConstraints.cs.meta deleted file mode 100644 index 899410696..000000000 --- a/Assets/Scripts/ServerShared/Narrative/ZoneConstraints.cs.meta +++ /dev/null @@ -1,3 +0,0 @@ -fileFormatVersion: 2 -guid: e5dcf761c4ab4b0ca8a477daec28b35f -timeCreated: 1619128088 \ No newline at end of file diff --git a/Assets/Scripts/ServerShared/Narrative/ZoneSelectors.cs b/Assets/Scripts/ServerShared/Narrative/ZoneSelectors.cs deleted file mode 100644 index ca88ea52b..000000000 --- a/Assets/Scripts/ServerShared/Narrative/ZoneSelectors.cs +++ /dev/null @@ -1,51 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using MessagePack; -using Random = CultMath.Random; - -public abstract class ZoneSelector -{ - public abstract GalaxyZone SelectZone(List candidates); -} - -public abstract class OrderedZoneSelector : ZoneSelector -{ - public bool Flip = false; - - protected abstract Func Comparison { get; } - - public override GalaxyZone SelectZone(List candidates) - { - var sorted = candidates.OrderBy(Comparison); - return Flip ? sorted.Last() : sorted.First(); - } -} - -public class DistanceSelector : OrderedZoneSelector -{ - private GalaxyZone Target { get; } - - - public DistanceSelector(string[] args, IZoneResolver zoneResolver) - { - Target = zoneResolver.ResolveZone(args[0].Trim()); - } - - protected override Func Comparison => zone => Target?.Distance[zone] ?? 0; -} - -public class RandomSelector : ZoneSelector -{ - private Random Random { get; } - - public RandomSelector(ref Random random) - { - Random = random; - } - - public override GalaxyZone SelectZone(List candidates) - { - return candidates[Random.NextInt(candidates.Count)]; - } -} \ No newline at end of file diff --git a/Assets/Scripts/ServerShared/Narrative/ZoneSelectors.cs.meta b/Assets/Scripts/ServerShared/Narrative/ZoneSelectors.cs.meta deleted file mode 100644 index 1559e31bd..000000000 --- a/Assets/Scripts/ServerShared/Narrative/ZoneSelectors.cs.meta +++ /dev/null @@ -1,3 +0,0 @@ -fileFormatVersion: 2 -guid: 917c5a50cc724463bfce61429b4b661e -timeCreated: 1619133153 \ No newline at end of file