Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor script preloading #505

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
18 commits
Select commit Hold shift + click to select a range
f887f7e
refactor: refactored script preloading to account for missing functio…
PhoebeMitchell Nov 16, 2024
7c32259
refactor: changed investigation to use object preloading
PhoebeMitchell Nov 17, 2024
8d59f0d
refactor: Extract move menu events
PhoebeMitchell Nov 17, 2024
6bbb594
refactor: Changed Texture2D to Sprite
PhoebeMitchell Nov 17, 2024
92faaac
feat: Added validation for investigation move tags
PhoebeMitchell Nov 17, 2024
8e8e3bf
test: Added stitch parsing test
PhoebeMitchell Nov 17, 2024
760036f
bugfix: Fix broken reference in Editor
PhoebeMitchell Nov 17, 2024
c8c978d
test: Added test cases for NarrativeScript
PhoebeMitchell Nov 18, 2024
707433f
bugfix: Fixed empty lines causing errors
PhoebeMitchell Nov 18, 2024
e344ba4
bugfix: Fixed bug where multiple tunnels could not contain choices
PhoebeMitchell Nov 18, 2024
c2c6040
test: added background tag test
PhoebeMitchell Nov 18, 2024
f57c878
bugfix: removed roque using statement
PhoebeMitchell Nov 18, 2024
45fcc8d
feat: More informative error message for missing background tag
PhoebeMitchell Nov 19, 2024
82fa118
Update unity-ggjj/Assets/Scripts/NarrativeScript/MissingBackgroundTag…
PhoebeMitchell Nov 20, 2024
0c236d3
Update unity-ggjj/Assets/Scripts/NarrativeScript/NarrativeScript.cs
PhoebeMitchell Nov 20, 2024
2d8a439
refactor: Inverted if statement
PhoebeMitchell Nov 20, 2024
724c0a5
refactor: Removed redundant code
PhoebeMitchell Nov 20, 2024
62e1dc3
refactor: Changed GetTagValue method to return null if no tag value f…
PhoebeMitchell Nov 20, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 24 additions & 3 deletions unity-ggjj/Assets/Editor/Ink/Validation.cs
Original file line number Diff line number Diff line change
Expand Up @@ -54,17 +54,24 @@ private static void FindAndReportErrorsForFiles(IEnumerable<InkFile> inkFiles)
private static IEnumerable<string> FindErrorsInFile(InkFile inkFile)
{
var errors = new List<string>();
var lines = new List<string>();

if (inkFile.jsonAsset == null)
{
return Array.Empty<string>();
}

var story = new Story(inkFile.jsonAsset.text);
NarrativeScript.ReadContent(story.mainContentContainer.content, lines, story);
var storyData = ReadStoryContent(story, errors, inkFile);

foreach (var line in lines.Where(t => t[0] == ActionDecoderBase.ACTION_TOKEN))
if (errors.Any())
{
return errors;
}

var actions = storyData.DistinctActions
.Concat(storyData.DistinctMoveTags.Select(tag => $"{ActionDecoderBase.ACTION_TOKEN}SCENE:{tag}"));

foreach (var line in actions)
{
try
{
Expand All @@ -78,5 +85,19 @@ private static IEnumerable<string> FindErrorsInFile(InkFile inkFile)

return errors;
}

private static StoryData ReadStoryContent(Story story, List<string> errors, InkFile inkFile)
{
try
{
return NarrativeScript.ReadContent(story);
}
catch (MissingBackgroundTagException exception)
{
errors.Add($"Error in {inkFile.jsonAsset.name}\n{exception.Message}.");
}

return new StoryData();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,174 +16,7 @@
&PLAY_SONG:PrologueInPMinor,4
&FADE_IN:6
&WAIT:0.5
&SPEAK:Laura
Oh my GAAAAD… Those chicken nuggets aren't yooooours!

&SHAKE_SCREEN:0.25,0.2
&PLAY_SFX:stab
&SPEAK_UNKNOWN:Tutorial_Boy
&ACTOR:Tutorial_Boy
...

&ACTOR:Laura
&SPEAK:Laura
&SET_POSE:Sweaty
I-I gotta report thiiis… it's my jooooob…

&SPEAK_UNKNOWN:Tutorial_Boy
&ACTOR:Tutorial_Boy
You won't tell a soul about this…
&SET_POSE:Angry
Because otherwise…
I'll tell EVERYBODY about what YOU did…!

&PLAY_SFX:RossEvilLaugh
&SET_POSE:Confident
&WAIT:0.7
&FADE_OUT_SONG:2
&FADE_OUT:2
&HIDE_TEXTBOX

//---------------------------------------[Game Grumps Office]------------------------------------------//
&SCENE:Office
&HIDE_ACTOR
&ACTOR:Arin
&WAIT:1.5
&PLAY_SONG:turnaboutGrumpsters,2.5
&FADE_IN:2

&THINK:Arin
&SET_POSE:Thinking
<color=\#2064e3>(Wow, what a day of laywerin'. Who could have guessed that Thomas the 18th Century Boy was killed by his own father?)
&THINK:Arin
<color=\#2064e3>(I never could have guessed you had to go to court for things other than dino related crimes.)
&PLAY_ANIMATION:Blink
&PLAY_SFX:lightbulb
&WAIT:0.1
&SCENE:Office
&THINK:Arin
&SET_POSE:normal
<color=\#2064e3>(All this work has got me starved. Luckily it's almost 4<link=character>:</link>30 already!)
&THINK:Arin
&SET_POSE:Confident
<color=\#2064e3>(Time go home, load up on carbohydrates, and lose another Magic game!)

&SHAKE_SCREEN:0.55,0.5
&PLAY_SFX:damage2
&STOP_SONG
&SPEAK_UNKNOWN:Dan
&SET_POSE:ShockAnimation
ARIN!! IT'S ALL GONE TO SHIT!!

&SPEAK:Arin
Uh... What?

&SHOW_ACTOR
&ACTOR:Dan
&SPEAK:Dan
&SET_POSE:Angry
&PLAY_SFX:shock2
&PLAY_SONG:Prelude6969,1
&SHAKE_SCREEN:0.4,0.4
It's all gone to shit! There's <color=\#d10a1e>a goddamn thief</color> in the building!

&PLAY_ANIMATION:Blink
&SCENE:Office
&SHAKE_SCREEN:0.25,0.25
&PLAY_SFX:stab2
&THINK:Arin
A thief? Did we get robbed?!

&SPEAK:Dan
&SET_POSE:Angry
&PLAY_SFX:Smack
&SHAKE_SCREEN:0.25,0.4
//TODO:Change to italics "I" once able
<color=\#d10a1e>I got robbed</color>, Arin! I was cooking up some snacks in the kitchen and stepped out just for a minute…
&SET_POSE:SideNormal
&PLAY_ANIMATION:Blink
&SCENE:Office
And when I came back,
&PLAY_SFX:realization
&CONTINUE_DIALOGUE
<color=\#d10a1e>my dino nuggies were stolen!

&PLAY_ANIMATION:Blink
&SCENE:Office
&THINK:Arin
&PLAY_SFX:realization
<color=\#d10a1e>Your dino nuggies were stolen?!

&SPEAK:Dan
&SET_POSE:Angry
Yeah,
&PLAY_SFX:realization
&CONTINUE_DIALOGUE
<color=\#d10a1e>my dino nuggies were stolen</color>.
Hear the plot point bells going off?

&THINK:Arin
Alright, alright, don't get meta this early in the game. Just tell me exactly what happened.

&SHAKE_SCREEN:0.25,0.25
&PLAY_SFX:damage1
&SPEAK:Dan
It's as I said, man: I was hungry, so I decided to heat up some of those frozen <color=\#d10a1e>dinosaur-shaped chicken nuggets</color> we have in the freezer.
&SET_POSE:Normal
It has to heat up for a while, and then you have to let it cool for even longer, so I decided to leave them to cook for about <color=\#d10a1e>ten minutes</color>.

&THINK:Arin
Seriously? That long? For frozen chicken?

&SPEAK:Dan
This is chicken on another level, Arin. First time it burned me HARD!
&SET_POSE:AirGuitar
I'm talking hotter than the new NSP album.

&THINK:Arin
Ha, nice plug.

&SET_POSE:Normal
&SPEAK:Dan
Anyway, I came back in and they were totally gone! The plate was still in the microwave, the cutlery was still there… but the nuggets had vanished!

&THINK:Arin
Did you, uh… look properly?

&SHAKE_SCREEN:0.25,0.3
&PLAY_SFX:stab2
&SPEAK:Dan
&SET_POSE:Angry
Of course I looked properly! Food doesn't just grow legs and walk off, Arin!

&PLAY_ANIMATION:Blink
&SCENE:Office
&THINK:Arin
&PLAY_SFX:lightbulb
Uh, Burgie did? And don't dino nuggies have legs already?

&SET_POSE:Lean
&WAIT:1.5
&SPEAK:Dan
&SET_POSE:Angry
…Okay. Yeah. You got me there. Very true.
&SHAKE_SCREEN:0.25,0.4
&PLAY_SFX:smack
&SET_POSE:Normal
But these dino nuggies weren't showing ANY signs of becoming sentient! There were crumbs on the plate; <color=\#d10a1e>someone</color> definitely ate them!
&SET_POSE:Angry
You gotta help me track down this chicken crook, man. I've been looking forward to these nuggies since I put them in the microwave.

&THINK:Arin
<color=\#2064e3>(Dang, guess the pizza and deck-building has to wait. Ain't no way I can let my bro down.)
Alright, Dan! Let's get this thief that's run… a-fowl!

&SET_POSE:Normal
&SPEAK:Dan
Real smooth, Arin. Not your greatest, but I'll take it.
We should check out the scene of the crime first. We might be able to find some clues that'll lead us to our guy.
&SET_POSE:AirGuitar
&PLAY_SFX:Damage1
Then…we cluck up that son-of-a-bitch.
&SET_POSE:Normal

Expand Down

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion unity-ggjj/Assets/Scenes/Game.unity
Original file line number Diff line number Diff line change
Expand Up @@ -13416,7 +13416,7 @@ MonoBehaviour:
_examinationKnownEvidence: {fileID: 2800000, guid: 6ca44d6afef844a27a9e66de26fdd092, type: 3}
_investigationTalkMenu: {fileID: 9193169995552675240}
_investigationMoveMenu: {fileID: 5938212526735672947}
_unestablishedSceneBackground: {fileID: 2800000, guid: cbc4be33b343c4c71b9d485d9ba55181, type: 3}
_unestablishedSceneBackground: {fileID: 21300000, guid: cbc4be33b343c4c71b9d485d9ba55181, type: 3}
_investigationEvidenceMenuOpener: {fileID: 6204405884193036418}
--- !u!222 &8421670506926057477
CanvasRenderer:
Expand Down
4 changes: 3 additions & 1 deletion unity-ggjj/Assets/Scripts/GameState/ChoiceExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ public static class ChoiceExtensions
{
public static string GetTagValue(this Choice choice, string key)
{
return choice.tags.First(choiceTags => choiceTags.StartsWith(key+":")).Split(':')[1];
return choice.tags
.FirstOrDefault(choiceTags => choiceTags.StartsWith(key+":"))?
.Split(':')[1];
}
}
96 changes: 54 additions & 42 deletions unity-ggjj/Assets/Scripts/GameState/InvestigationState.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
Expand All @@ -9,6 +10,9 @@

public class InvestigationState : MonoBehaviour, IInvestigationState
{
public const string ID_TAG_KEY = "id";
public const string BACKGROUND_TAG_KEY = "background";

[SerializeField] private MenuOpener _investigationMainMenuOpener;
[SerializeField] private NarrativeGameState _narrativeGameState;
[SerializeField] private InputManager _inputManager;
Expand Down Expand Up @@ -92,7 +96,7 @@ public void QuitExamination()
[Header("Talk + Move")]
[SerializeField] private ChoiceMenu _investigationTalkMenu;
[SerializeField] private InvestigationChoiceMenu _investigationMoveMenu;
[SerializeField] private Texture2D _unestablishedSceneBackground;
[SerializeField] private Sprite _unestablishedSceneBackground;

private List<Choice> _talkOptions;
private List<Choice> _moveOptions;
Expand Down Expand Up @@ -165,13 +169,13 @@ public void OpenTalkMenu()
var choiceTaggedInitial = _talkOptions.FirstOrDefault(choice => choice.tags != null && choice.tags.Contains("Initial"));
if (choiceTaggedInitial != null)
{
var choiceState = _choiceStates.FirstOrDefault(cs => cs.ChoiceId == choiceTaggedInitial.GetTagValue("id") && cs.Type == InvestigationChoiceType.Talk);
var choiceState = _choiceStates.FirstOrDefault(cs => cs.ChoiceId == choiceTaggedInitial.GetTagValue(ID_TAG_KEY) && cs.Type == InvestigationChoiceType.Talk);
if (choiceState is not { Examined: true })
{
_inputManager.SetInput(_gameInputModule);
_investigationMainMenuOpener.CloseMenu();
_narrativeGameState.NarrativeScriptPlayerComponent.NarrativeScriptPlayer.HandleChoice(0);
choiceState = GetOrCreateChoiceState(choiceTaggedInitial.GetTagValue("id"), InvestigationChoiceType.Talk);
choiceState = GetOrCreateChoiceState(choiceTaggedInitial.GetTagValue(ID_TAG_KEY), InvestigationChoiceType.Talk);
choiceState.Examined = true;
return;
}
Expand All @@ -184,7 +188,7 @@ public void OpenTalkMenu()
OpenWithChoices(_talkOptions, _moveOptions);
}, (menuItem, choice) =>
{
var choiceState = GetOrCreateChoiceState(choice.GetTagValue("id"), InvestigationChoiceType.Talk);
var choiceState = GetOrCreateChoiceState(choice.GetTagValue(ID_TAG_KEY), InvestigationChoiceType.Talk);
menuItem.transform.Find("AlreadyExamined").gameObject.SetActive(choiceState.Examined);
menuItem.GetComponent<Button>().onClick.AddListener(() =>
{
Expand All @@ -202,55 +206,63 @@ public void OpenMoveMenu()
{
_investigationMainMenuOpener.CloseMenu();
_investigationMoveMenu.transform.parent.gameObject.SetActive(true);
_investigationMoveMenu.ChoiceMenu.Initialise(_moveOptions, () =>
_investigationMoveMenu.ChoiceMenu.Initialise(
_moveOptions,
OnMoveMenuBackButtonClick,
OnMoveMenuButtonCreated);
}

private void OnMoveMenuButtonCreated(MenuItem menuItem, Choice choice)
{
var choiceState = GetOrCreateChoiceState(choice.GetTagValue(ID_TAG_KEY), InvestigationChoiceType.Move);
menuItem.ShouldIgnoreNextSelectEvent = false;
menuItem.GetComponent<Button>().onClick.AddListener(() =>
{
_investigationMoveMenu.ChoiceMenu.DeactivateChoiceMenu();
if (menuItem.Text == ChoiceMenu.BACK_BUTTON_LABEL)
{
return;
}

choiceState.Examined = true;
_investigationMoveMenu.transform.parent.gameObject.SetActive(false);
OpenWithChoices(_talkOptions, _moveOptions);
}, (menuItem, choice) =>
});
menuItem.OnItemSelect.AddListener(() =>
{
var choiceState = GetOrCreateChoiceState(choice.GetTagValue("id"), InvestigationChoiceType.Move);
menuItem.ShouldIgnoreNextSelectEvent = false;
menuItem.GetComponent<Button>().onClick.AddListener(() =>
if (menuItem.Text == ChoiceMenu.BACK_BUTTON_LABEL)
{
if (menuItem.Text == ChoiceMenu.BACK_BUTTON_LABEL)
{
return;
}
return;
}

choiceState.Examined = true;
_investigationMoveMenu.transform.parent.gameObject.SetActive(false);
});
menuItem.OnItemSelect.AddListener(() =>
{
if (menuItem.Text == ChoiceMenu.BACK_BUTTON_LABEL)
{
return;
}
_investigationMoveMenu.SceneImage.color = Color.white;

_investigationMoveMenu.SceneImage.color = Color.white;
if (!choiceState.Examined)
{
_investigationMoveMenu.SceneImage.sprite = _unestablishedSceneBackground;
return;
}

if (!choiceState.Examined)
{
_investigationMoveMenu.SceneImage.sprite = Sprite.Create(_unestablishedSceneBackground, new Rect(0, 0, _unestablishedSceneBackground.width, _unestablishedSceneBackground.height), new Vector2(0.5f, 0.5f));
return;
}
var bgScene = _moveOptions
.First(moveChoice => moveChoice.text == menuItem.Text)
.GetTagValue(BACKGROUND_TAG_KEY);

var bgScene = _moveOptions
.First(moveChoice => moveChoice.text == menuItem.Text)
.GetTagValue("background");
var rootPrefab = _narrativeGameState.ObjectStorage.GetObject<BGScene>(bgScene);
var sprite = rootPrefab.transform.Find("Background").GetComponent<SpriteRenderer>().sprite;
_investigationMoveMenu.SceneImage.sprite = sprite;
});

var rootPrefab = Resources.Load<GameObject>($"BGScenes/{bgScene}");
var sprite = rootPrefab.transform.Find("Background").GetComponent<SpriteRenderer>().sprite;
_investigationMoveMenu.SceneImage.sprite = sprite;
});
if (menuItem.transform.GetSiblingIndex() == 0)
{
menuItem.Selectable.Select();
}
}

if (menuItem.transform.GetSiblingIndex() == 0)
{
menuItem.Selectable.Select();
}
});
private void OnMoveMenuBackButtonClick()
{
_investigationMoveMenu.ChoiceMenu.DeactivateChoiceMenu();
_investigationMoveMenu.transform.parent.gameObject.SetActive(false);
OpenWithChoices(_talkOptions, _moveOptions);
}

#endregion

#region Present
Expand Down
Loading
Loading