Skip to content

Commit

Permalink
Collector heart of the sea
Browse files Browse the repository at this point in the history
  • Loading branch information
MegaPiggy committed Jul 23, 2024
1 parent 8db9cba commit 3f74df5
Show file tree
Hide file tree
Showing 6 changed files with 89 additions and 13 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"autoUnlock": true,
"autoUnlock": false,
"nameKey": "exampleitems.testability.name",
"descriptionKey": "exampleitems.testability.desc",
"shortDescriptionKey": "exampleitems.testability.shortDesc",
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
title: Collector_ExampleItemsHeartOfTheSea_Deliver
---
<<SetQuestStepCompleted ExampleItemsHeartOfTheSea_Return>>
<<RemoveItemById exampleitems.heartofthesea>>
<<RecordRelicHandedIn>>
<<AdjustIntVariable relics-handed-in 1>>
<<ShowPortrait COLLECTOR_NAME_KEY>>
You walk in and place the Heart of the Sea on a table by the Collector. #line:0cz83c6
COLLECTOR_NAME_KEY: Oh? What is that you have in your hand? #line:0da94d7
COLLECTOR_NAME_KEY: It looks like a sphere but it is blocky. #line:0986fhd
COLLECTOR_NAME_KEY: I sense some power eminating from it. #line:05ajy58
<<jump Collector_ExampleItemsHeartOfTheSea_Award>>
===
title: Collector_ExampleItemsHeartOfTheSea_Award
---
COLLECTOR_NAME_KEY: I'm not sure what I should give you for this... #line:04636c1
<<PlayClip collector-page-turn>>
COLLECTOR_NAME_KEY: Hmmm... #line:0a1543c
COLLECTOR_NAME_KEY: Actually, how about this. #line:03ec055
<<UnlockAbility exampleitems.testability>>
<<TogglePortraitVFX true>>
<<PlayClip collector-ability-unlock>>
COLLECTOR_NAME_KEY: Ok you can leave now. #exit #line:04fd166
===
10 changes: 10 additions & 0 deletions Winch.Examples/ExampleItems/Assets/Dialogues/en.csv
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,13 @@ TRAVELLING_MERCHANT_NAME_KEY,"Hey, there! You have a question for me?",line:0a34
,Yep.,line:0b16d07
,Cool...,line:0e5ab6f
,,
,You walk in and place the Heart of the Sea on a table by the Collector.,line:0cz83c6
COLLECTOR_NAME_KEY,Oh? What is that you have in your hand?,line:0da94d7
COLLECTOR_NAME_KEY,It looks like a sphere but it is blocky.,line:0986fhd
COLLECTOR_NAME_KEY,I sense some power eminating from it.,line:05ajy58
,,
COLLECTOR_NAME_KEY,I'm not sure what I should give you for this...,line:04636c1
COLLECTOR_NAME_KEY,Hmmm...,line:0a1543c
COLLECTOR_NAME_KEY,"Actually, how about this.",line:03ec055
COLLECTOR_NAME_KEY,Ok you can leave now.,line:04fd166
,,
15 changes: 15 additions & 0 deletions Winch.Examples/ExampleItems/Loader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,21 @@ public static void Initialize()
try
{
DialogueUtil.AddInstruction("TravellingMerchant_ChatOptions", 1, Instruction.Types.OpCode.AddOption, "line:01f8b99", "L84shortcutoption_TravellingMerchant_ChatOptions_6", 0, false);

DialogueUtil.AddInstructions(
// insert at 55 which is Stop
new DialogueUtil.DredgeInstruction("Collector_RelicRouting", 55, Instruction.Types.OpCode.PushString, "exampleitems.heartofthesea"),
new DialogueUtil.DredgeInstruction("Collector_RelicRouting", 56, Instruction.Types.OpCode.PushFloat, 1),
new DialogueUtil.DredgeInstruction("Collector_RelicRouting", 57, Instruction.Types.OpCode.CallFunc, "GetNumItemInInventoryById"),
new DialogueUtil.DredgeInstruction("Collector_RelicRouting", 58, Instruction.Types.OpCode.PushFloat, 0),
new DialogueUtil.DredgeInstruction("Collector_RelicRouting", 59, Instruction.Types.OpCode.PushFloat, 2),
new DialogueUtil.DredgeInstruction("Collector_RelicRouting", 60, Instruction.Types.OpCode.CallFunc, "Number.GreaterThan"),
new DialogueUtil.DredgeInstruction("Collector_RelicRouting", 61, Instruction.Types.OpCode.JumpIfFalse, "L53skipclause"),
new DialogueUtil.DredgeInstruction("Collector_RelicRouting", 62, Instruction.Types.OpCode.PushString, "Collector_ExampleItemsHeartOfTheSea_Deliver"),
new DialogueUtil.DredgeInstruction("Collector_RelicRouting", 63, Instruction.Types.OpCode.RunNode),
new DialogueUtil.DredgeInstruction("Collector_RelicRouting", 64, Instruction.Types.OpCode.JumpTo, "L47endif"),
new DialogueUtil.DredgeInstruction("Collector_RelicRouting", 65, Instruction.Types.OpCode.Pop)
);
}
catch (Exception e)
{
Expand Down
51 changes: 39 additions & 12 deletions Winch/Util/DialogueUtil.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@

namespace Winch.Util;

public class DialogueUtil
public static class DialogueUtil
{
/// <summary>
/// Unlocalized lines indexed by their IDs, loaded from mod .yarn files. Used as fallbacks. Loaded in LoadDialoguesFiles on startup.
Expand Down Expand Up @@ -105,19 +105,31 @@ private static CompilationResult CompileProgram(string[] inputs)
/// <param name="nodeID">The ID of the node.</param>
/// <param name="index">The index to insert the instruction at.</param>
/// <param name="opCode">The opcode to insert. See <see href="https://github.com/YarnSpinnerTool/YarnSpinner/blob/main/YarnSpinner/yarn_spinner.proto"/> for a list of opcodes.</param>
/// <param name="operands">Supported types: string, bool, float, int</param>
/// <param name="operands">Supported types: <see cref="string"/>, <see cref="bool"/>, <see cref="float"/>, <see cref="int"/></param>
public static void AddInstruction(string nodeID, int index, Yarn.Instruction.Types.OpCode opCode, params object[] operands)
{
instructions.Add(new DredgeInstruction
{
NodeID = nodeID,
Index = index,
OpCode = opCode,
Operands = operands
});
AddInstruction(new DredgeInstruction(nodeID, index, opCode, operands));
}

/// <summary>
/// Register an instruction to insert later
/// </summary>
/// <param name="instruction">The instruction to insert.</param>
public static void AddInstruction(DredgeInstruction instruction)
{
instructions.Add(instruction);
}

/// <summary>
/// Register instructions to insert later
/// </summary>
/// <param name="instructions">The instructions to insert.</param>
public static void AddInstructions(params DredgeInstruction[] instructions)
{
DialogueUtil.instructions.AddRange(instructions);
}

internal static void AddInstruction(DredgeInstruction dredgeInstruction)
internal static void InsertInstruction(DredgeInstruction dredgeInstruction)
{
Yarn.Instruction instruction = new Instruction();
instruction.Opcode = dredgeInstruction.OpCode;
Expand Down Expand Up @@ -248,7 +260,7 @@ internal static void Inject()

foreach (var instruction in instructions)
{
AddInstruction(instruction);
InsertInstruction(instruction);
}
}

Expand All @@ -259,11 +271,26 @@ internal class LinesCSVRecord
public string Id { get; set; }
}

internal class DredgeInstruction
public class DredgeInstruction
{
public string NodeID { get; set; }
public int Index { get; set; }
public Yarn.Instruction.Types.OpCode OpCode { get; set; }
public object[] Operands { get; set; }

/// <summary>
/// Create an instruction
/// </summary>
/// <param name="nodeID">The ID of the node.</param>
/// <param name="index">The index to insert the instruction at.</param>
/// <param name="opCode">The opcode to insert. See <see href="https://github.com/YarnSpinnerTool/YarnSpinner/blob/main/YarnSpinner/yarn_spinner.proto"/> for a list of opcodes.</param>
/// <param name="operands">Supported types: <see cref="string"/>, <see cref="bool"/>, <see cref="float"/>, <see cref="int"/></param>
public DredgeInstruction(string nodeID, int index, Yarn.Instruction.Types.OpCode opCode, params object[] operands)
{
NodeID = nodeID;
Index = index;
OpCode = opCode;
Operands = operands;
}
}
}

0 comments on commit 3f74df5

Please sign in to comment.