Skip to content

Commit

Permalink
feat(variables): added global database actions and conditions
Browse files Browse the repository at this point in the history
You can now create actions and conditions that persist across dialogue conversations. The database
where these are stored can be saved and loaded from a string if needed.
  • Loading branch information
ashblue committed Dec 29, 2020
1 parent 558c869 commit 4fef38c
Show file tree
Hide file tree
Showing 52 changed files with 755 additions and 43 deletions.
19 changes: 18 additions & 1 deletion Assets/Examples/BasicConversation/ExampleConversation.asset
Expand Up @@ -144,6 +144,22 @@ MonoBehaviour:
choices: []
actor: {fileID: 11400000, guid: aebb863e25cae0a4495c09b6a617ecf6, type: 2}
dialogue: They're doing fine. You've got bigger things to worry about.
--- !u!114 &-7021118909226780551
MonoBehaviour:
m_ObjectHideFlags: 1
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 0}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: dc39c8b552b94c01a6ae86d4b8cce494, type: 3}
m_Name: SetGlobalBool
m_EditorClassIdentifier:
_title: SetGlobalBool humans asked
_uniqueId: 067fa933-713f-4ff1-860b-4051d4c9b040
_value: 1
_variable: {fileID: 11400000, guid: 1906dabbacd5b15429089da6c10fd23d, type: 2}
--- !u!114 &-6868820908879997394
MonoBehaviour:
m_ObjectHideFlags: 1
Expand Down Expand Up @@ -306,6 +322,7 @@ MonoBehaviour:
conditions: []
enterActions:
- {fileID: -4687762883489335130}
- {fileID: -7021118909226780551}
exitActions: []
choices: []
actor: {fileID: 11400000, guid: d6a8e0fd1eb801d4ca00320f6b2e9e8b, type: 2}
Expand Down Expand Up @@ -470,7 +487,7 @@ MonoBehaviour:
- {fileID: -1221359623688907011}
- {fileID: 3721123120546049034}
root: {fileID: 426936237664981933}
scrollPosition: {x: 50450.676, y: 49996}
scrollPosition: {x: 50404.676, y: 50073}
--- !u!114 &373158185418196577
MonoBehaviour:
m_ObjectHideFlags: 0
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

@@ -0,0 +1,16 @@
using CleverCrow.Fluid.Databases;
using UnityEngine;

