Skip to content

Commit

Permalink
Restructure main node and resource types
Browse files Browse the repository at this point in the history
- Rename InkStory → InkPlayer
  • Loading branch information
paulloz committed Jun 5, 2022
1 parent 6f91d62 commit 16e93e1
Show file tree
Hide file tree
Showing 9 changed files with 206 additions and 144 deletions.
37 changes: 17 additions & 20 deletions addons/paulloz.ink/InkDock.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
[Tool]
public class InkDock : Control
{
private InkStory story;
private InkPlayer player;
private bool storyStarted;

private Button loadButton;
Expand Down Expand Up @@ -54,9 +54,10 @@ public override void _Ready()

private void UpdateTop()
{
bool hasStory = story != null;
bool hasStory = player != null;

storyNameLabel.Text = hasStory ? story.InkFile.ResourcePath : string.Empty;
// Do not judge me.
storyNameLabel.Text = hasStory ? ((Resource)player.Get("story")).ResourcePath : string.Empty;

startButton.Visible = hasStory && !storyStarted;
stopButton.Visible = hasStory && storyStarted;
Expand All @@ -69,41 +70,37 @@ private void UpdateTop()
private void LoadStoryResource()
{
StopStory();
story = null;
player = null;

if (!string.IsNullOrEmpty(fileDialog.CurrentFile))
{
story = new InkStory()
{
AutoLoadStory = false,
InkFile = ResourceLoader.Load(fileDialog.CurrentPath),
};
player = new InkPlayer();
player.LoadStory(ResourceLoader.Load<Resource>(fileDialog.CurrentPath));

story.Connect(nameof(InkStory.InkContinued), this, nameof(OnStoryContinued));
story.Connect(nameof(InkStory.InkChoices), this, nameof(OnStoryChoices));
story.Connect(nameof(InkStory.InkEnded), this, nameof(OnStoryEnded));
player.Connect(nameof(InkPlayer.InkContinued), this, nameof(OnStoryContinued));
player.Connect(nameof(InkPlayer.InkChoices), this, nameof(OnStoryChoices));
player.Connect(nameof(InkPlayer.InkEnded), this, nameof(OnStoryEnded));

AddChild(story);
AddChild(player);
}

UpdateTop();
}

private void StartStory()
{
if (story == null) return;
if (player == null) return;

story.LoadStory();
storyStarted = true;
story.Continue();
player.Continue();

UpdateTop();
}

private void StopStory()
{
storyStarted = false;
story?.LoadStory();
player?.LoadStory();

ClearStory(true);
}
Expand Down Expand Up @@ -142,7 +139,7 @@ private void OnStoryContinued(string text, string[] tags)
}
}

story.Continue();
player.Continue();
}

private void OnStoryChoices(string[] choices)
Expand Down Expand Up @@ -185,10 +182,10 @@ private void OnStoryEnded()

private void ClickChoice(int idx)
{
story.ChooseChoiceIndex(idx);
player.ChooseChoiceIndex(idx);
RemoveAllChoices();
AddToStory(new HSeparator());
story.Continue();
player.Continue();
}

private async void AddToStory(CanvasItem item)
Expand Down
53 changes: 37 additions & 16 deletions addons/paulloz.ink/InkDock.tscn
Original file line number Diff line number Diff line change
@@ -1,7 +1,22 @@
[gd_scene load_steps=3 format=2]
[gd_scene load_steps=5 format=2]

[ext_resource path="res://addons/paulloz.ink/InkDock.cs" type="Script" id=1]

[sub_resource type="Image" id=4]
data = {
"data": PoolByteArray( 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0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SubResource( 4 )
size = Vector2( 16, 16 )

[sub_resource type="StyleBoxFlat" id=1]
bg_color = Color( 0.137255, 0.160784, 0.184314, 1 )

Expand All @@ -20,25 +35,26 @@ size_flags_horizontal = 3
size_flags_vertical = 3

[node name="Left" type="VBoxContainer" parent="Container"]
margin_right = 812.0
margin_right = 1024.0
margin_bottom = 600.0
size_flags_horizontal = 3
size_flags_vertical = 3

[node name="Top" type="HBoxContainer" parent="Container/Left"]
margin_right = 812.0
margin_bottom = 20.0
margin_right = 1024.0
margin_bottom = 22.0

[node name="LoadButton" type="Button" parent="Container/Left/Top"]
margin_right = 54.0
margin_bottom = 20.0
margin_right = 72.0
margin_bottom = 22.0
text = "Load..."
icon = SubResource( 3 )

[node name="Label" type="Label" parent="Container/Left/Top"]
margin_left = 58.0
margin_top = 3.0
margin_right = 812.0
margin_bottom = 17.0
margin_left = 76.0
margin_top = 4.0
margin_right = 1024.0
margin_bottom = 18.0
size_flags_horizontal = 3

[node name="StartButton" type="Button" parent="Container/Left/Top"]
Expand All @@ -47,33 +63,37 @@ margin_left = 679.0
margin_right = 720.0
margin_bottom = 20.0
text = "Start"
icon = SubResource( 3 )

[node name="StopButton" type="Button" parent="Container/Left/Top"]
visible = false
margin_left = 724.0
margin_right = 764.0
margin_bottom = 20.0
text = "Stop"
icon = SubResource( 3 )

[node name="ClearButton" type="Button" parent="Container/Left/Top"]
visible = false
margin_left = 768.0
margin_right = 812.0
margin_bottom = 20.0
disabled = true
text = "Clear"
icon = SubResource( 3 )

[node name="Scroll" type="ScrollContainer" parent="Container/Left"]
margin_top = 24.0
margin_right = 812.0
margin_top = 26.0
margin_right = 1024.0
margin_bottom = 600.0
size_flags_horizontal = 11
size_flags_vertical = 3
custom_styles/bg = SubResource( 1 )
scroll_horizontal_enabled = false

[node name="Margin" type="MarginContainer" parent="Container/Left/Scroll"]
margin_right = 812.0
margin_bottom = 576.0
margin_right = 1024.0
margin_bottom = 574.0
size_flags_horizontal = 3
size_flags_vertical = 3
custom_constants/margin_right = 10
Expand All @@ -84,12 +104,13 @@ custom_constants/margin_bottom = 10
[node name="StoryText" type="VBoxContainer" parent="Container/Left/Scroll/Margin"]
margin_left = 10.0
margin_top = 10.0
margin_right = 802.0
margin_bottom = 566.0
margin_right = 1014.0
margin_bottom = 564.0
size_flags_horizontal = 11
size_flags_vertical = 3

[node name="Right" type="VBoxContainer" parent="Container"]
visible = false
margin_left = 824.0
margin_right = 1024.0
margin_bottom = 600.0
Expand Down
Loading

0 comments on commit 16e93e1

Please sign in to comment.