LOL 5 hours of trail and error, and I only got this far:
var Observable = require("FuseJS/Observable");
YZJSmainColor=Observable("#800000");
YZJScolorHelper=Observable([0.6,0.067,0.33,1]);
function YZJSmainColorFL(){
console.log('YZ_0:'+YZJScolorHelper.value);
return YZJScolorHelper.value;
};
function YZJSmainColorFL2(arg2){
console.log('YZ_1:'+arg2);
var h=arg2.replace('#', '');
h = h.match(new RegExp('(.{'+h.length/3+'})', 'g'));
for(var i=0; i<h.length; i++)
h[i] = +(Math.round((parseInt(h[i].length==1? h[i]+h[i]:h[i], 16)/255) + "e+2") + "e-2");
h.push("1");
return '['+h.join(',')+']';
};
function SetCol(arg){
// Input must start with '#' and have a valid number of digits
l = arg.value.length-1;
if(l!=3 && l!=4 && l!=6 && l!=8 || arg.value[0]!='#') return;
YZJSmainColor.value = arg.value;
YZJSmainColorFL2(arg.value);
YZJScolorHelper.value=YZJSmainColorFL2(arg.value);
console.log('YZ_2:'+YZJScolorHelper.value);
};
module.exports = {
SetCol,
YZJSmainColor,
YZJSmainColorFL: Observable(YZJSmainColorFL)
};
Triggering SetCol(#800)
does work and gives me this output:
YZ_1:#800
YZ_1:#800
YZ_0:[0.53,0,0,1]
YZ_0:[0.53,0,0,1]
YZ_2:[0.53,0,0,1]
But following by this error while using it:Unable to convert [0.53,0,0,1] to float4
with this output:
Uno.Exception: Unable to convert [0.53,0,0,1] to float4
at Fuse.Scripting.Marshal.ToFloat4(object)
at Fuse.Scripting.Marshal.TryConvertTo(Uno.Type,object)
at Fuse.Scripting.Marshal.TryConvertTo`1(object,T&)
at Fuse.Reactive.DataBinding`1.TryPushAsMarshalledValue(object)
at Fuse.Reactive.DataBinding`1.PushValue(object)
at Fuse.Reactive.DataBinding`1.Fuse.Scripting.IObserver.OnSet(object)
at Fuse.Scripting.Observable.Set.SendMessage(Fuse.Scripting.Observable.Subscription)
at Fuse.Scripting.Observable.Operation.Perform()
at Fuse.Scripting.Context.ProcessUIMessages()
at Fuse.UpdateListener.Invoke()
at Fuse.UpdateManager.Update(Fuse.Stage)
at Fuse.UpdateManager.Update()
at Fuse.AppBase.OnUpdate()
at Fuse.App.OnUpdate()
at Outracks.Simulator.Application.OnUpdate()
at Fuse.App.OnTick(object,Uno.Platform.TimerEventArgs)
at Uno.Platform2.Display.OnTick(Uno.Platform.TimerEventArgs)
Unable to convert [0.53,0,0,1] to float4
I know that im a mega noob, im just trying my best. Any help would be awesome
Gratefully
Blade