Skip to content

Commit

Permalink
Fixed time speed and difficulty creative powers. (#1874)
Browse files Browse the repository at this point in the history
* Fixed time speed and difficulty creative powers.

* Fixed time speed and difficulty creative powers.
  • Loading branch information
RussDev7 authored Aug 7, 2023
1 parent a10fffc commit ae4a15a
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 34 deletions.
36 changes: 26 additions & 10 deletions src/TEdit/Terraria/CreativePowers.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System.IO;
using System;
using System.IO;
using System.Collections.Generic;
using Microsoft.Xna.Framework;
using SharpDX.Direct3D11;
Expand All @@ -22,7 +23,7 @@ public enum CreativePowerId : ushort
rain_setfrozen = 9,
wind_setfrozen = 10,
increaseplacementrange = 11, // player only
setdifficulty = 12, // player only
setdifficulty = 12,
biomespread_setfrozen = 13,
setspawnrate = 14,
}
Expand All @@ -49,11 +50,21 @@ public void SetPowerStateSafe(CreativePowerId id, float? value = null, bool? isE
switch (id)
{
case CreativePowerId.time_setspeed:
if (_powers.ContainsKey(id) && value != null)
{
_powers[id] = MathHelper.Clamp((float)value, 0, 1f);
}
return;
case CreativePowerId.setdifficulty:
if (_powers.ContainsKey(id) && value != null)
{
_powers[id] = MathHelper.Clamp((float)value, 0, 1f);
}
return;
case CreativePowerId.setspawnrate:
if (_powers.ContainsKey(id) && value != null)
{
_powers[id] = MathHelper.Clamp((float)id, 0, 1f);
_powers[id] = MathHelper.Clamp((float)value, 0, 1f);
}
return;
default:
Expand All @@ -72,11 +83,6 @@ public void SetPowerStateSafe(CreativePowerArgs args)
case CreativePowerId.time_setspeed:
case CreativePowerId.setdifficulty:
case CreativePowerId.setspawnrate:
if (_powers.ContainsKey(args.Id))
{
_powers[args.Id] = MathHelper.Clamp((float)args.Value, 0, 1f);
}
return;
default:
if (_powers.ContainsKey(args.Id))
{
Expand Down Expand Up @@ -108,7 +114,17 @@ public void SetPowerStateSafe(CreativePowerArgs args)
switch (id)
{
case CreativePowerId.time_setspeed:
if (_powers.TryGetValue(id, out object t))
{
return (float)t;
}
return null;
case CreativePowerId.setdifficulty:
if (_powers.TryGetValue(id, out object u))
{
return (float)u;
}
return null;
case CreativePowerId.setspawnrate:
if (_powers.TryGetValue(id, out object v))
{
Expand All @@ -119,7 +135,7 @@ public void SetPowerStateSafe(CreativePowerArgs args)
throw new System.ArgumentOutOfRangeException(nameof(id), $"Power {id.ToString()} is not type of float.");
}
}

// public bool DisablePower(CreativePowerId id) => _powers.Remove(id);

public void Save(BinaryWriter w)
Expand All @@ -138,7 +154,7 @@ public void Save(BinaryWriter w)
w.Write((bool)item.Value);
break;
case CreativePowerId.time_setspeed:
w.Write(MathHelper.Clamp((float)item.Value, 0, 1f));
w.Write((float)item.Value);
break;
case CreativePowerId.rain_setfrozen:
w.Write((bool)item.Value);
Expand Down
48 changes: 24 additions & 24 deletions src/TEdit/ViewModel/CreativePowersViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,11 @@ public class CreativePowersViewModel : ObservableObject
private bool _IsBiomeSpreadFrozen = false;

private float _TimeSpeed = 0f;
//private float _Difficulty = 0f;
private float _Difficulty = 0f;
private float _SpawnRate = 0f;

private bool _EnableTimeSpeed = false;
//private bool _EnableDifficulty = false;
private bool _EnableDifficulty = false;
private bool _EnableSpawnRate = false;

private ICommand _SavePowersCommand;
Expand Down Expand Up @@ -59,9 +59,9 @@ public void LoadFromWorld()
EnableTimeSpeed = (timeSpeed != null);
TimeSpeed = timeSpeed ?? 0f;

//var setdifficulty = powers.GetPowerFloat(CreativePowers.CreativePowerId.setdifficulty);
//EnableDifficulty = (setdifficulty != null);
//Difficulty = setdifficulty ?? 0f;
var setdifficulty = powers.GetPowerFloat(CreativePowers.CreativePowerId.setdifficulty);
EnableDifficulty = (setdifficulty != null);
Difficulty = setdifficulty ?? 0f;

IsTimeFrozen = powers.GetPowerBool(CreativePowers.CreativePowerId.time_setfrozen) ?? false;
//IsGodMode = powers.GetPowerBool(CreativePowers.CreativePowerId.godmode) ?? false;
Expand All @@ -78,7 +78,7 @@ public void SaveToWorld()

powers.SetPowerStateSafe(CreativePowers.CreativePowerId.setspawnrate, value: EnableSpawnRate ? SpawnRate : null);
powers.SetPowerStateSafe(CreativePowers.CreativePowerId.time_setspeed, value: EnableTimeSpeed ? TimeSpeed : null);
//powers.SetPowerStateSafe(CreativePowers.CreativePowerId.setdifficulty, value: EnableDifficulty ? Difficulty : null);
powers.SetPowerStateSafe(CreativePowers.CreativePowerId.setdifficulty, value: EnableDifficulty ? Difficulty : null);
powers.SetPowerStateSafe(CreativePowers.CreativePowerId.time_setfrozen, isEnabled: IsTimeFrozen);
//powers.SetPowerStateSafe(CreativePowers.CreativePowerId.godmode, isEnabled: IsGodMode);
powers.SetPowerStateSafe(CreativePowers.CreativePowerId.rain_setfrozen, isEnabled: IsRainFrozen);
Expand All @@ -92,11 +92,11 @@ public bool EnableSpawnRate
get { return _EnableSpawnRate; }
set { Set(nameof(EnableSpawnRate), ref _EnableSpawnRate, value); }
}
//public bool EnableDifficulty
//{
// get { return _EnableDifficulty; }
// set { Set(nameof(EnableDifficulty), ref _EnableDifficulty, value); }
//}
public bool EnableDifficulty
{
get { return _EnableDifficulty; }
set { Set(nameof(EnableDifficulty), ref _EnableDifficulty, value); }
}
public bool EnableTimeSpeed
{
get { return _EnableTimeSpeed; }
Expand Down Expand Up @@ -127,20 +127,20 @@ public float SpawnRate
/// 0.6666666f: 1x normal difficulty
/// 1: 0.5x creative difficulty
/// </summary>
//public float Difficulty
//{
// get { return _Difficulty; }
// set
// {
// Set(nameof(Difficulty), ref _Difficulty, value);
// RaisePropertyChanged(nameof(DifficultyUI));
// }
//}
public float Difficulty
{
get { return _Difficulty; }
set
{
Set(nameof(Difficulty), ref _Difficulty, value);
RaisePropertyChanged(nameof(DifficultyUI));
}
}

//public float DifficultyUI => (float)System.Math.Round(
// ((double)this.Difficulty > 0.330000013113022 ?
// Calc.Remap(Difficulty, 0.33f, 1f, 1f, 3f) :
// Calc.Remap(Difficulty, 0.0f, 0.33f, 0.5f, 1f)) * 20) / 20f;
public float DifficultyUI => (float)System.Math.Round(
((double)this.Difficulty > 0.330000013113022 ?
Calc.Remap(Difficulty, 0.33f, 1f, 1f, 3f) :
Calc.Remap(Difficulty, 0.0f, 0.33f, 0.5f, 1f)) * 20) / 20f;


/// <summary>
Expand Down

0 comments on commit ae4a15a

Please sign in to comment.