Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 0 additions & 3 deletions Audio/Audio.cs
Original file line number Diff line number Diff line change
Expand Up @@ -233,9 +233,6 @@ private void RemoveHandle(Audio.Handle handle)
//make sure the sound is really stopped!
if (handle.Instance != null)
{
#if !XNA
handle.Instance.IsLooped = false;
#endif
handle.Instance.Stop();
}

Expand Down
7 changes: 2 additions & 5 deletions Audio/Sound.cs
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ public static Audio.Handle Play(string sound, float volume = -1f, float panning
Instance = instance,
Name = info.Name,
Type = Audio.Type.Sound,
Looped = false
Looped = looped
};
Audio.Instance.AddHandle(handle);
return handle;
Expand All @@ -95,12 +95,10 @@ public static Audio.Handle FadeIn(string sound, bool looped, float duration, Twe
function = TweenFunctions.Linear;

var info = Audio.Instance.audiolist[sound];
var handle = Play(sound, 0.00001f);
var handle = Play(sound, 0.00001f, 0, looped);
if (handle==null || !handle.Success)
return handle;

handle.Instance.IsLooped = looped;

handle.FadeState = 1;
handle.FadeDuration = handle.FadeTimer = duration;
handle.FadeFunction = function;
Expand Down Expand Up @@ -141,7 +139,6 @@ public static void Stop(Audio.Handle sound)
if (sound == null)
return;
#if !NOAUDIO
sound.Instance.IsLooped = false;
sound.Instance.Stop();
#endif
}
Expand Down
5 changes: 1 addition & 4 deletions Core/Content.cs
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,6 @@ public override string ToString()
}
#endif

#if XNA
public static string SoundExtension = ".wav";
#endif


public const string DefaultContext = "<default>";
Expand Down Expand Up @@ -397,7 +394,7 @@ private SoundEffect LoadAffixedSoundEffect(string assetName)