namespace CleverCrow.Fluid.Dialogues.Actions.Databases {
[CreateMenu("Database/Globals/Set Bool")]
public class SetGlobalBool : SetLocalVariableBase<bool> {
[SerializeField]
public KeyValueDefinitionBool _variable;

protected override KeyValueDefinitionBase<bool> Variable => _variable;

protected override IKeyValueData<bool> GetDatabase (IDialogueController dialogue) {
return GlobalDatabaseManager.Instance.Database.Bools;
}
}
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

@@ -0,0 +1,16 @@
using CleverCrow.Fluid.Databases;
using UnityEngine;

namespace CleverCrow.Fluid.Dialogues.Actions.Databases {
[CreateMenu("Database/Globals/Set Float")]
public class SetGlobalFloat : SetLocalVariableBase<float> {
[SerializeField]
public KeyValueDefinitionFloat _variable;

protected override KeyValueDefinitionBase<float> Variable => _variable;

protected override IKeyValueData<float> GetDatabase (IDialogueController dialogue) {
return GlobalDatabaseManager.Instance.Database.Floats;
}
}
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

@@ -0,0 +1,16 @@
using CleverCrow.Fluid.Databases;
using UnityEngine;

namespace CleverCrow.Fluid.Dialogues.Actions.Databases {
[CreateMenu("Database/Globals/Set Int")]
public class SetGlobalInt : SetLocalVariableBase<int> {
[SerializeField]
public KeyValueDefinitionInt _variable;

protected override KeyValueDefinitionBase<int> Variable => _variable;

protected override IKeyValueData<int> GetDatabase (IDialogueController dialogue) {
return GlobalDatabaseManager.Instance.Database.Ints;
}
}
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

@@ -0,0 +1,16 @@
using CleverCrow.Fluid.Databases;
using UnityEngine;

namespace CleverCrow.Fluid.Dialogues.Actions.Databases {
[CreateMenu("Database/Globals/Set String")]
public class SetGlobalString : SetLocalVariableBase<string> {
[SerializeField]
public KeyValueDefinitionString _variable;

protected override KeyValueDefinitionBase<string> Variable => _variable;

protected override IKeyValueData<string> GetDatabase (IDialogueController dialogue) {
return GlobalDatabaseManager.Instance.Database.Strings;
}
}
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

@@ -0,0 +1,11 @@
using CleverCrow.Fluid.Databases;
using CleverCrow.Fluid.Dialogues.Actions.Databases;

namespace CleverCrow.Fluid.Dialogues.Conditions.Databases {
[CreateMenu("Database/Globals/Is Bool")]
public class IsGlobalBool : IsBoolBase {
protected override IKeyValueData<bool> GetBoolInstance (IDialogueController dialogue) {
return GlobalDatabaseManager.Instance.Database.Bools;
}
}
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

@@ -0,0 +1,11 @@
using CleverCrow.Fluid.Databases;
using CleverCrow.Fluid.Dialogues.Actions.Databases;

namespace CleverCrow.Fluid.Dialogues.Conditions.Databases {
[CreateMenu("Database/Globals/Is Float")]
public class IsGlobalFloat : IsFloatBase {
protected override IKeyValueData<float> GetFloatInstance (IDialogueController dialogue) {
return GlobalDatabaseManager.Instance.Database.Floats;
}
}
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

@@ -0,0 +1,11 @@
using CleverCrow.Fluid.Databases;
using CleverCrow.Fluid.Dialogues.Actions.Databases;

namespace CleverCrow.Fluid.Dialogues.Conditions.Databases {
[CreateMenu("Database/Globals/Is Int")]
public class IsGlobalInt : IsIntBase {
protected override IKeyValueData<int> GetIntInstance (IDialogueController dialogue) {
return GlobalDatabaseManager.Instance.Database.Ints;
}
}
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

@@ -0,0 +1,11 @@
using CleverCrow.Fluid.Databases;
using CleverCrow.Fluid.Dialogues.Actions.Databases;

namespace CleverCrow.Fluid.Dialogues.Conditions.Databases {
[CreateMenu("Database/Globals/Is String")]
public class IsGlobalString : IsStringBase {
protected override IKeyValueData<string> GetStringInstance (IDialogueController dialogue) {
return GlobalDatabaseManager.Instance.Database.Strings;
}
}
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Expand Up @@ -5,9 +5,8 @@
using UnityEngine;

namespace CleverCrow.Fluid.Dialogues.Actions.Databases {
[CreateMenu("Database/Locals/Is Bool")]
public class IsLocalBool : ConditionDataBase {
private ConditionLocalBoolInternal _condition;
public abstract class IsBoolBase : ConditionDataBase {
private ConditionBoolInternal _condition;

[SerializeField]
private KeyValueDefinitionBool _variable = null;
Expand All @@ -23,8 +22,10 @@ private enum Comparison {
NotEqual
}

protected abstract IKeyValueData<bool> GetBoolInstance (IDialogueController dialogue);

public override void OnInit (IDialogueController dialogue) {
_condition = new ConditionLocalBoolInternal(dialogue.LocalDatabase.Bools);
_condition = new ConditionBoolInternal(GetBoolInstance(dialogue));
}

public override bool OnGetIsValid (INode parent) {
Expand All @@ -39,10 +40,10 @@ private enum Comparison {
}
}

public class ConditionLocalBoolInternal {
public class ConditionBoolInternal {
private readonly IKeyValueData<bool> _database;

public ConditionLocalBoolInternal (IKeyValueData<bool> database) {
public ConditionBoolInternal (IKeyValueData<bool> database) {
_database = database;
}

Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

@@ -0,0 +1,10 @@
using CleverCrow.Fluid.Databases;

namespace CleverCrow.Fluid.Dialogues.Actions.Databases {
[CreateMenu("Database/Locals/Is Bool")]
public class IsLocalBool : IsBoolBase {
protected override IKeyValueData<bool> GetBoolInstance (IDialogueController dialogue) {
return dialogue.LocalDatabase.Bools;
}
}
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Expand Up @@ -6,8 +6,8 @@

namespace CleverCrow.Fluid.Dialogues.Actions.Databases {
[CreateMenu("Database/Locals/Is Float")]
public class ConditionLocalFloat : ConditionDataBase {
private ConditionLocalFloatInternal _condition;
public abstract class IsFloatBase : ConditionDataBase {
private ConditionFloatInternal _condition;

[SerializeField]
private KeyValueDefinitionFloat _variable = null;
Expand All @@ -18,19 +18,21 @@ public class ConditionLocalFloat : ConditionDataBase {
[SerializeField]
private float _value = 0;

protected abstract IKeyValueData<float> GetFloatInstance (IDialogueController dialogue);

public override void OnInit (IDialogueController dialogue) {
_condition = new ConditionLocalFloatInternal(dialogue.LocalDatabase.Floats);
_condition = new ConditionFloatInternal(GetFloatInstance(dialogue));
}

public override bool OnGetIsValid (INode parent) {
return _condition.IsComparisonValid(_variable, _value, _comparison);
}
}

public class ConditionLocalFloatInternal {
public class ConditionFloatInternal {
private readonly IKeyValueData<float> _database;

public ConditionLocalFloatInternal (IKeyValueData<float> database) {
public ConditionFloatInternal (IKeyValueData<float> database) {
_database = database;
}

Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

@@ -0,0 +1,10 @@
using CleverCrow.Fluid.Databases;

namespace CleverCrow.Fluid.Dialogues.Actions.Databases {
[CreateMenu("Database/Locals/Is Float")]
public class ConditionLocalFloat : IsFloatBase {
protected override IKeyValueData<float> GetFloatInstance (IDialogueController dialogue) {
return dialogue.LocalDatabase.Floats;
}
}
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Expand Up @@ -5,9 +5,8 @@
using UnityEngine;

namespace CleverCrow.Fluid.Dialogues.Actions.Databases {
[CreateMenu("Database/Locals/Is Int")]
public class IsLocalInt : ConditionDataBase {
private ConditionLocalIntInternal _condition;
public abstract class IsIntBase : ConditionDataBase {
private ConditionIntInternal _condition;

[SerializeField]
private KeyValueDefinitionInt _variable = null;
Expand All @@ -18,19 +17,21 @@ public class IsLocalInt : ConditionDataBase {
[SerializeField]
private int _value = 0;

protected abstract IKeyValueData<int> GetIntInstance (IDialogueController dialogue);

public override void OnInit (IDialogueController dialogue) {
_condition = new ConditionLocalIntInternal(dialogue.LocalDatabase.Ints);
_condition = new ConditionIntInternal(GetIntInstance(dialogue));
}

public override bool OnGetIsValid (INode parent) {
return _condition.IsComparisonValid(_variable, _value, _comparison);
}
}

public class ConditionLocalIntInternal {
public class ConditionIntInternal {
private readonly IKeyValueData<int> _database;

public ConditionLocalIntInternal (IKeyValueData<int> database) {
public ConditionIntInternal (IKeyValueData<int> database) {
_database = database;
}

Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

@@ -0,0 +1,10 @@
using CleverCrow.Fluid.Databases;

namespace CleverCrow.Fluid.Dialogues.Actions.Databases {
[CreateMenu("Database/Locals/Is Int")]
public class IsLocalInt : IsIntBase {
protected override IKeyValueData<int> GetIntInstance (IDialogueController dialogue) {
return dialogue.LocalDatabase.Ints;
}
}
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

@@ -0,0 +1,10 @@
using CleverCrow.Fluid.Databases;

namespace CleverCrow.Fluid.Dialogues.Actions.Databases {
[CreateMenu("Database/Locals/Is String")]
public class IsLocalString : IsStringBase {
protected override IKeyValueData<string> GetStringInstance (IDialogueController dialogue) {
return dialogue.LocalDatabase.Strings;
}
}
}

0 comments on commit 4fef38c

Please sign in to comment.