Browse Source

Meshviewer : web version now creates cookie to store current session.

undefined
Benjamin ‘Touky’ Huet Sam Hocevar <sam@hocevar.net> 11 years ago
parent
commit
47ca78b85e
4 changed files with 131 additions and 45 deletions
  1. +6
    -37
      test/javascript/typedictionnary.js
  2. +83
    -0
      test/javascript/utils.js
  3. +1
    -1
      test/meshviewer.cpp
  4. +41
    -7
      test/meshviewer.index.html

+ 6
- 37
test/javascript/typedictionnary.js View File

@@ -13,16 +13,11 @@ function CmdVarObj() { }
function CmdVar(m_type, m_syntax)
{
var current_dict = GetCmdDictionnary();

new_obj = new CmdVarObj();
new_obj.m_type = m_type;
new_obj.m_syntax = m_syntax;
new_obj.ToString = function()
{
var res = m_type + ' ';
if (m_syntax != undefined)
for (var i = 0; i < m_syntax.length; i++)
res += m_syntax[i] + ' ';
}

current_dict.m_vars[current_dict.m_vars.length] = new_obj;
}

@@ -33,15 +28,11 @@ function CmdArgObj() { }
function CmdArg(m_type, m_name, m_optional)
{
new_obj = new CmdArgObj();

new_obj.m_type = m_type;
new_obj.m_name = m_name;
new_obj.m_optional = m_optional;
new_obj.ToString = function()
{
if (m_optional != undefined)
return m_type + ' ' + m_name + ' = ' + m_optional;
return m_type + ' ' + m_name;
}

return new_obj;
}

