Skip to content

Commit 18b29c7

Browse files
authored
Blackholio - Logging back in and resuming gameplay (#2990)
# Description of Changes - Previous to this PR if you login, create a player, then logout and log back in you are prompted for a username again instead of just resuming your gameplay. This is confusing to players because it seems like your token is not being reused and you are just creating a new player. # API and ABI breaking changes None # Expected complexity level and risk 1 - this is a demo change but technically affects the testsuite # Testing 1. Clear your token, then open the game, create a player. Then logout 2. Without clearing your token, log back into the game. 3. Make sure that: - Your username is correct - Your circles are where you left them (and the amount of circles is correct.)
1 parent 37c64c7 commit 18b29c7

46 files changed

Lines changed: 251 additions & 74 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

demo/Blackholio/client-unity/Assets/Scenes/Main.unity

Lines changed: 22 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,7 @@ GameObject:
191191
m_Icon: {fileID: 0}
192192
m_NavMeshLayer: 0
193193
m_StaticEditorFlags: 0
194-
m_IsActive: 1
194+
m_IsActive: 0
195195
--- !u!224 &75691256
196196
RectTransform:
197197
m_ObjectHideFlags: 0
@@ -665,10 +665,10 @@ RectTransform:
665665
- {fileID: 15926227}
666666
m_Father: {fileID: 920270125}
667667
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
668-
m_AnchorMin: {x: 0, y: 0}
669-
m_AnchorMax: {x: 0, y: 0}
670-
m_AnchoredPosition: {x: 0, y: 0}
671-
m_SizeDelta: {x: 0, y: 0}
668+
m_AnchorMin: {x: 0, y: 1}
669+
m_AnchorMax: {x: 0, y: 1}
670+
m_AnchoredPosition: {x: 119.685, y: -18.51}
671+
m_SizeDelta: {x: 239.37, y: 37.02}
672672
m_Pivot: {x: 0.5, y: 0.5}
673673
--- !u!114 &380907976
674674
MonoBehaviour:
@@ -1214,10 +1214,10 @@ RectTransform:
12141214
m_Children: []
12151215
m_Father: {fileID: 867669873}
12161216
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
1217-
m_AnchorMin: {x: 0, y: 0}
1218-
m_AnchorMax: {x: 0, y: 0}
1219-
m_AnchoredPosition: {x: 0, y: 0}
1220-
m_SizeDelta: {x: 0, y: 0}
1217+
m_AnchorMin: {x: 0, y: 1}
1218+
m_AnchorMax: {x: 0, y: 1}
1219+
m_AnchoredPosition: {x: 209.305, y: -40.11}
1220+
m_SizeDelta: {x: 378.61, y: 40.22}
12211221
m_Pivot: {x: 0.5, y: 0.5}
12221222
--- !u!114 &734198859
12231223
MonoBehaviour:
@@ -1335,7 +1335,7 @@ GameObject:
13351335
m_Icon: {fileID: 0}
13361336
m_NavMeshLayer: 0
13371337
m_StaticEditorFlags: 0
1338-
m_IsActive: 1
1338+
m_IsActive: 0
13391339
--- !u!224 &867669873
13401340
RectTransform:
13411341
m_ObjectHideFlags: 0
@@ -1356,7 +1356,7 @@ RectTransform:
13561356
m_AnchorMin: {x: 0.5, y: 0.5}
13571357
m_AnchorMax: {x: 0.5, y: 0.5}
13581358
m_AnchoredPosition: {x: 0, y: 0}
1359-
m_SizeDelta: {x: 0, y: 0}
1359+
m_SizeDelta: {x: 418.61, y: 216.14}
13601360
m_Pivot: {x: 0.5, y: 0.5}
13611361
--- !u!114 &867669874
13621362
MonoBehaviour:
@@ -1620,10 +1620,10 @@ RectTransform:
16201620
- {fileID: 380907975}
16211621
m_Father: {fileID: 867669873}
16221622
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
1623-
m_AnchorMin: {x: 0, y: 0}
1624-
m_AnchorMax: {x: 0, y: 0}
1625-
m_AnchoredPosition: {x: 0, y: 0}
1626-
m_SizeDelta: {x: 0, y: 0}
1623+
m_AnchorMin: {x: 0, y: 1}
1624+
m_AnchorMax: {x: 0, y: 1}
1625+
m_AnchoredPosition: {x: 209.305, y: -96.03001}
1626+
m_SizeDelta: {x: 239.37, y: 37.02}
16271627
m_Pivot: {x: 0.5, y: 0.5}
16281628
--- !u!114 &920270126
16291629
MonoBehaviour:
@@ -1826,8 +1826,10 @@ MonoBehaviour:
18261826
m_Script: {fileID: 11500000, guid: fdf6b37246fc5824eb3c4e6888c33a4a, type: 3}
18271827
m_Name:
18281828
m_EditorClassIdentifier:
1829+
elements:
1830+
- {fileID: 75691255}
1831+
- {fileID: 867669872}
18291832
UsernameInputField: {fileID: 380907977}
1830-
PlayButton: {fileID: 1670294508}
18311833
--- !u!1 &1005992895
18321834
GameObject:
18331835
m_ObjectHideFlags: 0
@@ -2424,10 +2426,10 @@ RectTransform:
24242426
- {fileID: 1005992896}
24252427
m_Father: {fileID: 867669873}
24262428
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
2427-
m_AnchorMin: {x: 0, y: 0}
2428-
m_AnchorMax: {x: 0, y: 0}
2429-
m_AnchoredPosition: {x: 0, y: 0}
2430-
m_SizeDelta: {x: 0, y: 0}
2429+
m_AnchorMin: {x: 0, y: 1}
2430+
m_AnchorMax: {x: 0, y: 1}
2431+
m_AnchoredPosition: {x: 209.305, y: -163.98999}
2432+
m_SizeDelta: {x: 179.31, y: 64.3}
24312433
m_Pivot: {x: 0.5, y: 0.5}
24322434
--- !u!114 &1670294507
24332435
MonoBehaviour:

demo/Blackholio/client-unity/Assets/Scripts/CameraController.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
using System.Collections;
22
using System.Collections.Generic;
3+
using SpacetimeDB.Types;
34
using UnityEngine;
45

56
public class CameraController : MonoBehaviour
@@ -9,10 +10,10 @@ public class CameraController : MonoBehaviour
910
private void LateUpdate()
1011
{
1112
var arenaCenterTransform = new Vector3(WorldSize / 2, WorldSize / 2, -10.0f);
12-
if (PlayerController.Local == null || !GameManager.IsConnected())
13+
if (PlayerController.Local == null || !GameManager.IsConnected() || PlayerController.Local.NumberOfOwnedCircles == 0)
1314
{
1415
// Set the camera to be in middle of the arena if we are not connected or
15-
// there is no local player
16+
// there are no circles to follow
1617
transform.position = arenaCenterTransform;
1718
return;
1819
}

demo/Blackholio/client-unity/Assets/Scripts/EntityController.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,15 +16,15 @@ public abstract class EntityController : MonoBehaviour
1616

1717
protected float LerpTime;
1818
protected Vector3 LerpStartPosition;
19-
protected Vector3 LerpTargetPositio;
19+
protected Vector3 LerpTargetPosition;
2020
protected Vector3 TargetScale;
2121

2222
protected virtual void Spawn(uint entityId)
2323
{
2424
EntityId = entityId;
2525

2626
var entity = GameManager.Conn.Db.Entity.EntityId.Find(entityId);
27-
LerpStartPosition = LerpTargetPositio = transform.position = (Vector2)entity.Position;
27+
LerpStartPosition = LerpTargetPosition = transform.position = (Vector2)entity.Position;
2828
transform.localScale = Vector3.one;
2929
TargetScale = MassToScale(entity.Mass);
3030
}
@@ -38,7 +38,7 @@ public virtual void OnEntityUpdated(Entity newVal)
3838
{
3939
LerpTime = 0.0f;
4040
LerpStartPosition = transform.position;
41-
LerpTargetPositio = (Vector2)newVal.Position;
41+
LerpTargetPosition = (Vector2)newVal.Position;
4242
TargetScale = MassToScale(newVal.Mass);
4343
}
4444

@@ -78,7 +78,7 @@ public virtual void Update()
7878
{
7979
//Interpolate position and scale
8080
LerpTime = Mathf.Min(LerpTime + Time.deltaTime, LERP_DURATION_SEC);
81-
transform.position = Vector3.Lerp(LerpStartPosition, LerpTargetPositio, LerpTime / LERP_DURATION_SEC);
81+
transform.position = Vector3.Lerp(LerpStartPosition, LerpTargetPosition, LerpTime / LERP_DURATION_SEC);
8282
transform.localScale = Vector3.Lerp(transform.localScale, TargetScale, Time.deltaTime * 8);
8383
}
8484

demo/Blackholio/client-unity/Assets/Scripts/GameManager.cs

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ private void Start()
5050
// and their circles will be able to eat each other.
5151
if (AuthToken.Token != "")
5252
{
53+
Debug.Log("Using auth token!");
5354
builder = builder.WithToken(AuthToken.Token);
5455
}
5556

@@ -98,11 +99,39 @@ private void HandleSubscriptionApplied(SubscriptionEventContext ctx)
9899
{
99100
Debug.Log("Subscription applied!");
100101
OnSubscriptionApplied?.Invoke();
101-
102+
102103
// Once we have the initial subscription sync'd to the client cache
103104
// Get the world size from the config table and set up the arena
104105
var worldSize = Conn.Db.Config.Id.Find(0).WorldSize;
105106
SetupArena(worldSize);
107+
108+
// Check to see if we already have a player, if we don't we'll need to create one
109+
var player = ctx.Db.Player.Identity.Find(LocalIdentity);
110+
if (string.IsNullOrEmpty(player.Name))
111+
{
112+
// The player has to choose a username
113+
UIUsernameChooser.Instance.Show(true);
114+
115+
// When our username is updated, hide the username chooser
116+
Conn.Db.Player.OnUpdate += (_, _, newPlayer) =>
117+
{
118+
if (newPlayer.Identity == LocalIdentity)
119+
{
120+
UIUsernameChooser.Instance.Show(false);
121+
}
122+
};
123+
} else {
124+
// We already have a player
125+
if (ctx.Db.Circle.PlayerId.Filter(player.PlayerId).Any())
126+
{
127+
// We already have at least one circle, we should just be able to start
128+
// playing immediately.
129+
UIUsernameChooser.Instance.Show(false);
130+
} else {
131+
// Create a new circle for our player.
132+
ctx.Reducers.EnterGame(player.Name);
133+
}
134+
}
106135
}
107136

108137
private void SetupArena(float worldSize)

demo/Blackholio/client-unity/Assets/Scripts/UIUsernameChooser.cs

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -8,32 +8,33 @@ public class UIUsernameChooser : MonoBehaviour
88
{
99
public static UIUsernameChooser Instance { get; private set; }
1010

11+
// The elements that compose the username chooser UI
12+
public GameObject[] elements;
1113
public TMPro.TMP_InputField UsernameInputField;
12-
public Button PlayButton;
1314

1415
private void Start()
1516
{
1617
Instance = this;
17-
GameManager.Conn.Db.Player.OnInsert += (ctx, newPlayer) =>
18-
{
19-
if (newPlayer.Identity == GameManager.LocalIdentity)
20-
{
21-
// We have a player
22-
UsernameInputField.text = newPlayer.Name;
23-
}
24-
};
2518
}
2619

2720
public void PlayPressed()
2821
{
2922
Debug.Log("Creating player");
3023

31-
string name = UsernameInputField.text.Trim();
24+
var name = UsernameInputField.text.Trim();
3225
if (string.IsNullOrEmpty(name))
3326
{
3427
name = "<No Name>";
3528
}
3629
GameManager.Conn.Reducers.EnterGame(name);
37-
gameObject.SetActive(false);
30+
Show(false);
3831
}
32+
33+
public void Show(bool showing)
34+
{
35+
foreach (var element in elements)
36+
{
37+
element.SetActive(showing);
38+
}
39+
}
3940
}

demo/Blackholio/client-unity/Assets/Scripts/autogen/Reducers/CircleDecay.g.cs

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

demo/Blackholio/client-unity/Assets/Scripts/autogen/Reducers/CircleRecombine.g.cs

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

demo/Blackholio/client-unity/Assets/Scripts/autogen/Reducers/Connect.g.cs

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

demo/Blackholio/client-unity/Assets/Scripts/autogen/Reducers/ConsumeEntity.g.cs

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

demo/Blackholio/client-unity/Assets/Scripts/autogen/Reducers/Disconnect.g.cs

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)