Skip to content

Commit adb6fbb

Browse files
authored
feat: add interactions to Loading Docs (#75)
1 parent 3f78d66 commit adb6fbb

21 files changed

+889
-224
lines changed

Assets/DevTools/CSV/CsvConverter.cs

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,6 @@ Object context
8080
_lookup.Add("is_RT_present", InteractionContext.IsRTPresent);
8181
_lookup.Add("call_other", InteractionContext.CallOther);
8282
_lookup.Add("enter", InteractionContext.Enter);
83-
_lookup.Add("available_item", InteractionContext.AvailableItem);
8483
_lookup.Add("LT_item", InteractionContext.LTItem);
8584
_lookup.Add("RT_item", InteractionContext.RTItem);
8685

@@ -155,9 +154,11 @@ Object context
155154
try {
156155
switch (cells.Type()) {
157156
case "fact":
158-
case "item":
159157
CreateFactEntry(cells, previous);
160158
break;
159+
case "item":
160+
CreateItemEntry(cells, previous);
161+
break;
161162
case "event":
162163
previous = CreateEventEntry(cells, previous);
163164
break;
@@ -209,6 +210,18 @@ BaseEntry previous
209210
return entry;
210211
}
211212

213+
private static BaseEntry CreateItemEntry(
214+
List<string> cells,
215+
BaseEntry previous
216+
) {
217+
var entry = _lookup[cells.Key()].GetEntry();
218+
BeginConversion(entry, cells, previous);
219+
entry.Scope = InteractionContext.InteractionScope;
220+
EndConversion(entry);
221+
222+
return entry;
223+
}
224+
212225
private static BaseEntry CreateEventEntry(
213226
List<string> cells,
214227
BaseEntry previous

Assets/Environment/Floodlight.cs

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
using Aarthificial.Typewriter;
2+
using Aarthificial.Typewriter.Attributes;
3+
using Aarthificial.Typewriter.Entries;
4+
using Aarthificial.Typewriter.References;
5+
using Aarthificial.Typewriter.Tools;
6+
using Interactions;
7+
using Typewriter;
8+
using UnityEngine;
9+
using Utils;
10+
11+
namespace Environment {
12+
public class Floodlight : MonoBehaviour {
13+
[SerializeField]
14+
[EntryFilter(BaseType = typeof(ItemEntry), AllowEmpty = true)]
15+
private EntryReference _itemFilter;
16+
[SerializeField]
17+
[EntryFilter(Variant = EntryVariant.Fact)]
18+
private EntryReference _turnedOnFact;
19+
[SerializeField] private Interactable _interactable;
20+
[SerializeField] private Light[] _lights;
21+
22+
private TypewriterWatcher _watcher;
23+
private Cached<bool> _turnedOn;
24+
25+
private void Update() {
26+
if (!_watcher.ShouldUpdate()
27+
|| !_turnedOn.HasChanged(_interactable.Context.Get(_itemFilter) == 1)) {
28+
return;
29+
}
30+
31+
_interactable.Context.Set(_turnedOnFact, _turnedOn.Value ? 1 : 0);
32+
if (_turnedOn) {
33+
foreach (var lightItem in _lights) {
34+
lightItem.enabled = true;
35+
}
36+
} else {
37+
foreach (var lightItem in _lights) {
38+
lightItem.enabled = false;
39+
}
40+
}
41+
}
42+
}
43+
}

Assets/Environment/Floodlight.cs.meta

Lines changed: 3 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
version https://git-lfs.github.com/spec/v1
2-
oid sha256:acbd653f24bbf426fc400c61f5153441de47cb50cb778977a6e7a2c045ad349e
2+
oid sha256:ddc66bfc6cacf3ee21f487e9be36e8dbf5530427b6af225826f71765c2c65c00
33
size 20796

Assets/Environment/Prefabs/LoadingDocsWorld.prefab

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
using Aarthificial.Typewriter;
2+
using Aarthificial.Typewriter.Attributes;
3+
using Aarthificial.Typewriter.Entries;
4+
using Aarthificial.Typewriter.References;
5+
using Aarthificial.Typewriter.Tools;
6+
using Framework;
7+
using UnityEngine;
8+
using Utils.Tweening;
9+
10+
namespace Environment {
11+
public class SecurityKiosk : MonoBehaviour {
12+
[SerializeField]
13+
[EntryFilter(Variant = EntryVariant.Fact)]
14+
private EntryReference _doorOpenFact;
15+
16+
[SerializeField] private Transform _door;
17+
[SerializeField] private Vector2 _doorAngles;
18+
private SpringTween _doorTween;
19+
private TypewriterWatcher _watcher;
20+
21+
private float CurrentAngle =>
22+
App.Game.Story.Get(_doorOpenFact) == 0 ? _doorAngles.x : _doorAngles.y;
23+
24+
private void Start() {
25+
_doorTween.ForceSet(CurrentAngle);
26+
}
27+
28+
private void Update() {
29+
if (_watcher.ShouldUpdate()) {
30+
_doorTween.Set(CurrentAngle);
31+
}
32+
}
33+
34+
private void FixedUpdate() {
35+
if (_doorTween.FixedUpdate(SpringConfig.Slow)) {
36+
_door.localRotation = Quaternion.Euler(0, _doorTween.X, 0);
37+
}
38+
}
39+
}
40+
}

Assets/Environment/SecurityKiosk.cs.meta

Lines changed: 3 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Assets/Framework/StoryState.cs

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
using Aarthificial.Safekeeper;
22
using Aarthificial.Safekeeper.Stores;
3+
using Aarthificial.Typewriter;
4+
using Aarthificial.Typewriter.Blackboards;
5+
using Interactions;
36
using Saves;
47
using System;
58
using System.Collections;
@@ -9,7 +12,7 @@
912
using Utils;
1013

1114
namespace Framework {
12-
public class StoryState : GameState {
15+
public class StoryState : GameState, ITypewriterContext {
1316
[NonSerialized] public bool IsPaused;
1417
public event Action<bool> LoadingChanged;
1518
public event Action Paused;
@@ -136,5 +139,15 @@ public void AutoSave() {
136139
public void Save() {
137140
_saveScene = true;
138141
}
142+
143+
public bool TryGetBlackboard(int scope, out IBlackboard blackboard) {
144+
if (scope == InteractionContext.GlobalScope) {
145+
blackboard = _saveController.GlobalData.Blackboard;
146+
return true;
147+
}
148+
149+
blackboard = default;
150+
return false;
151+
}
139152
}
140153
}

Assets/Interactions/Conversation.cs

Lines changed: 0 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,7 @@
11
using Aarthificial.Typewriter;
2-
using Aarthificial.Typewriter.Attributes;
3-
using Aarthificial.Typewriter.References;
42
using Cinemachine;
53
using Framework;
6-
using Items;
74
using Player;
8-
using Typewriter;
95
using UnityEngine;
106
using Utils;
117
using View.Overlay;
@@ -30,18 +26,14 @@ InteractionWaypoint waypoint
3026
}
3127

3228
public InteractionWaypoint[] Waypoints;
33-
[EntryFilter(BaseType = typeof(ItemEntry), AllowEmpty = true)]
34-
public EntryReference Item;
3529

3630
private PlayerLookup<Interaction> _interactions;
3731

3832
[SerializeField] private CinemachineVirtualCamera _cameraTemplate;
3933
[SerializeField] private float _orthoSize = 4;
4034
[SerializeField] private InteractionArea _area;
41-
[SerializeField] private Transform _itemTransform;
4235

4336
private CinemachineVirtualCamera _camera;
44-
private Item _itemInstance;
4537
private Camera _mainCamera;
4638

4739
protected override void Awake() {
@@ -62,13 +54,6 @@ protected override void Awake() {
6254
_camera.Priority = 100;
6355
_camera.m_Lens.OrthographicSize = _orthoSize;
6456
_camera.gameObject.SetActive(false);
65-
66-
Context.Set(InteractionContext.AvailableItem, Item);
67-
}
68-
69-
protected override void Start() {
70-
TryInstantiateItem();
71-
base.Start();
7257
}
7358

7459
private void Update() {
@@ -255,32 +240,6 @@ private int IsPresent(PlayerController player) {
255240
return -1;
256241
}
257242

258-
public override void UseItem(EntryReference item) {
259-
base.UseItem(item);
260-
Item = item;
261-
TryInstantiateItem();
262-
}
263-
264-
public override EntryReference PickUpItem() {
265-
base.PickUpItem();
266-
if (_itemInstance != null) {
267-
Destroy(_itemInstance.gameObject);
268-
_itemInstance = null;
269-
}
270-
271-
return Item;
272-
}
273-
274-
protected override void LoadBlackboard() {
275-
Item = Context.Get(InteractionContext.AvailableItem);
276-
}
277-
278-
private void TryInstantiateItem() {
279-
if (Item.TryGetEntry(out ItemEntry itemEntry)) {
280-
_itemInstance = Instantiate(itemEntry.Prefab, _itemTransform);
281-
}
282-
}
283-
284243
private void UpdateGizmo() {
285244
var ltPosition =
286245
(Vector2)_mainCamera.WorldToScreenPoint(Players.LT.transform.position);

Assets/Interactions/Interactable.cs

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,16 @@
22
using Aarthificial.Safekeeper.Attributes;
33
using Aarthificial.Safekeeper.Stores;
44
using Aarthificial.Typewriter;
5+
using Aarthificial.Typewriter.Attributes;
56
using System;
67
using Aarthificial.Typewriter.Blackboards;
78
using Aarthificial.Typewriter.References;
89
using Aarthificial.Typewriter.Tools;
910
using Player;
1011
using Saves;
12+
using Typewriter;
1113
using UnityEngine;
14+
using UnityEngine.Serialization;
1215

1316
namespace Interactions {
1417
public class Interactable : MonoBehaviour, ISaveStore {
@@ -25,6 +28,10 @@ public class Interactable : MonoBehaviour, ISaveStore {
2528
[NonSerialized] public EntryReference Listener;
2629
public InteractionGizmo Gizmo;
2730
public TypewriterEvent Event;
31+
[SerializeField]
32+
[FormerlySerializedAs("Item")]
33+
[EntryFilter(BaseType = typeof(ItemEntry), AllowEmpty = true)]
34+
private EntryReference _initialItem;
2835

2936
public Blackboard Blackboard = new();
3037
public InteractionContext Context;
@@ -49,8 +56,8 @@ private void OnDisable() {
4956

5057
public void OnLoad(SaveControllerBase save) {
5158
Context.Global = ((SaveController)save).GlobalData.Blackboard;
52-
if (save.Data.Read(_id, Blackboard)) {
53-
LoadBlackboard();
59+
if (!save.Data.Read(_id, Blackboard) && _initialItem.HasValue) {
60+
Context.Set(_initialItem, 1);
5461
}
5562
}
5663

@@ -89,19 +96,14 @@ public virtual void OnDialogueExit() {
8996
OnStateChanged();
9097
}
9198

92-
protected virtual void OnStateChanged() {
99+
protected void OnStateChanged() {
93100
StateChanged?.Invoke();
94101
}
95102

96-
public virtual void UseItem(EntryReference item) {
97-
Blackboard.Set(InteractionContext.AvailableItem, item);
98-
}
99-
100-
public virtual EntryReference PickUpItem() {
101-
Blackboard.Set(InteractionContext.AvailableItem, 0);
102-
return 0;
103+
public void UseItem(EntryReference item) {
104+
if (item.HasValue) {
105+
Blackboard.Set(item, 1);
106+
}
103107
}
104-
105-
protected virtual void LoadBlackboard() { }
106108
}
107109
}

0 commit comments

Comments
 (0)