//////////////////// // un/redoing public void SetSize(int idx, int size) { Assert.IsTrue(spawnedSpecies.ContainsKey(idx), "idx not spawned"); Species s = spawnedSpecies[idx]; s.BodySize = size; OnSizeSet?.Invoke(idx, sizeTrait.NormaliseValue(size)); factory.RegenerateSpecies(s.GObject, sizeTrait.NormaliseValue(s.BodySize), greedTrait.NormaliseValue(s.Greediness), s.RandomSeed); if (inspected == s) { sizeTrait.SetValueWithoutCallback(s.BodySize); greedTrait.SetValueWithoutCallback(s.Greediness); } s.Status.SetSize(sizeTrait.PositivifyValue(size)); }
void SetSizeFromSlider(int prevValue, int newValue) { Assert.IsTrue(incubated != null || inspected != null, "nothing inspected or incubated"); Assert.IsFalse(incubated != null && inspected != null, "both inspecting and incubating"); Species toSet = incubated != null? incubated : inspected; toSet.BodySize = newValue; toSet.Status?.SetSize(sizeTrait.PositivifyValue(toSet.BodySize)); factory.RegenerateSpecies(toSet.GObject, sizeTrait.NormaliseValue(toSet.BodySize), greedTrait.NormaliseValue(toSet.Greediness), toSet.RandomSeed); SetNameIfNotUser(toSet); if (inspected != null) // only call events on spawned species { OnSizeSet?.Invoke(toSet.Idx, sizeTrait.NormaliseValue(newValue)); OnUserSizeSet?.Invoke(toSet.Idx, prevValue, newValue); } }
private void SpawnWithNonUserEvents(Species toSpawn) { if (graveyard.ContainsKey(toSpawn.Idx)) { // toSpawn.GObject.SetActive(true); graveyard.Remove(toSpawn.Idx); } spawnedSpecies[toSpawn.Idx] = toSpawn; if (toSpawn.Status == null) { toSpawn.Status = Instantiate(statusPrefab, statusCanvas.transform); toSpawn.Status.FollowSpecies(toSpawn.GObject); toSpawn.Status.SetSize(sizeTrait.PositivifyValue(toSpawn.BodySize)); toSpawn.Status.SetGreed(greedTrait.PositivifyValue(toSpawn.Greediness)); toSpawn.Status.ShowHealth(); } // must be invoked first so that nodelink focuses after adding OnSpawned?.Invoke(toSpawn.Idx, toSpawn.IsProducer, toSpawn.GObject); OnSizeSet?.Invoke(toSpawn.Idx, sizeTrait.NormaliseValue(toSpawn.BodySize)); OnGreedSet?.Invoke(toSpawn.Idx, greedTrait.NormaliseValue(toSpawn.Greediness)); }