usability fixes for LightShare API

exception based error messages were cryptic for casual users

Signed-off-by: BlueWall <jamesh@bluewallgroup.com>
inv-download
Freaky Tech 2015-03-04 18:11:55 +01:00 committed by BlueWall
parent e520364f65
commit 061dd3385c
1 changed files with 328 additions and 41 deletions

View File

@ -265,169 +265,438 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
int idx = 0; int idx = 0;
while (idx < rules.Length) while (idx < rules.Length)
{ {
uint rule = (uint)rules.GetLSLIntegerItem(idx); uint rule;
try
{
rule = (uint)rules.GetLSLIntegerItem(idx);
}
catch (InvalidCastException)
{
throw new InvalidCastException(string.Format("Error running rule type: arg #{0} - parameter type must be integer", idx));
}
LSL_Types.Quaternion iQ; LSL_Types.Quaternion iQ;
LSL_Types.Vector3 iV; LSL_Types.Vector3 iV;
switch (rule) switch (rule)
{ {
case (int)ScriptBaseClass.WL_SUN_MOON_POSITION: case (int)ScriptBaseClass.WL_SUN_MOON_POSITION:
idx++; idx++;
try
{
wl.sunMoonPosition = (float)rules.GetLSLFloatItem(idx); wl.sunMoonPosition = (float)rules.GetLSLFloatItem(idx);
}
catch (InvalidCastException)
{
throw new InvalidCastException(string.Format("Error running rule WL_SUN_MOON_POSITION: arg #{0} - parameter 1 must be float", idx));
}
break; break;
case (int)ScriptBaseClass.WL_AMBIENT: case (int)ScriptBaseClass.WL_AMBIENT:
idx++; idx++;
try
{
iQ = rules.GetQuaternionItem(idx); iQ = rules.GetQuaternionItem(idx);
}
catch (InvalidCastException)
{
throw new InvalidCastException(string.Format("Error running rule WL_AMBIENT: arg #{0} - parameter 1 must be rotation", idx));
}
wl.ambient = new Vector4((float)iQ.x, (float)iQ.y, (float)iQ.z, (float)iQ.s); wl.ambient = new Vector4((float)iQ.x, (float)iQ.y, (float)iQ.z, (float)iQ.s);
break; break;
case (int)ScriptBaseClass.WL_BIG_WAVE_DIRECTION: case (int)ScriptBaseClass.WL_BIG_WAVE_DIRECTION:
idx++; idx++;
try
{
iV = rules.GetVector3Item(idx); iV = rules.GetVector3Item(idx);
}
catch (InvalidCastException)
{
throw new InvalidCastException(string.Format("Error running rule WL_BIG_WAVE_DIRECTION: arg #{0} - parameter 1 must be vector", idx));
}
wl.bigWaveDirection = new Vector2((float)iV.x, (float)iV.y); wl.bigWaveDirection = new Vector2((float)iV.x, (float)iV.y);
break; break;
case (int)ScriptBaseClass.WL_BLUE_DENSITY: case (int)ScriptBaseClass.WL_BLUE_DENSITY:
idx++; idx++;
try
{
iQ = rules.GetQuaternionItem(idx); iQ = rules.GetQuaternionItem(idx);
}
catch (InvalidCastException)
{
throw new InvalidCastException(string.Format("Error running rule WL_BLUE_DENSITY: arg #{0} - parameter 1 must be rotation", idx));
}
wl.blueDensity = new Vector4((float)iQ.x, (float)iQ.y, (float)iQ.z, (float)iQ.s); wl.blueDensity = new Vector4((float)iQ.x, (float)iQ.y, (float)iQ.z, (float)iQ.s);
break; break;
case (int)ScriptBaseClass.WL_BLUR_MULTIPLIER: case (int)ScriptBaseClass.WL_BLUR_MULTIPLIER:
idx++; idx++;
try
{
wl.blurMultiplier = (float)rules.GetLSLFloatItem(idx); wl.blurMultiplier = (float)rules.GetLSLFloatItem(idx);
}
catch (InvalidCastException)
{
throw new InvalidCastException(string.Format("Error running rule WL_BLUR_MULTIPLIER: arg #{0} - parameter 1 must be float", idx));
}
break; break;
case (int)ScriptBaseClass.WL_CLOUD_COLOR: case (int)ScriptBaseClass.WL_CLOUD_COLOR:
idx++; idx++;
try
{
iQ = rules.GetQuaternionItem(idx); iQ = rules.GetQuaternionItem(idx);
}
catch (InvalidCastException)
{
throw new InvalidCastException(string.Format("Error running rule WL_CLOUD_COLOR: arg #{0} - parameter 1 must be rotation", idx));
}
wl.cloudColor = new Vector4((float)iQ.x, (float)iQ.y, (float)iQ.z, (float)iQ.s); wl.cloudColor = new Vector4((float)iQ.x, (float)iQ.y, (float)iQ.z, (float)iQ.s);
break; break;
case (int)ScriptBaseClass.WL_CLOUD_COVERAGE: case (int)ScriptBaseClass.WL_CLOUD_COVERAGE:
idx++; idx++;
try
{
wl.cloudCoverage = (float)rules.GetLSLFloatItem(idx); wl.cloudCoverage = (float)rules.GetLSLFloatItem(idx);
}
catch (InvalidCastException)
{
throw new InvalidCastException(string.Format("Error running rule WL_CLOUD_COVERAGE: arg #{0} - parameter 1 must be float", idx));
}
break; break;
case (int)ScriptBaseClass.WL_CLOUD_DETAIL_XY_DENSITY: case (int)ScriptBaseClass.WL_CLOUD_DETAIL_XY_DENSITY:
idx++; idx++;
try
{
iV = rules.GetVector3Item(idx); iV = rules.GetVector3Item(idx);
}
catch (InvalidCastException)
{
throw new InvalidCastException(string.Format("Error running rule WL_CLOUD_DETAIL_XY_DENSITY: arg #{0} - parameter 1 must be vector", idx));
}
wl.cloudDetailXYDensity = iV; wl.cloudDetailXYDensity = iV;
break; break;
case (int)ScriptBaseClass.WL_CLOUD_SCALE: case (int)ScriptBaseClass.WL_CLOUD_SCALE:
idx++; idx++;
try
{
wl.cloudScale = (float)rules.GetLSLFloatItem(idx); wl.cloudScale = (float)rules.GetLSLFloatItem(idx);
}
catch (InvalidCastException)
{
throw new InvalidCastException(string.Format("Error running rule WL_CLOUD_SCALE: arg #{0} - parameter 1 must be float", idx));
}
break; break;
case (int)ScriptBaseClass.WL_CLOUD_SCROLL_X: case (int)ScriptBaseClass.WL_CLOUD_SCROLL_X:
idx++; idx++;
try
{
wl.cloudScrollX = (float)rules.GetLSLFloatItem(idx); wl.cloudScrollX = (float)rules.GetLSLFloatItem(idx);
}
catch (InvalidCastException)
{
throw new InvalidCastException(string.Format("Error running rule WL_CLOUD_SCROLL_X: arg #{0} - parameter 1 must be float", idx));
}
break; break;
case (int)ScriptBaseClass.WL_CLOUD_SCROLL_X_LOCK: case (int)ScriptBaseClass.WL_CLOUD_SCROLL_X_LOCK:
idx++; idx++;
try
{
wl.cloudScrollXLock = rules.GetLSLIntegerItem(idx).value == 1 ? true : false; wl.cloudScrollXLock = rules.GetLSLIntegerItem(idx).value == 1 ? true : false;
}
catch (InvalidCastException)
{
throw new InvalidCastException(string.Format("Error running rule WL_CLOUD_SCROLL_Y_LOCK: arg #{0} - parameter 1 must be integer", idx));
}
break; break;
case (int)ScriptBaseClass.WL_CLOUD_SCROLL_Y: case (int)ScriptBaseClass.WL_CLOUD_SCROLL_Y:
idx++; idx++;
try
{
wl.cloudScrollY = (float)rules.GetLSLFloatItem(idx); wl.cloudScrollY = (float)rules.GetLSLFloatItem(idx);
}
catch (InvalidCastException)
{
throw new InvalidCastException(string.Format("Error running rule WL_CLOUD_SCROLL_Y: arg #{0} - parameter 1 must be float", idx));
}
break; break;
case (int)ScriptBaseClass.WL_CLOUD_SCROLL_Y_LOCK: case (int)ScriptBaseClass.WL_CLOUD_SCROLL_Y_LOCK:
idx++; idx++;
try
{
wl.cloudScrollYLock = rules.GetLSLIntegerItem(idx).value == 1 ? true : false; wl.cloudScrollYLock = rules.GetLSLIntegerItem(idx).value == 1 ? true : false;
}
catch (InvalidCastException)
{
throw new InvalidCastException(string.Format("Error running rule WL_CLOUD_SCROLL_Y_LOCK: arg #{0} - parameter 1 must be integer", idx));
}
break; break;
case (int)ScriptBaseClass.WL_CLOUD_XY_DENSITY: case (int)ScriptBaseClass.WL_CLOUD_XY_DENSITY:
idx++; idx++;
try
{
iV = rules.GetVector3Item(idx); iV = rules.GetVector3Item(idx);
}
catch (InvalidCastException)
{
throw new InvalidCastException(string.Format("Error running rule WL_CLOUD_XY_DENSITY: arg #{0} - parameter 1 must be vector", idx));
}
wl.cloudXYDensity = iV; wl.cloudXYDensity = iV;
break; break;
case (int)ScriptBaseClass.WL_DENSITY_MULTIPLIER: case (int)ScriptBaseClass.WL_DENSITY_MULTIPLIER:
idx++; idx++;
try
{
wl.densityMultiplier = (float)rules.GetLSLFloatItem(idx); wl.densityMultiplier = (float)rules.GetLSLFloatItem(idx);
}
catch (InvalidCastException)
{
throw new InvalidCastException(string.Format("Error running rule WL_DENSITY_MULTIPLIER: arg #{0} - parameter 1 must be float", idx));
}
break; break;
case (int)ScriptBaseClass.WL_DISTANCE_MULTIPLIER: case (int)ScriptBaseClass.WL_DISTANCE_MULTIPLIER:
idx++; idx++;
try
{
wl.distanceMultiplier = (float)rules.GetLSLFloatItem(idx); wl.distanceMultiplier = (float)rules.GetLSLFloatItem(idx);
}
catch (InvalidCastException)
{
throw new InvalidCastException(string.Format("Error running rule WL_DISTANCE_MULTIPLIER: arg #{0} - parameter 1 must be float", idx));
}
break; break;
case (int)ScriptBaseClass.WL_DRAW_CLASSIC_CLOUDS: case (int)ScriptBaseClass.WL_DRAW_CLASSIC_CLOUDS:
idx++; idx++;
try
{
wl.drawClassicClouds = rules.GetLSLIntegerItem(idx).value == 1 ? true : false; wl.drawClassicClouds = rules.GetLSLIntegerItem(idx).value == 1 ? true : false;
}
catch (InvalidCastException)
{
throw new InvalidCastException(string.Format("Error running rule WL_DRAW_CLASSIC_CLOUDS: arg #{0} - parameter 1 must be integer", idx));
}
break; break;
case (int)ScriptBaseClass.WL_EAST_ANGLE: case (int)ScriptBaseClass.WL_EAST_ANGLE:
idx++; idx++;
try
{
wl.eastAngle = (float)rules.GetLSLFloatItem(idx); wl.eastAngle = (float)rules.GetLSLFloatItem(idx);
}
catch (InvalidCastException)
{
throw new InvalidCastException(string.Format("Error running rule WL_EAST_ANGLE: arg #{0} - parameter 1 must be float", idx));
}
break; break;
case (int)ScriptBaseClass.WL_FRESNEL_OFFSET: case (int)ScriptBaseClass.WL_FRESNEL_OFFSET:
idx++; idx++;
try
{
wl.fresnelOffset = (float)rules.GetLSLFloatItem(idx); wl.fresnelOffset = (float)rules.GetLSLFloatItem(idx);
}
catch (InvalidCastException)
{
throw new InvalidCastException(string.Format("Error running rule WL_FRESNEL_OFFSET: arg #{0} - parameter 1 must be float", idx));
}
break; break;
case (int)ScriptBaseClass.WL_FRESNEL_SCALE: case (int)ScriptBaseClass.WL_FRESNEL_SCALE:
idx++; idx++;
try
{
wl.fresnelScale = (float)rules.GetLSLFloatItem(idx); wl.fresnelScale = (float)rules.GetLSLFloatItem(idx);
}
catch (InvalidCastException)
{
throw new InvalidCastException(string.Format("Error running rule WL_FRESNEL_SCALE: arg #{0} - parameter 1 must be float", idx));
}
break; break;
case (int)ScriptBaseClass.WL_HAZE_DENSITY: case (int)ScriptBaseClass.WL_HAZE_DENSITY:
idx++; idx++;
try
{
wl.hazeDensity = (float)rules.GetLSLFloatItem(idx); wl.hazeDensity = (float)rules.GetLSLFloatItem(idx);
}
catch (InvalidCastException)
{
throw new InvalidCastException(string.Format("Error running rule WL_HAZE_DENSITY: arg #{0} - parameter 1 must be float", idx));
}
break; break;
case (int)ScriptBaseClass.WL_HAZE_HORIZON: case (int)ScriptBaseClass.WL_HAZE_HORIZON:
idx++; idx++;
try
{
wl.hazeHorizon = (float)rules.GetLSLFloatItem(idx); wl.hazeHorizon = (float)rules.GetLSLFloatItem(idx);
}
catch (InvalidCastException)
{
throw new InvalidCastException(string.Format("Error running rule WL_HAZE_HORIZON: arg #{0} - parameter 1 must be float", idx));
}
break; break;
case (int)ScriptBaseClass.WL_HORIZON: case (int)ScriptBaseClass.WL_HORIZON:
idx++; idx++;
try
{
iQ = rules.GetQuaternionItem(idx); iQ = rules.GetQuaternionItem(idx);
}
catch (InvalidCastException)
{
throw new InvalidCastException(string.Format("Error running rule WL_HORIZON: arg #{0} - parameter 1 must be rotation", idx));
}
wl.horizon = new Vector4((float)iQ.x, (float)iQ.y, (float)iQ.z, (float)iQ.s); wl.horizon = new Vector4((float)iQ.x, (float)iQ.y, (float)iQ.z, (float)iQ.s);
break; break;
case (int)ScriptBaseClass.WL_LITTLE_WAVE_DIRECTION: case (int)ScriptBaseClass.WL_LITTLE_WAVE_DIRECTION:
idx++; idx++;
try
{
iV = rules.GetVector3Item(idx); iV = rules.GetVector3Item(idx);
}
catch (InvalidCastException)
{
throw new InvalidCastException(string.Format("Error running rule WL_LITTLE_WAVE_DIRECTION: arg #{0} - parameter 1 must be vector", idx));
}
wl.littleWaveDirection = new Vector2((float)iV.x, (float)iV.y); wl.littleWaveDirection = new Vector2((float)iV.x, (float)iV.y);
break; break;
case (int)ScriptBaseClass.WL_MAX_ALTITUDE: case (int)ScriptBaseClass.WL_MAX_ALTITUDE:
idx++; idx++;
try
{
wl.maxAltitude = (ushort)rules.GetLSLIntegerItem(idx).value; wl.maxAltitude = (ushort)rules.GetLSLIntegerItem(idx).value;
}
catch (InvalidCastException)
{
throw new InvalidCastException(string.Format("Error running rule WL_MAX_ALTITUDE: arg #{0} - parameter 1 must be integer", idx));
}
break; break;
case (int)ScriptBaseClass.WL_NORMAL_MAP_TEXTURE: case (int)ScriptBaseClass.WL_NORMAL_MAP_TEXTURE:
idx++; idx++;
try
{
wl.normalMapTexture = new UUID(rules.GetLSLStringItem(idx).m_string); wl.normalMapTexture = new UUID(rules.GetLSLStringItem(idx).m_string);
}
catch (ArgumentException)
{
throw new InvalidCastException(string.Format("Error running rule WL_NORMAL_MAP_TEXTURE: arg #{0} - parameter 1 must be key", idx));
}
break; break;
case (int)ScriptBaseClass.WL_REFLECTION_WAVELET_SCALE: case (int)ScriptBaseClass.WL_REFLECTION_WAVELET_SCALE:
idx++; idx++;
try
{
iV = rules.GetVector3Item(idx); iV = rules.GetVector3Item(idx);
}
catch (InvalidCastException)
{
throw new InvalidCastException(string.Format("Error running rule WL_REFLECTION_WAVELET_SCALE: arg #{0} - parameter 1 must be vector", idx));
}
wl.reflectionWaveletScale = iV; wl.reflectionWaveletScale = iV;
break; break;
case (int)ScriptBaseClass.WL_REFRACT_SCALE_ABOVE: case (int)ScriptBaseClass.WL_REFRACT_SCALE_ABOVE:
idx++; idx++;
try
{
wl.refractScaleAbove = (float)rules.GetLSLFloatItem(idx); wl.refractScaleAbove = (float)rules.GetLSLFloatItem(idx);
}
catch (InvalidCastException)
{
throw new InvalidCastException(string.Format("Error running rule WL_REFRACT_SCALE_ABOVE: arg #{0} - parameter 1 must be float", idx));
}
break; break;
case (int)ScriptBaseClass.WL_REFRACT_SCALE_BELOW: case (int)ScriptBaseClass.WL_REFRACT_SCALE_BELOW:
idx++; idx++;
try
{
wl.refractScaleBelow = (float)rules.GetLSLFloatItem(idx); wl.refractScaleBelow = (float)rules.GetLSLFloatItem(idx);
}
catch (InvalidCastException)
{
throw new InvalidCastException(string.Format("Error running rule WL_REFRACT_SCALE_BELOW: arg #{0} - parameter 1 must be float", idx));
}
break; break;
case (int)ScriptBaseClass.WL_SCENE_GAMMA: case (int)ScriptBaseClass.WL_SCENE_GAMMA:
idx++; idx++;
try
{
wl.sceneGamma = (float)rules.GetLSLFloatItem(idx); wl.sceneGamma = (float)rules.GetLSLFloatItem(idx);
}
catch (InvalidCastException)
{
throw new InvalidCastException(string.Format("Error running rule WL_SCENE_GAMMA: arg #{0} - parameter 1 must be float", idx));
}
break; break;
case (int)ScriptBaseClass.WL_STAR_BRIGHTNESS: case (int)ScriptBaseClass.WL_STAR_BRIGHTNESS:
idx++; idx++;
try
{
wl.starBrightness = (float)rules.GetLSLFloatItem(idx); wl.starBrightness = (float)rules.GetLSLFloatItem(idx);
}
catch (InvalidCastException)
{
throw new InvalidCastException(string.Format("Error running rule WL_STAR_BRIGHTNESS: arg #{0} - parameter 1 must be float", idx));
}
break; break;
case (int)ScriptBaseClass.WL_SUN_GLOW_FOCUS: case (int)ScriptBaseClass.WL_SUN_GLOW_FOCUS:
idx++; idx++;
try
{
wl.sunGlowFocus = (float)rules.GetLSLFloatItem(idx); wl.sunGlowFocus = (float)rules.GetLSLFloatItem(idx);
}
catch (InvalidCastException)
{
throw new InvalidCastException(string.Format("Error running rule WL_SUN_GLOW_FOCUS: arg #{0} - parameter 1 must be float", idx));
}
break; break;
case (int)ScriptBaseClass.WL_SUN_GLOW_SIZE: case (int)ScriptBaseClass.WL_SUN_GLOW_SIZE:
idx++; idx++;
try
{
wl.sunGlowSize = (float)rules.GetLSLFloatItem(idx); wl.sunGlowSize = (float)rules.GetLSLFloatItem(idx);
}
catch (InvalidCastException)
{
throw new InvalidCastException(string.Format("Error running rule WL_SUN_GLOW_SIZE: arg #{0} - parameter 1 must be float", idx));
}
break; break;
case (int)ScriptBaseClass.WL_SUN_MOON_COLOR: case (int)ScriptBaseClass.WL_SUN_MOON_COLOR:
idx++; idx++;
iQ = rules.GetQuaternionItem(idx); iQ = rules.GetQuaternionItem(idx);
try
{
wl.sunMoonColor = new Vector4((float)iQ.x, (float)iQ.y, (float)iQ.z, (float)iQ.s); wl.sunMoonColor = new Vector4((float)iQ.x, (float)iQ.y, (float)iQ.z, (float)iQ.s);
}
catch (InvalidCastException)
{
throw new InvalidCastException(string.Format("Error running rule WL_SUN_MOON_COLOR: arg #{0} - parameter 1 must be rotation", idx));
}
break; break;
case (int)ScriptBaseClass.WL_UNDERWATER_FOG_MODIFIER: case (int)ScriptBaseClass.WL_UNDERWATER_FOG_MODIFIER:
idx++; idx++;
try
{
wl.underwaterFogModifier = (float)rules.GetLSLFloatItem(idx); wl.underwaterFogModifier = (float)rules.GetLSLFloatItem(idx);
}
catch (InvalidCastException)
{
throw new InvalidCastException(string.Format("Error running rule WL_UNDERWATER_FOG_MODIFIER: arg #{0} - parameter 1 must be float", idx));
}
break; break;
case (int)ScriptBaseClass.WL_WATER_COLOR: case (int)ScriptBaseClass.WL_WATER_COLOR:
idx++; idx++;
try
{
iV = rules.GetVector3Item(idx); iV = rules.GetVector3Item(idx);
}
catch (InvalidCastException)
{
throw new InvalidCastException(string.Format("Error running rule WL_WATER_COLOR: arg #{0} - parameter 1 must be vector", idx));
}
wl.waterColor = iV; wl.waterColor = iV;
break; break;
case (int)ScriptBaseClass.WL_WATER_FOG_DENSITY_EXPONENT: case (int)ScriptBaseClass.WL_WATER_FOG_DENSITY_EXPONENT:
idx++; idx++;
try
{
wl.waterFogDensityExponent = (float)rules.GetLSLFloatItem(idx); wl.waterFogDensityExponent = (float)rules.GetLSLFloatItem(idx);
}
catch (InvalidCastException)
{
throw new InvalidCastException(string.Format("Error running rule WL_WATER_FOG_DENSITY_EXPONENT: arg #{0} - parameter 1 must be float", idx));
}
break; break;
} }
idx++; idx++;
@ -464,7 +733,16 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
if (LightShareModule.EnableWindlight) if (LightShareModule.EnableWindlight)
{ {
RegionLightShareData wl = getWindlightProfileFromRules(rules); RegionLightShareData wl;
try
{
wl = getWindlightProfileFromRules(rules);
}
catch(InvalidCastException e)
{
LSShoutError(e.Message);
return 0;
}
wl.valid = true; wl.valid = true;
m_host.ParentGroup.Scene.StoreWindlightProfile(wl); m_host.ParentGroup.Scene.StoreWindlightProfile(wl);
success = 1; success = 1;
@ -533,7 +811,16 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
if (LightShareModule.EnableWindlight) if (LightShareModule.EnableWindlight)
{ {
RegionLightShareData wl = getWindlightProfileFromRules(rules); RegionLightShareData wl;
try
{
wl = getWindlightProfileFromRules(rules);
}
catch(InvalidCastException e)
{
LSShoutError(e.Message);
return 0;
}
World.EventManager.TriggerOnSendNewWindlightProfileTargeted(wl, new UUID(target.m_string)); World.EventManager.TriggerOnSendNewWindlightProfileTargeted(wl, new UUID(target.m_string));
success = 1; success = 1;
} }