diff --git a/Controllers/HomeController.cs b/Controllers/HomeController.cs index cd00f48..f620c54 100644 --- a/Controllers/HomeController.cs +++ b/Controllers/HomeController.cs @@ -13,6 +13,7 @@ public class HomeController : Controller public static readonly string _inkJsonsDirectory = "/AppData/InkJsons/"; public static readonly string _rawInksDirectory = "/AppData/RawInks/"; private static readonly string _gameStatesDirectory = "/AppData/GameStates/"; + private static readonly string _permaplaysDirectory = "/Permaplays/"; //_rootPath is a filesystem path, for writing .ink/.jsons. _webAppPath is a URL modifier that is used instead of ~ (tilde, ofc, doesn't work with nginx) // tilde handling is under discussion: https://github.com/aspnet/Announcements/issues/57 doesn't quite look like this is speaking to my issue, though. @@ -25,16 +26,32 @@ public HomeController(Microsoft.Extensions.PlatformAbstractions.IApplicationEnvi _webAppPath = config["WebAppPath"]; } - public IActionResult Index() + public ViewResult Index() { ViewBag.SessionGuid = Guid.NewGuid(); ViewBag.WebAppPath = _webAppPath; return View(); } - public IActionResult ContinueStory(Guid sessionGuid, int? choiceIndex) + public ViewResult PlayOnly(string playId) { - string inkJsonPath = _rootPath + _inkJsonsDirectory + sessionGuid + ".json"; + ViewBag.SessionGuid = Guid.NewGuid(); + ViewBag.WebAppPath = _webAppPath; + ViewBag.PlayId = playId; + + //make sure it's a valid path. + string inkPath = _rootPath + _permaplaysDirectory + playId + ".json"; + ViewBag.InkFileExists = System.IO.File.Exists(inkPath); + + return View(); + } + + public JsonResult ContinueStory(Guid sessionGuid, string playId, int? choiceIndex) + { + //if we have a playId, this is a permaplay story, and we load it from permaplays insetad of inkJsons. + string inkJsonPath = string.IsNullOrEmpty(playId) + ? _rootPath + _inkJsonsDirectory + sessionGuid + ".json" + : _rootPath + _permaplaysDirectory + playId + ".json"; string gameStatePath = _rootPath + _gameStatesDirectory + sessionGuid + ".json"; //if no choices at all, this means we're starting a new story. @@ -53,7 +70,18 @@ public IActionResult ContinueStory(Guid sessionGuid, int? choiceIndex) return Json(outputs); } - public IActionResult PlayInk(string inktext, Guid sessionGuid) + private JsonResult StartNewStory(string inkJsonPath, string gameStatePath) + { + var story = Models.InkMethods.LoadEmptyStory(inkJsonPath); + + List outputs = InkMethods.GetStoryOutputMessages(story); + + InkMethods.SaveStory(gameStatePath, story); + + return Json(outputs); + } + + public JsonResult PlayInk(string inktext, Guid sessionGuid) { try { @@ -91,7 +119,7 @@ public IActionResult PlayInk(string inktext, Guid sessionGuid) { try { - var errors = GetInklecateErrors(x.Message); + var errors = GetInklecateErrors(x.Message); return Json(new { errors = errors }); } //MWCTODO: this means GetInklecateErrors() threw a new exception, should also write to the internal log (figure out the RC2 way of doing this) @@ -153,17 +181,5 @@ private void AddCateError(string errorMessage, int start, int end, Regex re, ref errs.Add(new CateError() { Message = msg, LineNumber = line }); } - private IActionResult StartNewStory(string inkJsonPath, string gameStatePath) - { - var story = Models.InkMethods.LoadEmptyStory(inkJsonPath); - - List outputs = InkMethods.GetStoryOutputMessages(story); - - InkMethods.SaveStory(gameStatePath, story); - - return Json(outputs); - } - - } } diff --git a/Models/InkModels.cs b/Models/InkModels.cs index aa86fe0..f76c913 100644 --- a/Models/InkModels.cs +++ b/Models/InkModels.cs @@ -42,7 +42,10 @@ public static List GetStoryOutputMessages(Story story) { outputs.Add(new InkOutputMessage() { MessageType = InkOutputMessageTypes.Text, OutputText = story.Continue() }); } + outputs.AddRange(story.currentChoices.Select(c => new InkOutputMessage() { MessageType = InkOutputMessageTypes.Choice, ChoiceIndex = c.index, OutputText = c.text })); + + outputs = outputs.Select(o => { o.OutputText = System.Net.WebUtility.HtmlEncode(o.OutputText); return o; }).ToList(); return outputs; } diff --git a/Startup.cs b/Startup.cs index 26934f2..b46db65 100644 --- a/Startup.cs +++ b/Startup.cs @@ -49,6 +49,11 @@ public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerF app.UseMvc(routes => { + routes.MapRoute( + "perma", + "play/{playId}", + new { controller = "Home", action = "PlayOnly" } + ); routes.MapRoute( name: "default", template: "{controller=Home}/{action=Index}/{id?}"); diff --git a/Views/Home/PlayOnly.cshtml b/Views/Home/PlayOnly.cshtml new file mode 100644 index 0000000..5b29da1 --- /dev/null +++ b/Views/Home/PlayOnly.cshtml @@ -0,0 +1,89 @@ +@{ + string webAppPath = ViewBag.WebAppPath == null ? "/" : (string)ViewBag.WebAppPath; +} + +
+
+
+

Welcome! Enjoy playing the story. If you'd like to try writing one of your own, see the main Quill page.

+
+
+
+
+
+
+
+
+ +
+
+
+ +@section scripts { + + +}