Skip to content

Commit

Permalink
Reorganize repo
Browse files Browse the repository at this point in the history
  • Loading branch information
paulloz committed Jun 4, 2022
1 parent fdd030c commit 8aa4980
Show file tree
Hide file tree
Showing 17 changed files with 2,278 additions and 227 deletions.
96 changes: 96 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
root = true

[*]

end_of_line = lf
insert_final_newline = true

[*.cs]

indent_style = space
indent_size = 4
tab_width = 4

dotnet_sort_system_directives_first = false
dotnet_separate_import_directive_groups = false

csharp_new_line_before_open_brace = all
csharp_new_line_before_else = true
csharp_new_line_before_catch = true
csharp_new_line_before_finally = true
csharp_new_line_before_members_in_object_initializers = true
csharp_new_line_before_members_in_anonymous_types = true
csharp_new_line_between_query_expression_clauses = true

csharp_indent_case_contents = true
csharp_indent_switch_labels = true
csharp_indent_block_contents = true
csharp_indent_braces = false
csharp_indent_case_contents_when_block = false

csharp_space_after_cast = false
csharp_space_after_keywords_in_control_flow_statements = true
csharp_space_before_colon_in_inheritance_clause = true
csharp_space_after_colon_in_inheritance_clause = true
csharp_space_around_binary_operators = before_and_after
csharp_space_between_method_declaration_parameter_list_parentheses = false
csharp_space_between_method_declaration_empty_parameter_list_parentheses = false
csharp_space_between_method_declaration_name_and_open_parenthesis = false
csharp_space_between_method_call_parameter_list_parentheses = false
csharp_space_between_method_call_empty_parameter_list_parentheses = false
csharp_space_between_method_call_name_and_opening_parenthesis = false
csharp_space_after_comma = true
csharp_space_before_comma = false
csharp_space_after_dot = false
csharp_space_before_dot = false
csharp_space_after_semicolon_in_for_statement = true
csharp_space_before_semicolon_in_for_statement = false
csharp_space_around_declaration_statements = false
csharp_space_before_open_square_brackets = false
csharp_space_between_empty_square_brackets = false
csharp_space_between_square_brackets = false

csharp_preserve_single_line_statements = true
csharp_preserve_single_line_blocks = true

csharp_using_directive_placement = outside_namespace

csharp_style_namespace_declarations = block_scoped


dotnet_diagnostic.IDE0001.severity = suggestion
dotnet_diagnostic.IDE0002.severity = suggestion
dotnet_diagnostic.IDE0004.severity = warning
dotnet_diagnostic.IDE0005.severity = error
dotnet_diagnostoc.IDE0035.severity = error
dotnet_diagnostoc.IDE0051.severity = warning
dotnet_diagnostoc.IDE0052.severity = warning
dotnet_diagnostoc.IDE0058.severity = warning
dotnet_diagnostoc.IDE0059.severity = error
dotnet_diagnostoc.IDE0060.severity = suggestion
dotnet_diagnostoc.IDE0079.severity = suggestion
dotnet_diagnostoc.IDE0080.severity = error
dotnet_diagnostoc.IDE0100.severity = error
dotnet_diagnostoc.IDE0110.severity = error
dotnet_diagnostoc.IDE0110.severity = error

dotnet_diagnostoc.CA1802.severity = error
dotnet_diagnostoc.CA1805.severity = warning
dotnet_diagnostoc.CA1806.severity = warning
dotnet_diagnostoc.CA1810.severity = warning
dotnet_diagnostoc.CA1815.severity = suggestion
dotnet_diagnostoc.CA1819.severity = error
dotnet_diagnostoc.CA1820.severity = suggestion
dotnet_diagnostoc.CA1822.severity = suggestion
dotnet_diagnostoc.CA1823.severity = warning
dotnet_diagnostoc.CA1825.severity = warning
dotnet_diagnostoc.CA1826.severity = warning
dotnet_diagnostoc.CA1827.severity = warning
dotnet_diagnostoc.CA1828.severity = warning
dotnet_diagnostoc.CA1829.severity = warning
dotnet_diagnostoc.CA1836.severity = warning
dotnet_diagnostoc.CA1841.severity = warning