@@ -52,34 +43,12 @@ function CmdTypeObj() { }
function CmdType(m_name, m_comment, m_arg)
{
var current_dict = GetCmdDictionnary();

new_obj = new CmdTypeObj();
new_obj.m_name = m_name;
new_obj.m_comment = m_comment;
new_obj.m_arg = m_arg;
new_obj.ToString = function()
{
var str = m_name.toString() + ' [' + m_comment + ']';
if (m_arg != undefined)
{
str += '{';
var found_optional = false;
for (var vi = 0; vi < m_arg.length; vi++)
{
if (m_arg[vi].m_optional != undefined && found_optional == false)
{
str += ' [';
found_optional = true;
}
if (vi != 0)
str += ', ';
str += m_arg[vi].ToString();
}
if (found_optional == true)
str += ']';
str += '}';
}
return str;
}

new_obj.CheckCommand = function(check_name)
{
if (m_name != undefined && check_name.length > 0)


+ 83
- 0
test/javascript/utils.js View File

@@ -1,3 +1,85 @@
//-----------------------------------------------------------------------------
// COOKIE MANAGEMENT - nom nom nom nom -
//-----------------------------------------------------------------------------

function LolCookie() { }
function LolCookieDays(m_name, m_value, m_expire_days)
{
var cookie = new LolCookie();

cookie.m_name = m_name;
cookie.m_value = m_value;
cookie.m_expire_date = new Date();
cookie.m_expire_date.setDate(cookie.m_expire_date.getDate() + m_expire_days);

return cookie;
}
function LolCookieDate(m_name, m_value, m_expire_date)
{
var cookie = new LolCookie();

cookie.m_name = m_name;
cookie.m_value = m_value;
cookie.m_expire_date = m_expire_date;

return cookie;
}

//Set a cookie
function StoreLolCookie(cookie)
{
//Get the cookie and removes it if it exists.
GetLolCookie(cookie.m_name, true);

var enc_value = escape(cookie.m_value) + ";";

//Add expire days
if (cookie.m_expire_date)
enc_value += " expires=" + cookie.m_expire_date.toUTCString() + ";";
enc_value = cookie.m_name + "=" + enc_value;

//Store cookies
document.cookie = enc_value;
}

//Get a cookie
function GetLolCookie(name, remove)
{
var cki_doc = document.cookie;
var cookie = null;

var cki_start = cki_doc.indexOf(name + "=");
if (cki_start > -1)
{
cookie = new LolCookie();
cookie.m_name = name;
cookie.m_expire_date = null;

//Retrieve value
var val_start = cki_doc.indexOf("=", cki_start) + 1;
var val_end = cki_doc.indexOf(";", cki_start);
cookie.m_value = unescape(cki_doc.substring(val_start, val_end));

if (remove)
document.cookie = name + "=; expires=0;";
}
return cookie;
}

//Check the existence of a cookie
function DoesLolCookieExist(name)
{
var cki_doc = document.cookie;
if (cki_doc.indexOf(name + "=") > -1)
return true;
return false;
}

//-----------------------------------------------------------------------------
// FILE MANAGEMENT
//-----------------------------------------------------------------------------

//Dynamic load
function DynLoadFile(filename)
{
var filetype = filename.match(/\.[a-zA-Z]+$/);
@@ -20,6 +102,7 @@ function DynLoadFile(filename)
document.getElementsByTagName("head")[0].appendChild(fileref);
}

//Dynamic remove
function DynRemoveFile(filename)
{
var filetype = filename.match(/\.[a-zA-Z]+$/);


+ 1
- 1
test/meshviewer.cpp View File

@@ -158,7 +158,7 @@ public:

//Compile ref meshes
m_gizmos << new EasyMesh();
m_gizmos.Last()->Compile("[sc#0f0 ac 3 .5 .4 0 ty .25 [ad 3 .4 sy -1] ty .5 ac 3 1 .1 ty .5 dup[rz 90 ry 90 scv#00f dup[ry 90 scv#f00]]][sc#fff ab .1]");
m_gizmos.Last()->Compile("[sc#0f0 ac 3 .5 .4 0 ty .25 [ad 3 .4 sy -1] ty .5 ac 3 1 .075 ty .5 dup[rz 90 ry 90 scv#00f dup[ry 90 scv#f00]]][sc#fff ab .1]");
m_gizmos << new EasyMesh();
m_gizmos.Last()->Compile("[sc#666 acap 1 .5 .5 ty -.5 sc#fff asph 2 1]");
m_gizmos << new EasyMesh();


+ 41
- 7
test/meshviewer.index.html View File

@@ -105,13 +105,15 @@ progress::-webkit-progress-value
//This is the module pointer : can be either the NaCl or Em one depending on the context.
g_embed_module = null;

var g_autosave_timer = 4.0;
var g_autosave_time = 4.0;
var g_code_addin = ['custom setmesh "#CODE#"', '#CODE#'];
var g_code_base = [];
var CodeDictionnary = [];

g_code_id = 0;
g_code_base[0] = "//This is a comment\nsc#f8f afcb 1 1 1 0";
g_code_base[1] = "//This is a comment\naddlight 0.0 position (4 -1 -4) color (.0 .2 .5 1)\naddlight 0.0 position (8 2 6) color #ffff\nshowgizmo true\nshowlight true";
g_code_base = ["//This is a comment\nsc#f8f afcb 1 1 1 0",
"//This is a comment\naddlight 0.0 position (4 -1 -4) color (.0 .2 .5 1)\naddlight 0.0 position (8 2 6) color #ffff\nshowgizmo true\nshowlight true"];
function machinchose() { return 'test machin '; }
function GetTextAreaCodeSrc() { return g_txtarea_code_src; }
@@ -180,7 +182,16 @@ function machinchose() { return 'test machin '; }
VarInit();

//Put here any cookie update
if (!g_txtarea_code_src.value)
if (DoesLolCookieExist("LolMeshViewerAutosave"))
{
var lol_cookie = GetLolCookie("LolMeshViewerAutosave");
var value_list = lol_cookie.m_value.split(";");
for (var i = 0; i < g_code_base.length && i < value_list.length; i++)
g_code_base[i] = value_list[i];
g_txtarea_code_src.value = g_code_base[g_code_id];
}
else if (!g_txtarea_code_src.value)
g_txtarea_code_src.value = g_code_base[g_code_id];

//Fill the TOC
@@ -220,18 +231,38 @@ function machinchose() { return 'test machin '; }
g_frame_embed.onload = function() { VarInit(); }

//Tick has been done, start Tick
window.setTimeout("Tick()", 200);
window.setTimeout("Tick(.2)", 200);
}

function Tick()
function Tick(seconds)
{
window.setTimeout("Tick()", 100);
window.setTimeout("Tick(.1)", 100);

var text_src = g_txtarea_code_src;
var div_cmds = g_div_helper_cmd;
var div_args = g_div_helper_args;
var div_cmnt = g_div_helper_cmnt;
var div_vars = g_div_helper_vars;
CmdLookup(div_cmds, div_args, div_cmnt, div_vars, text_src);

g_autosave_timer -= seconds;
if (g_autosave_timer < 0.0)
{
g_autosave_timer = g_autosave_time;
StoreLolCookie("LolMeshViewerAutosave", GetTextValue(true), 10);
}
}

function GetTextValue(getall)
{
var result = '';
for (var i = (getall)?(0):(g_code_id); i < g_code_base.length; i++)
{
result += g_code_addin[i].replace('#CODE#', g_code_base[i]) + (getall)?(';'):('');
if (getall && i == g_code_id)
break;
}
return result;
}

function StoreTextAreaValue()
@@ -263,7 +294,10 @@ function machinchose() { return 'test machin '; }
{
StoreTextAreaValue();
if (g_embed_module)
g_embed_module.SendMessage(g_code_addin[g_code_id].replace('#CODE#', g_code_base[g_code_id]));
{
StoreLolCookie("LolMeshViewerAutosave", GetTextValue(true), 10);
g_embed_module.SendMessage(GetTextValue(false));
}
else
alert("Module not loaded !");
}


Loading…
Cancel
Save