refactoring the networking stuff

master
Jordan Orelli 5 years ago
parent c641df65af
commit fcaf7122ea

@ -102,26 +102,46 @@ public class Networking : ScriptableObject {
return;
}
GameObject soul;
switch (parts[0]) {
case "spawn-soul":
Debug.LogFormat("spawn a soul: {0}", parts[1]);
SpawnSoul ss = JsonUtility.FromJson<SpawnSoul>(parts[1]);
soul = Instantiate(soulPrefab, ss.position, Quaternion.identity);
soul.name = ss.playerName;
SpawnSoul spawned = JsonUtility.FromJson<SpawnSoul>(parts[1]);
onSpawnSoul(spawned);
break;
case "soul-collected":
CollectSoul collected = JsonUtility.FromJson<CollectSoul>(parts[1]);
onSoulCollected(collected);
break;
case "login-result":
LoginResult login = JsonUtility.FromJson<LoginResult>(parts[1]);
onLoginResult(login);
break;
case "tick":
break;
default:
Debug.LogFormat("also can't handle this one: {0} {1}", parts[0], parts[1]);
break;
}
}
private void onSpawnSoul(SpawnSoul spawn) {
Debug.LogFormat("spawn a soul: {0}", spawn);
GameObject soul = Instantiate(soulPrefab, spawn.position, Quaternion.identity);
soul.name = spawn.playerName;
GameObject allSouls = GameObject.Find("Souls");
soul.transform.SetParent(allSouls.transform);
SoulController sc = soul.GetComponent<SoulController>();
sc.playerName = ss.playerName;
break;
sc.playerName = spawn.playerName;
}
case "soul-collected":
Debug.LogFormat("a soul was collected: {0}", parts[1]);
CollectSoul collected = JsonUtility.FromJson<CollectSoul>(parts[1]);
soul = GameObject.Find("Souls/"+collected.playerName);
private void onSoulCollected(CollectSoul collected) {
Debug.LogFormat("a soul was collected: {0}", collected);
GameObject soul = GameObject.Find("Souls/"+collected.playerName);
Destroy(soul);
if (collected.playerName == loginInfo.playerName) {
@ -133,26 +153,16 @@ public class Networking : ScriptableObject {
cc.player = player.transform;
}
}
break;
}
case "login-result":
Debug.LogFormat("received login result: {0}", parts[1]);
private void onLoginResult(LoginResult result) {
Debug.LogFormat("received login result: {0}", result);
loginInfo.sentLogin = false;
LoginResult login = JsonUtility.FromJson<LoginResult>(parts[1]);
if (login.passed) {
if (result.passed) {
loginInfo.isLoggedIn = true;
} else {
loginInfo.loginError = login.error;
Debug.LogErrorFormat("failed login: {0}", login.error);
}
break;
case "tick":
break;
default:
Debug.LogFormat("also can't handle this one: {0} {1}", parts[0], parts[1]);
break;
loginInfo.loginError = result.error;
Debug.LogErrorFormat("failed login: {0}", result.error);
}
}

Loading…
Cancel
Save