dotnet_diagnostoc.CA2207.severity = warning
dotnet_diagnostoc.CA2211.severity = warning
dotnet_diagnostoc.CA2227.severity = error
11 changes: 9 additions & 2 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -1,8 +1,15 @@
/.github/ export-ignore
/examples/ export-ignore
/screenshots/ export-ignore

/.editorconfig export-ignore
/.gitattributes export-ignore
/.gitignore export-ignore

/CODE_OF_CONDUCT.md export-ignore
/CONTRIBUTING.md export-ignore
/README.md export-ignore
/LICENSE export-ignore
/*.png export-ignore
/README.md export-ignore

/icon.png export-ignore
/project.godot export-ignore
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,6 @@ export_presets.cfg
project.godot
*.import

inklecate.exe
ink_compiler.dll
ink-engine-runtime.dll
ink-engine-runtime.dll.mdb
6 changes: 2 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,6 @@ The following platforms have been tested with Godot 3.2.2:

I'm pretty sure this will also run fine on MacOS and Android but haven't witnessed it yet. If you end up testing an unlisted platform, please create an issue to tell me whether everything work or not.

Examples can be found in my [godot-ink-example](https://github.com/paulloz/godot-ink-example) repository.

## Installation

* Drop the `paulloz.ink/` folder in your project's `addons/` folder.
Expand All @@ -40,7 +38,7 @@ Examples can be found in my [godot-ink-example](https://github.com/paulloz/godot

When the plugin is properly loaded, you should be able to use the new ink panel to inspect your story.

![](inspector_screenshot.png)
![](screenshots/inspector_screenshot.png)

If you want to compile your `.ink` files directly, you'll also need to download the [ink compiler](https://github.com/inkle/ink/releases) on your computer and copy/paste the path to the `inklecate` binary into your project settings (*Project -> Project Settings... -> Ink -> Inklecate Path*).

Expand All @@ -55,7 +53,7 @@ In **GDScript** for some properties, you'll need to use a `get_` prefix (e.g. `g

First you should navigate to your `.json` or `.ink` file and import it as an `Ink story` in Godot. To do that, select the file in Godot, go to `Import`, select `Ink story` under `Import As:` and click `ReImport`.

![](import_screenshot.png)
![](screenshots/import_screenshot.png)

To load your story, you can:

Expand Down
97 changes: 53 additions & 44 deletions addons/paulloz.ink/InkDock.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
#if TOOLS
using Godot;
using System;

[Tool]
public class InkDock : Control
Expand All @@ -13,9 +12,8 @@ public class InkDock : Control
private InkStory story;
private VBoxContainer storyText;
private VBoxContainer storyChoices;

private ScrollContainer scroll;
private ScrollBar scrollbar;

public override void _Ready()
{
Expand All @@ -28,51 +26,52 @@ public override void _Ready()
scroll = GetNode<ScrollContainer>("Container/Bottom/Scroll");
story = GetNode<InkStory>("Story");

resetButton.Connect("pressed", this, nameof(onResetButtonPressed));
loadButton.Connect("pressed", this, nameof(onLoadButtonPressed));
fileDialog.Connect("popup_hide", this, nameof(onFileDialogHide));
story.Connect(nameof(InkStory.InkChoices), this, nameof(onStoryChoices));
story.Connect(nameof(InkStory.InkContinued), this, nameof(onStoryContinued));
story.Connect(nameof(InkStory.InkEnded), this, nameof(onStoryEnded));
resetButton.Connect("pressed", this, nameof(OnResetButtonPressed));
loadButton.Connect("pressed", this, nameof(OnLoadButtonPressed));
fileDialog.Connect("popup_hide", this, nameof(OnFileDialogHide));
story.Connect(nameof(InkStory.InkChoices), this, nameof(OnStoryChoices));
story.Connect(nameof(InkStory.InkContinued), this, nameof(OnStoryContinued));
story.Connect(nameof(InkStory.InkEnded), this, nameof(OnStoryEnded));
}

private void resetStoryContent()
private void ResetStoryContent()
{
removeAllStoryContent();
removeAllChoices();
RemoveAllStoryContent();
RemoveAllChoices();
}

private void removeAllStoryContent()
private void RemoveAllStoryContent()
{
foreach (Node n in storyText.GetChildren())
storyText.RemoveChild(n);
}

private void removeAllChoices()
private void RemoveAllChoices()
{
foreach (Node n in storyChoices.GetChildren())
storyChoices.RemoveChild(n);
}

private void onResetButtonPressed()
private void OnResetButtonPressed()
{
resetStoryContent();
ResetStoryContent();
story.LoadStory();
story.Continue();
}

private void onLoadButtonPressed()
private void OnLoadButtonPressed()
{
fileDialog.PopupCentered();
}

private void onFileDialogHide()
private void OnFileDialogHide()
{
resetStoryContent();
ResetStoryContent();
fileName.Text = "";
if (fileDialog.CurrentFile == null || fileDialog.CurrentFile.Length == 0) {
if (fileDialog.CurrentFile == null || fileDialog.CurrentFile.Length == 0)
resetButton.Disabled = true;
} else {
else
{
resetButton.Disabled = false;
fileName.Text = fileDialog.CurrentFile;
story.InkFile = ResourceLoader.Load(fileDialog.CurrentPath);
Expand All @@ -81,64 +80,74 @@ private void onFileDialogHide()
}
}

private void onStoryContinued(String text, String[] tags)
private void OnStoryContinued(string text, string[] _)
{
text = text.Trim();
if (text.Length > 0) {
Label newLine = new Label();
newLine.Autowrap = true;
newLine.Text = text;
addToStory(newLine);
if (text.Length > 0)
{
Label newLine = new Label()
{
Autowrap = true,
Text = text,
};
AddToStory(newLine);
}

story.Continue();
}

private void onStoryChoices(String[] choices)
private void OnStoryChoices(string[] choices)
{
int i = 0;
foreach (String choice in choices)
foreach (string choice in choices)
{
if (i < storyChoices.GetChildCount()) { continue; }
Button button = new Button();
button.Text = choice;
button.Connect("pressed", this, nameof(clickChoice), new Godot.Collections.Array() { i });
if (i < storyChoices.GetChildCount()) continue;

Button button = new Button()
{
Text = choice,
};
button.Connect("pressed", this, nameof(ClickChoice), new Godot.Collections.Array() { i });
storyChoices.AddChild(button);
++i;
}
}

private void onStoryEnded()
private void OnStoryEnded()
{
CanvasItem endOfStory = new VBoxContainer();
endOfStory.AddChild(new HSeparator());
CanvasItem endOfStoryLine = new HBoxContainer();
endOfStory.AddChild(endOfStoryLine);
endOfStory.AddChild(new HSeparator());
Control separator = new HSeparator();
separator.SizeFlagsHorizontal = (int)(SizeFlags.Fill | SizeFlags.Expand);
Label endOfStoryText = new Label();
endOfStoryText.Text = "End of story";
Control separator = new HSeparator()
{
SizeFlagsHorizontal = (int)(SizeFlags.Fill | SizeFlags.Expand),
};
Label endOfStoryText = new Label()
{
Text = "End of story"
};
endOfStoryLine.AddChild(separator);
endOfStoryLine.AddChild(endOfStoryText);
endOfStoryLine.AddChild(separator.Duplicate());
addToStory(endOfStory);
AddToStory(endOfStory);
}

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

private async void addToStory(CanvasItem item)
private async void AddToStory(CanvasItem item)
{
storyText.AddChild(item);
await ToSignal(GetTree(), "idle_frame");
await ToSignal(GetTree(), "idle_frame");
scroll.ScrollVertical = (int)scroll.GetVScrollbar().MaxValue;
}
}
#endif
#endif
Loading

0 comments on commit 8aa4980

Please sign in to comment.