// SISL specific cfg processing and translation from .py coordinates (PsychoPy) to .js (canvas HTML5) // These also apply for SeVi // these strings should be deprecated var cfg_strings=['key_list','letter_color', 'feedback', 'feedback_remove_cue', 'progress_bar', 'fixation_info', 'results_file', 'on_screen_feedback', 'trigrams_held_out']; // config tokens not to be converted to numbers var cfg_colors=['background_color','cue_colors','target_color','letter_color','feedback_pos_color','feedback_neg_color']; // fixation // parse_config is a global that is set by parse_config // parse_config now returns the session structure that SISL uses // .cfg parameters not yet processed // fixation point // progress bar // text feedback // utilities for parse_config, contains and hex translation for colors function contains(s,string_list){ for(var i=0;i (i + 1)) { i++; g = (parseFloat(tokens[i])+1.0)*127.5; i++; b = (parseFloat(tokens[i])+1.0)*127.5; } else { g=r; b=r; } // scale from [-1.0, 1.0] to [#00, FF] color='#'+dec2hex(r)+dec2hex(g)+dec2hex(b); color_list.push(color); } } return(color_list); } // sets up the cfg array, which is global function parse_config(config) { //var config=ServerHelper.config_file; var j=0; var t=[]; var args=[]; var a=''; var in_session_struct=false; var session=[]; // some initial cfg settings; should probably scale to window size; also set within SISL.html var canvas = document.getElementById("mainWin"); // parse config var lines = config.split('\n'); for (var i=0;i0 && t[0].trim()!='') { args=[]; if(t[0]=='session_begin{'){ // this syntax is used for overall trial structure in SISL in_session_struct=true; session.push(["Preload:"]); } else if(t[0]=='}session_end') in_session_struct = false; else if(in_session_struct){ // if in session struct, trim all the arguments and add to session structure list for(j=0;j0) args.push(a); } session.push(args); } else { // otherwise add to cfg object if (t[0].includes("color")) { // Changed to look for substring 'color' and treat as color, checking this first -- (contains(t[0], cfg_colors)) { args = convert_colors(t.slice(1)); // parse color information } else if (isNaN(parseFloat(t[1]))) { // if first argument isn't a number, treat all args as string for (j = 1; j < t.length; j++) { a = t[j].trim(); if (a.length > 0) { if (a.length == 1) args.push(a.toUpperCase()); // convert single keys to uppercase else args.push(a); } } } else { // convert to numbers for (j = 1; j < t.length; j++) args.push(Number(t[j].trim())); } // add args to cfg object, appending if this key already exists if (cfg.hasOwnProperty(t[0])) cfg[t[0]] = cfg[t[0]].concat(args); else { if (args.length == 1) cfg[t[0]] = args[0]; // if only one value, don't store as list else cfg[t[0]] = args; } } } } return session; } // modify on-screen reference parameters from PsychoPy structure to browser coordinates // assumes the existence of all the cfg value parameters function cfg_adjust(){ // Fill in z parameters if missing if(server_debug) console.log("In cfg adjust"); if(cfg.hasOwnProperty('start_z')==false){ cfg['start_z']=[]; cfg['delta_z']=[]; cfg['target_z']=[]; for (i=0;i