mirror of https://github.com/kurisufriend/0x40-web
parent
0a7bb27f50
commit
9791338196
@ -1,388 +1,123 @@ |
||||
function HuesSettings(defaults) { |
||||
this.core = null; |
||||
// TODO: HTML5 local storage or something
|
||||
} |
||||
|
||||
HuesSettings.prototype.connectCore = function(core) { |
||||
this.core = core; |
||||
}; |
||||
/* |
||||
//class HuesSettings
|
||||
package
|
||||
{ |
||||
import flash.display.*; |
||||
import flash.net.*; |
||||
HuesSettings.prototype.defaultSettings = { |
||||
// Debugging var, for loading zips or not
|
||||
load : true, |
||||
// Debug, play first song automatically?
|
||||
autoplay : true, |
||||
// If true, defaults passed in initialiser override locally saved
|
||||
overwriteLocal : false, |
||||
|
||||
public class HuesSettings extends Object |
||||
{ |
||||
public function HuesSettings() |
||||
{ |
||||
this.bools = ["imageSmoothing", "blurEnabled", "smartAlign", "autosongShuffle", "blackoutUI"]; |
||||
this.numbs = ["autosongDelay"]; |
||||
super(); |
||||
trace("Settings created"); |
||||
this.callbacks = []; |
||||
this.currentSettings = {}; |
||||
this.setDefaults(); |
||||
this.load(); |
||||
return; |
||||
} |
||||
|
||||
public function set autosongDelay(arg1:int):void |
||||
{ |
||||
trace("AutoSong delay:", arg1); |
||||
this.currentSettings["autosongDelay"] = arg1; |
||||
this.callCallbacks(); |
||||
return; |
||||
} |
||||
|
||||
public function set autosongShuffle(arg1:Boolean):void |
||||
{ |
||||
trace("Image scaling:", arg1); |
||||
this.currentSettings["autosongShuffle"] = arg1; |
||||
this.callCallbacks(); |
||||
return; |
||||
} |
||||
|
||||
public function set imagescaling(arg1:String):void |
||||
{ |
||||
trace("Image scaling:", arg1); |
||||
this.currentSettings["imagescaling"] = arg1; |
||||
this.callCallbacks(); |
||||
return; |
||||
} |
||||
|
||||
public function set colors(arg1:String):void |
||||
{ |
||||
trace("Colors:", arg1); |
||||
this.currentSettings["colors"] = arg1; |
||||
this.callCallbacks(); |
||||
return; |
||||
} |
||||
|
||||
internal function setDefaults():void |
||||
{ |
||||
this.currentSettings = {"flashQuality":flash.display.StageQuality.HIGH, "imageSmoothing":true, "blurEnabled":true, "blurAmount":"medium", "blurDecay":"high", "channels":"stereo", "smartAlign":true, "buildups":"once", "blendMode":"hard", "ui":"modern", "autosong":"off", "autosongDelay":5, "autosongShuffle":true, "imagescaling":"on", "colors":"normal", "blackoutUI":false}; |
||||
return; |
||||
} |
||||
|
||||
public function defaults():void |
||||
{ |
||||
this.setDefaults(); |
||||
this.saveSettings(); |
||||
return; |
||||
} |
||||
|
||||
public function getSettingsFromParameters(arg1:Object):void |
||||
{ |
||||
var loc1:*=undefined; |
||||
var loc2:*=null; |
||||
if (arg1)
|
||||
{ |
||||
var loc3:*=0; |
||||
var loc4:*=arg1; |
||||
for (loc2 in loc4)
|
||||
{ |
||||
loc1 = arg1[loc2]; |
||||
if (this.bools.indexOf(loc2) == -1)
|
||||
{ |
||||
if (this.numbs.indexOf(loc2) != -1)
|
||||
{ |
||||
if (loc1.match(new RegExp("\\d+")))
|
||||
{ |
||||
loc1 = int(loc1); |
||||
if (loc2 == "autosongDelay")
|
||||
{ |
||||
loc1 = Math.max(1, loc1); |
||||
} |
||||
} |
||||
else
|
||||
{ |
||||
loc1 = null; |
||||
} |
||||
} |
||||
} |
||||
else if (loc1 != "true")
|
||||
{ |
||||
if (loc1 != "false")
|
||||
{ |
||||
loc1 = null; |
||||
} |
||||
else
|
||||
{ |
||||
loc1 = false; |
||||
} |
||||
} |
||||
else
|
||||
{ |
||||
loc1 = true; |
||||
} |
||||
if (loc1 == null)
|
||||
{ |
||||
continue; |
||||
} |
||||
this.currentSettings[loc2] = loc1; |
||||
} |
||||
this.saveSettings(); |
||||
this.callCallbacks(); |
||||
} |
||||
return; |
||||
} |
||||
|
||||
public function saveSettings():void |
||||
{ |
||||
var so:flash.net.SharedObject; |
||||
var k:String; |
||||
|
||||
var loc1:*; |
||||
k = null; |
||||
trace("Saving settings!"); |
||||
so = flash.net.SharedObject.getLocal(this.objectName); |
||||
var loc2:*=0; |
||||
var loc3:*=this.currentSettings; |
||||
for (k in loc3)
|
||||
{ |
||||
so.data[k] = this.currentSettings[k]; |
||||
} |
||||
so.data.saved = true; |
||||
try
|
||||
{ |
||||
so.flush(); |
||||
} |
||||
catch (e:Error) |
||||
{ |
||||
trace("Saving settings failed, oh well"); |
||||
} |
||||
return; |
||||
} |
||||
|
||||
public function load():void |
||||
{ |
||||
var loc1:*=flash.net.SharedObject.getLocal(this.objectName); |
||||
if ("saved" in loc1.data)
|
||||
{ |
||||
trace("Old settings"); |
||||
this.currentSettings = loc1.data; |
||||
} |
||||
else
|
||||
{ |
||||
trace("Defaults"); |
||||
this.defaults(); |
||||
} |
||||
this.callCallbacks(); |
||||
return; |
||||
} |
||||
|
||||
public function set blackoutUI(arg1:Boolean):void |
||||
{ |
||||
trace("Blackout UI:", arg1); |
||||
this.currentSettings["blackoutUI"] = arg1; |
||||
this.callCallbacks(); |
||||
return; |
||||
} |
||||
|
||||
public function addCallback(arg1:Function):void |
||||
{ |
||||
if (this.callbacks.indexOf(arg1) == -1)
|
||||
{ |
||||
this.callbacks.push(arg1); |
||||
arg1(); |
||||
} |
||||
return; |
||||
} |
||||
|
||||
public function callCallbacks():void |
||||
{ |
||||
var loc1:*=undefined; |
||||
this.saveSettings(); |
||||
var loc2:*=0; |
||||
var loc3:*=this.callbacks; |
||||
for each (loc1 in loc3)
|
||||
{ |
||||
loc1(); |
||||
} |
||||
return; |
||||
} |
||||
|
||||
public function get flashQuality():String |
||||
{ |
||||
return this.currentSettings["flashQuality"]; |
||||
} |
||||
|
||||
public function get imageSmoothing():Boolean |
||||
{ |
||||
return this.currentSettings["imageSmoothing"]; |
||||
} |
||||
|
||||
public function get blurEnabled():Boolean |
||||
{ |
||||
return this.currentSettings["blurEnabled"]; |
||||
} |
||||
|
||||
public function get blurAmount():String |
||||
{ |
||||
return this.currentSettings["blurAmount"]; |
||||
} |
||||
|
||||
public function get blurDecay():String |
||||
{ |
||||
return this.currentSettings["blurDecay"]; |
||||
} |
||||
|
||||
public function get channels():String |
||||
{ |
||||
return this.currentSettings["channels"]; |
||||
} |
||||
|
||||
public function get smartAlign():Boolean |
||||
{ |
||||
return this.currentSettings["smartAlign"]; |
||||
} |
||||
|
||||
public function get buildups():String |
||||
{ |
||||
return this.currentSettings["buildups"]; |
||||
} |
||||
|
||||
public function get blendMode():String |
||||
{ |
||||
return this.currentSettings["blendMode"]; |
||||
} |
||||
|
||||
public function get ui():String |
||||
{ |
||||
return this.currentSettings["ui"]; |
||||
} |
||||
|
||||
public function get autosong():String |
||||
{ |
||||
return this.currentSettings["autosong"]; |
||||
} |
||||
|
||||
public function get autosongDelay():int |
||||
{ |
||||
return this.currentSettings["autosongDelay"]; |
||||
} |
||||
|
||||
public function get autosongShuffle():Boolean |
||||
{ |
||||
return this.currentSettings["autosongShuffle"]; |
||||
} |
||||
|
||||
public function get imagescaling():String |
||||
{ |
||||
return this.currentSettings["imagescaling"]; |
||||
} |
||||
|
||||
public function get colors():String |
||||
{ |
||||
return this.currentSettings["colors"]; |
||||
} |
||||
|
||||
public function get blackoutUI():Boolean |
||||
{ |
||||
return this.currentSettings["blackoutUI"]; |
||||
} |
||||
|
||||
public function set flashQuality(arg1:String):void |
||||
{ |
||||
trace("Flash quality:", arg1); |
||||
this.currentSettings["flashQuality"] = arg1; |
||||
this.callCallbacks(); |
||||
return; |
||||
} |
||||
|
||||
public function set imageSmoothing(arg1:Boolean):void |
||||
{ |
||||
trace("Image smoothing:", arg1); |
||||
this.currentSettings["imageSmoothing"] = arg1; |
||||
this.callCallbacks(); |
||||
return; |
||||
} |
||||
|
||||
public function set blurEnabled(arg1:Boolean):void |
||||
{ |
||||
trace("Blur:", arg1); |
||||
this.currentSettings["blurEnabled"] = arg1; |
||||
this.callCallbacks(); |
||||
return; |
||||
} |
||||
|
||||
public function set blurAmount(arg1:String):void |
||||
{ |
||||
trace("Blur amount:", arg1); |
||||
this.currentSettings["blurAmount"] = arg1; |
||||
this.callCallbacks(); |
||||
return; |
||||
} |
||||
|
||||
public function set blurDecay(arg1:String):void |
||||
{ |
||||
trace("Blur decay:", arg1); |
||||
this.currentSettings["blurDecay"] = arg1; |
||||
this.callCallbacks(); |
||||
return; |
||||
} |
||||
|
||||
public function set channels(arg1:String):void |
||||
{ |
||||
trace("Channels:", arg1); |
||||
this.currentSettings["channels"] = arg1; |
||||
this.callCallbacks(); |
||||
return; |
||||
} |
||||
// UI accessible config
|
||||
// Autosong stuff is a todo, becuase why even implement that
|
||||
smartAlign: "on", |
||||
blurAmount: "medium", |
||||
blurDecay: "fast", |
||||
blurQuality: "high", |
||||
currentUI: "modern", |
||||
colourSet: "normal", |
||||
blackoutUI: "off", |
||||
playBuildups: "on", |
||||
volume : 0.7 |
||||
} |
||||
|
||||
public function set smartAlign(arg1:Boolean):void |
||||
{ |
||||
trace("Smart align:", arg1); |
||||
this.currentSettings["smartAlign"] = arg1; |
||||
this.callCallbacks(); |
||||
return; |
||||
} |
||||
// To dynamically build the UI like the cool guy I am
|
||||
HuesSettings.prototype.settingsCategories = { |
||||
"Image Settings" : [ |
||||
"smartAlign", |
||||
"blurAmount", |
||||
"blurDecay", |
||||
"blurQuality" |
||||
], |
||||
"UI Settings" : [ |
||||
"currentUI", |
||||
"colourSet", |
||||
"blackoutUI" |
||||
], |
||||
"Audio Settings" : [ |
||||
"playBuildups" |
||||
] |
||||
} |
||||
|
||||
public function set buildups(arg1:String):void |
||||
{ |
||||
trace("Buildups:", arg1); |
||||
this.currentSettings["buildups"] = arg1; |
||||
this.callCallbacks(); |
||||
return; |
||||
} |
||||
HuesSettings.prototype.settingsOptions = { |
||||
smartAlign : { |
||||
name : "Smart Align Images", |
||||
options : ["on", "off"] |
||||
}, |
||||
blurAmount : { |
||||
name : "Blur Amount", |
||||
options : ["low", "med", "high"] |
||||
}, |
||||
blurDecay : { |
||||
name : "Blur Decay", |
||||
options : ["slow", "medium", "fast", "faster!"] |
||||
}, |
||||
blurQuality : { |
||||
name : "Blur Quality", |
||||
options : ["low", "medium", "high", "extreme"] |
||||
}, |
||||
currentUI : { |
||||
name : "User Interface", |
||||
options : ["retro", "weed", "modern", "xmas"] |
||||
}, |
||||
colourSet : { |
||||
name : "Colour Set", |
||||
options : ["normal", "pastel", "420"] |
||||
}, |
||||
blackoutUI : { |
||||
name : "Blackout affects UI", |
||||
options : ["on", "off"] |
||||
}, |
||||
playBuildups : { |
||||
name : "Play buildups", |
||||
options : ["off", "once", "on"] |
||||
} |
||||
|
||||
} |
||||
|
||||
public function set blendMode(arg1:String):void |
||||
{ |
||||
trace("Blend mode:", arg1); |
||||
this.currentSettings["blendMode"] = arg1; |
||||
this.callCallbacks(); |
||||
return; |
||||
function HuesSettings(defaults) { |
||||
this.core = null; |
||||
|
||||
for(var attr in this.defaultSettings) { |
||||
if(attr == "respacks") { |
||||
continue; |
||||
} |
||||
|
||||
public function set ui(arg1:String):void |
||||
{ |
||||
trace("UI:", arg1); |
||||
this.currentSettings["ui"] = arg1; |
||||
this.callCallbacks(); |
||||
return; |
||||
if(defaults[attr] == undefined) { |
||||
defaults[attr] = this.defaultSettings[attr]; |
||||
} else if(defaults.overwriteLocal) { |
||||
localStorage[attr] = defaults[attr]; |
||||
} |
||||
|
||||
public function set autosong(arg1:String):void |
||||
{ |
||||
trace("AutoSong:", arg1); |
||||
this.currentSettings["autosong"] = arg1; |
||||
this.callCallbacks(); |
||||
return; |
||||
// populate defaults, ignoring current
|
||||
if(localStorage[attr] == undefined) { |
||||
localStorage[attr] = defaults[attr]; |
||||
} |
||||
} |
||||
|
||||
this.defaults = defaults; |
||||
} |
||||
|
||||
internal var currentSettings:Object; |
||||
|
||||
internal var bools:Array; |
||||
|
||||
internal var numbs:Array; |
||||
|
||||
internal var objectName:*="HuesSettings51"; |
||||
HuesSettings.prototype.connectCore = function(core) { |
||||
this.core = core; |
||||
core.settingsUpdated(); |
||||
}; |
||||
|
||||
internal var callbacks:Array; |
||||
// Set a named index to its named value, returns false if name doesn't exist
|
||||
HuesSettings.prototype.set = function(setting, value) { |
||||
value = value.toLowerCase(); |
||||
var opt = this.settingsOptions[setting]; |
||||
if(!opt || opt.options.indexOf(value) == -1) { |
||||
return false; |
||||
} |
||||
localStorage[setting] = value; |
||||
core.settingsUpdated(); |
||||
return true; |
||||
} |
||||
|
||||
|
||||
*/ |
||||
// Note: This is not defaults as per defaultSettings, but those merged with
|
||||
// the defaults given in the initialiser
|
||||
HuesSettings.prototype.setDefaults = function() { |
||||
for(var attr in this.defaults) { |
||||
if(attr == "respacks") { |
||||
continue; |
||||
} |
||||
localStorage[attr] = this.defaults[attr]; |
||||
} |
||||
} |
@ -1,42 +0,0 @@ |
||||
Self.prototype.updateVolume = function(muted, gain) { |
||||
var label = this.volLabel |
||||
var input = this.volInput |
||||
|
||||
var text = gain.toFixed(1) + "dB" |
||||
if (muted) { |
||||
text = "(" + text + ")" |
||||
} |
||||
label.textContent = text |
||||
input.value = gain |
||||
} |
||||
|
||||
Self.prototype.setupVolume = function(box) { |
||||
var volBar = box.ownerDocument.createElement("div") |
||||
volBar.className = "hues-m-vol-bar" |
||||
box.appendChild(volBar) |
||||
|
||||
var label = box.ownerDocument.createElement("button") |
||||
volBar.appendChild(label) |
||||
this.volLabel = label |
||||
label.addEventListener("click", (function() { |
||||
if (this.core.isMuted()) { |
||||
this.core.unmute() |
||||
} else { |
||||
this.core.mute() |
||||
} |
||||
}).bind(this)) |
||||
|
||||
var input = box.ownerDocument.createElement("input") |
||||
input.type = "range" |
||||
input.min = -60 |
||||
input.max = 5 |
||||
input.step = 1 |
||||
volBar.appendChild(input) |
||||
this.volInput = input |
||||
input.addEventListener("input", (function() { |
||||
this.core.setVolume(parseFloat(input.value)) |
||||
}).bind(this)) |
||||
|
||||
this.updateVolume(this.core.isMuted(), this.core.getVolume()) |
||||
Hues.addEventListener("volumechange", this.updateVolume.bind(this)) |
||||
} |
Loading…
Reference in new issue