try
{
FileStream fs = new FileStream("Assets/" + assetName + SoundExtension, FileMode.Open);
FileStream fs = new FileStream("Assets/" + assetName + ".wav", FileMode.Open);
SoundEffect snd = SoundEffect.FromStream(fs);
fs.Close();
return snd;
Expand Down
254 changes: 254 additions & 0 deletions Utils/PhantomComponentNotation.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@

namespace Phantom.Utils
{
public enum PCNValueType { Null, Bool, Int, Float, String, Color, Vector2, Vector3, Vector4, CalculatedValue, List, PCNKeyword }

public class PCNKeyword
{
public static string[] Keywords = new string[] { "auto", "odd", "even", "mapWidth", "mapHeight", "symbolCount" };
Expand Down Expand Up @@ -835,6 +837,258 @@ public static bool CompareValues(object value1, object value2, PCNOperator oper)
return false;
}

public static void SetValueAndType(object _value, ref PCNValueType valueType, ref int intValue)
{
if (_value is string)
{
intValue = ((string)_value).GetHashCode();
valueType = PCNValueType.String;
}
else if (_value is int)
{
intValue = (int)_value;
valueType = PCNValueType.Int;
}
else if (_value is bool)
{
intValue = (bool)_value ? 1 : 0;
valueType = PCNValueType.Bool;
}
else if (_value is float)
valueType = PCNValueType.Float;
else if (_value is Vector2)
valueType = PCNValueType.Vector2;
else if (_value is Vector3)
valueType = PCNValueType.Vector3;
else if (_value is Vector4)
valueType = PCNValueType.Vector4;
else if (_value is Color)
valueType = PCNValueType.Color;
else if (_value is CalculatedValue)
valueType = PCNValueType.CalculatedValue;
else if (_value is PCNKeyword)
valueType = PCNValueType.PCNKeyword;
else if (_value is List<object>)
valueType = PCNValueType.List;
else
valueType = PCNValueType.Null;
}


public static bool CompareValues(PCNValueType valueType1, object value1, int intValue1, PCNValueType valueType2, object value2, int intValue2, PCNOperator oper)
{
if (valueType1 == PCNValueType.CalculatedValue)
{
value1 = ((CalculatedValue)value1).GetValue();
SetValueAndType(value1, ref valueType1, ref intValue1);

}
if (value2 is CalculatedValue)
{
value2 = ((CalculatedValue)value2).GetValue();
SetValueAndType(value2, ref valueType2, ref intValue2);
}

if (valueType1 == PCNValueType.Bool && valueType2 == PCNValueType.Int)
{
valueType2 = PCNValueType.Bool;
intValue2 = intValue2 > 0 ? 1 : 0;
}
if (valueType1 == PCNValueType.Bool && valueType2 == PCNValueType.Float)
{
valueType2 = PCNValueType.Bool;
intValue2 = ((float)value2 > 0) ? 1 : 0;
}
if (valueType1 == PCNValueType.Bool && valueType2 == PCNValueType.Null)
{
valueType2 = PCNValueType.Bool;
intValue2 = 0;
}

if (valueType2 == PCNValueType.Bool && valueType1 == PCNValueType.Int)
{
valueType1 = PCNValueType.Bool;
intValue1 = intValue1 > 0 ? 1 : 0;
}
if (valueType2 == PCNValueType.Bool && valueType1 == PCNValueType.Float)
{
valueType1 = PCNValueType.Bool;
intValue1 = ((float)value1 > 0) ? 1 : 0;
}
if (valueType2 == PCNValueType.Bool && valueType1 == PCNValueType.Null)
{
valueType1 = PCNValueType.Bool;
intValue1 = 0;
}

if (valueType1 == PCNValueType.Null && valueType2 == PCNValueType.Int)
{
valueType1 = PCNValueType.Int;
intValue1 = 0;
}
if (valueType1 == PCNValueType.Null && valueType2 == PCNValueType.Float)
{
valueType1 = PCNValueType.Float;
value1 = 0.0f;
}
if (valueType1 == PCNValueType.Null && valueType2 == PCNValueType.Bool)
{
valueType1 = PCNValueType.Bool;
intValue1 = 0;
}

if (valueType2 == PCNValueType.Null && valueType1 == PCNValueType.Int)
{
valueType2 = PCNValueType.Int;
intValue2 = 0;
}
if (valueType2 == PCNValueType.Null && valueType1 == PCNValueType.Float)
{
valueType2 = PCNValueType.Float;
value2 = 0.0f;
}
if (valueType2 == PCNValueType.Null && valueType1 == PCNValueType.Bool)
{
valueType2 = PCNValueType.Bool;
intValue2 = 0;
}


switch (oper)
{
default:
case PCNOperator.EqualTo:
if (valueType1 == PCNValueType.Null && valueType2 == PCNValueType.Null)
return true;
if (valueType1 == PCNValueType.Int && valueType2 == PCNValueType.Int)
return intValue1 == intValue2;
if (valueType1 == PCNValueType.Int && valueType2 == PCNValueType.Float)
return intValue1 == (float)value2;
if (valueType1 == PCNValueType.Float && valueType2 == PCNValueType.Float)
return (float)value1 == (float)value2;
if (valueType1 == PCNValueType.Float && valueType2 == PCNValueType.Int)
return (float)value1 == intValue2;
if (valueType1 == PCNValueType.String && valueType2 == PCNValueType.String)
return intValue1 == intValue2; //comparing the hashes
if (valueType1 == PCNValueType.Color && valueType2 == PCNValueType.Color)
return (Color)value1 == (Color)value2;
if (valueType1 == PCNValueType.Bool && valueType2 == PCNValueType.Bool)
return intValue1 == intValue2;
if (valueType1 == PCNValueType.Vector2 && valueType2 == PCNValueType.Vector2)
return ((Vector2)value1).X == ((Vector2)value2).X && ((Vector2)value1).Y == ((Vector2)value2).Y;
if (valueType1 == PCNValueType.Vector3 && valueType2 == PCNValueType.Vector3)
return ((Vector3)value1).X == ((Vector3)value2).X && ((Vector3)value1).Y == ((Vector3)value2).Y && ((Vector3)value1).Z == ((Vector3)value2).Z;
if (valueType1 == PCNValueType.Vector4 && valueType2 == PCNValueType.Vector4)
return ((Vector4)value1).X == ((Vector4)value2).X && ((Vector4)value1).Y == ((Vector4)value2).Y && ((Vector4)value1).Z == ((Vector4)value2).Z && ((Vector4)value1).W == ((Vector4)value2).W;
if (valueType1 == PCNValueType.Int && valueType2 == PCNValueType.PCNKeyword && (value2 as PCNKeyword).Value == "even")
return intValue1 % 2 == 0;
if (valueType1 == PCNValueType.Int && valueType2 == PCNValueType.PCNKeyword && (value2 as PCNKeyword).Value == "odd")
return intValue1 % 2 == 1;

break;
case PCNOperator.NotEqualTo:
if (valueType1 == PCNValueType.Null && valueType2 == PCNValueType.Null)
return false;
if (valueType1 == PCNValueType.Int && valueType2 == PCNValueType.Int)
return intValue1 != intValue2;
if (valueType1 == PCNValueType.Int && valueType2 == PCNValueType.Float)
return intValue1 != (float)value2;
if (valueType1 == PCNValueType.Float && valueType2 == PCNValueType.Float)
return (float)value1 != (float)value2;
if (valueType1 == PCNValueType.Float && valueType2 == PCNValueType.Int)
return (float)value1 != intValue2;
if (valueType1 == PCNValueType.String && valueType2 == PCNValueType.String)
return intValue1 != intValue2;
if (valueType1 == PCNValueType.Color && valueType2 == PCNValueType.Color)
return (Color)value1 != (Color)value2;
if (valueType1 == PCNValueType.Bool && valueType2 == PCNValueType.Bool)
return intValue1 != intValue2;
if (valueType1 == PCNValueType.Vector2 && valueType2 == PCNValueType.Vector2)
return ((Vector2)value1).X != ((Vector2)value2).X || ((Vector2)value1).Y != ((Vector2)value2).Y;
if (valueType1 == PCNValueType.Vector3 && valueType2 == PCNValueType.Vector3)
return ((Vector3)value1).X != ((Vector3)value2).X || ((Vector3)value1).Y != ((Vector3)value2).Y || ((Vector3)value1).Z != ((Vector3)value2).Z;
if (valueType1 == PCNValueType.Vector4 && valueType2 == PCNValueType.Vector4)
return ((Vector4)value1).X != ((Vector4)value2).X || ((Vector4)value1).Y != ((Vector4)value2).Y || ((Vector4)value1).Z != ((Vector4)value2).Z || ((Vector4)value1).W != ((Vector4)value2).W;
if (valueType1 == PCNValueType.Int && valueType2 == PCNValueType.PCNKeyword && (value2 as PCNKeyword).Value == "even")
return intValue1 % 2 != 0;
if (valueType1 == PCNValueType.Int && valueType2 == PCNValueType.PCNKeyword && (value2 as PCNKeyword).Value == "odd")
return intValue1 % 2 != 1;

return true;
case PCNOperator.GreaterThan:
if (valueType1 == PCNValueType.Int && valueType2 == PCNValueType.Int)
return intValue1 > intValue2;
if (valueType1 == PCNValueType.Int && valueType2 == PCNValueType.Float)
return intValue1 > (float)value2;
if (valueType1 == PCNValueType.Float && valueType2 == PCNValueType.Float)
return (float)value1 > (float)value2;
if (valueType1 == PCNValueType.Float && valueType2 == PCNValueType.Int)
return (float)value1 > intValue2;
break;
case PCNOperator.GreaterThanOrEqualTo:
if (valueType1 == PCNValueType.Int && valueType2 == PCNValueType.Int)
return intValue1 >= intValue2;
if (valueType1 == PCNValueType.Int && valueType2 == PCNValueType.Float)
return intValue1 >= (float)value2;
if (valueType1 == PCNValueType.Float && valueType2 == PCNValueType.Float)
return (float)value1 >= (float)value2;
if (valueType1 == PCNValueType.Float && valueType2 == PCNValueType.Int)
return (float)value1 >= intValue2;
break;
case PCNOperator.LessThan:
if (valueType1 == PCNValueType.Int && valueType2 == PCNValueType.Int)
return intValue1 < intValue2;
if (valueType1 == PCNValueType.Int && valueType2 == PCNValueType.Float)
return intValue1 < (float)value2;
if (valueType1 == PCNValueType.Float && valueType2 == PCNValueType.Float)
return (float)value1 < (float)value2;
if (valueType1 == PCNValueType.Float && valueType2 == PCNValueType.Int)
return (float)value1 < intValue2;
break;
case PCNOperator.LessThanOrEqualTo:
if (valueType1 == PCNValueType.Int && valueType2 == PCNValueType.Int)
return intValue1 <= intValue2;
if (valueType1 == PCNValueType.Int && valueType2 == PCNValueType.Float)
return intValue1 <= (float)value2;
if (valueType1 == PCNValueType.Float && valueType2 == PCNValueType.Float)
return (float)value1 <= (float)value2;
if (valueType1 == PCNValueType.Int && valueType2 == PCNValueType.Int)
return (float)value1 <= intValue2;
break;
case PCNOperator.BitwiseAnd:
if (valueType1 == PCNValueType.List)
{
List<object> l = (List<object>)value1;
string s = ValueToString(value2);
for (int i = 0; i < l.Count; i++)
{
if (ValueToString(l[i]) == s)
{
return true;
}
}
return false;
}
break;
case PCNOperator.BitwiseXor:
if (valueType1 == PCNValueType.List)
{
List<object> l = (List<object>)value1;
string s = ValueToString(value2);
for (int i = 0; i < l.Count; i++)
{
if (ValueToString(l[i]) == s)
{
return false;
}
}
return true;
}
break;
}
return false;
}

[Obsolete("This function will be removed in the future. Please pass the operator as a PCNOperator", false)]
public static object TransformValue(object target, object source, string oper)
{
Expand Down