|
|
|
|
|
|
|
|
using System;
|
|
|
using System.Collections.Generic;
|
|
|
using System.Text.RegularExpressions;
|
|
|
using System.Linq;
|
|
|
|
|
|
using Microsoft.Xna.Framework;
|
|
|
|
|
|
using isometricparkfna.Messages;
|
|
|
using isometricparkfna.Components;
|
|
|
using static isometricparkfna.CellMap;
|
|
|
using isometricparkfna.UI;
|
|
|
|
|
|
using Encompass;
|
|
|
using TraceryNet;
|
|
|
using Ink.Runtime;
|
|
|
|
|
|
|
|
|
namespace isometricparkfna.Spawners {
|
|
|
|
|
|
[Reads(typeof(DialogComponent))]
|
|
|
[Receives(typeof(SpawnDialogMessage))]
|
|
|
class DialogSpawner : Spawner<SpawnDialogMessage>
|
|
|
|
|
|
{
|
|
|
Story Story;
|
|
|
Grammar Grammar;
|
|
|
|
|
|
public DialogSpawner(Story story, Grammar grammar)
|
|
|
{
|
|
|
this.Story = story;
|
|
|
this.Grammar = grammar;
|
|
|
}
|
|
|
|
|
|
protected override void Spawn(in SpawnDialogMessage message)
|
|
|
{
|
|
|
Logging.Spy(this.Story.currentChoices.Count(), "Count");
|
|
|
Logging.Spy(this.Story.canContinue, "CanContinue");
|
|
|
//If there are no existing dialog:
|
|
|
if(ReadEntities<DialogComponent>().Length == 0
|
|
|
&& this.Story.currentChoices.Count() == 0
|
|
|
&& !this.Story.canContinue)
|
|
|
{
|
|
|
Logging.Debug("Creating and hydrating new Dialog.");
|
|
|
//Jump to the specified part of the story:
|
|
|
Story.ChoosePathString(message.Path);
|
|
|
|
|
|
var newDialog = CreateEntity();
|
|
|
var continuation = this.Story.ContinueMaximally();
|
|
|
|
|
|
var parts = Regex.Split(continuation, ":", 0);
|
|
|
var speaker = (parts.Length == 2) ? parts[0] : "";
|
|
|
var dialog = (parts.Length == 2) ? parts[1] : continuation;
|
|
|
|
|
|
AddComponent(newDialog, new DialogComponent {
|
|
|
Knot = message.Path,
|
|
|
CurrentDialog = this.Grammar.Flatten(dialog),
|
|
|
CurrentSpeaker = this.Grammar.Flatten(speaker),
|
|
|
Options = this.Story.currentChoices
|
|
|
.Select(option => option.text)
|
|
|
.ToList()});
|
|
|
|
|
|
AddComponent(newDialog, new WindowTypeComponent {
|
|
|
type = Window.Dialog});
|
|
|
AddComponent(newDialog,
|
|
|
new VisibilityComponent{ visible = true});
|
|
|
|
|
|
Logging.Success("Spawned new dialog.");
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
|
|
|
Logging.Debug("Creating new Dialog without hydrating.");
|
|
|
var newDialog = CreateEntity();
|
|
|
AddComponent(newDialog, new DialogComponent {
|
|
|
Knot = message.Path});
|
|
|
AddComponent(newDialog, new WindowTypeComponent {
|
|
|
type = Window.Dialog});
|
|
|
AddComponent(newDialog,
|
|
|
new VisibilityComponent{ visible = true});
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
|