Luke Briggs

Upgraded canvas, window and JSON examples to the new JS engine

......@@ -37,25 +37,22 @@ html{
</div>
<script type='text/nitro'>
<script type='text/javascript'>
/*
--- This version of Nitro is now depreciated ---
Use C# instead, or request the new JavaScript engine.
Javascript is totally optional - everything it can do, C# can do too (see also UI.document, a static reference)
*/
// Grab the canvas:
var myCanvas=(document.getElementById("my-canvas")):HtmlElement;
var myCanvas=document.getElementById("my-canvas");
// Get the context:
var ctx=myCanvas.getContext("2d");
ctx.beginPath();
ctx.moveTo(0f,10f);
ctx.lineTo(50f,10f);
ctx.lineTo(50f,60f);
ctx.moveTo(0,10);
ctx.lineTo(50,10);
ctx.lineTo(50,60);
ctx.closePath();
// Colour with alpha:
......@@ -67,9 +64,9 @@ ctx.strokeStyle="#000022";
ctx.stroke();
ctx.beginPath();
ctx.moveTo(40f,10f);
ctx.lineTo(90f,10f);
ctx.lineTo(90f,60f);
ctx.moveTo(40,10);
ctx.lineTo(90,10);
ctx.lineTo(90,60);
ctx.closePath();
// Colour with alpha:
......@@ -77,10 +74,10 @@ ctx.fillStyle="#ff882299";
ctx.fill();
ctx.beginPath();
ctx.moveTo(80f,10f);
ctx.lineTo(130f,10f);
ctx.lineTo(130f,60f);
ctx.quadraticCurveTo(80f,60f,80f,10f);
ctx.moveTo(80,10);
ctx.lineTo(130,10);
ctx.lineTo(130,60);
ctx.quadraticCurveTo(80,60,80,10);
// Colour with alpha:
ctx.fillStyle="#22ff8899";
......
......@@ -38,17 +38,16 @@ html{
<br><b>Note!</b> Keys are case insensitive - uppercase is not preserved.
</div>
<script type='text/nitro'>
<script type='text/javascript'>
/*
--- This version of Nitro is now depreciated ---
Use C# instead, or request the new JavaScript engine.
Javascript is totally optional - everything it can do, C# can do too (see also UI.document, a static reference)
*/
// Load up the JSON (from Unity resources):
var jsonString=Resources.Load("JSON-Example",TextAsset);
var UnityEngine = importNamespace("UnityEngine");
var jsonString=UnityEngine.Resources.Load("JSON-Example", UnityEngine.TextAsset);
// Load it:
var jsonObject=JSON.parse(jsonString);
......@@ -57,25 +56,20 @@ var jsonObject=JSON.parse(jsonString);
var gloss=jsonObject.glossary;
// Let's log the glossary title:
debug.log(gloss.title);
console.log(gloss.title);
// We can also access like this (note! C# JSON requires accessing like this):
debug.log(gloss["title"]);
console.log(gloss["title"]);
// How about related entry 2:
debug.log(gloss.GlossList.GlossEntry.Related[2]);
console.log(gloss.GlossList.GlossEntry.Related[2]);
// Back to a string, the "proper" way (Note! Case is *not* preserved):
debug.log(JSON.stringify(gloss));
// Singular values are supported too:
jsonObject=JSON.parse("'hello!'");
debug.log(jsonObject); // hello!
console.log(JSON.stringify(gloss));
// Null:
jsonObject=JSON.parse("null");
debug.log((jsonObject==null)); // True
console.log((jsonObject==null)); // True
</script>
\ No newline at end of file
......
......@@ -32,11 +32,10 @@ body{
This widget resizes and moves too - Drag either the window itself or the bottom right corner.
</center>
<script type='text/nitro'>
<script type='text/javascript'>
/*
This version of Nitro is depreciated
but it demonstrates a simple way of passing variables to a widget.
/*
Here's a simple way to pass in variables to an opening widget. Note that they can be accessed from C# too.
Calling document.widgets.open or adding a query string to the widget URL
will set global variables. They're available immediately!
......@@ -44,14 +43,14 @@ will set global variables. They're available immediately!
------------------------
E.g. The widget URL that loads up this content is..
widget://floating/WindowExample/windowContent.html?hello=nitro
widget://floating/WindowExample/windowContent.html?hello=javascript
We'll get a global called 'hello' and it's value is 'nitro'.
We'll get a global called 'hello' and it's value is 'javascript'.
*/
// Show it:
debug.log("The widget URL set the hello global to:");
debug.log(hello);
console.log("The widget URL set the hello global to:");
console.log(hello);
</script>
\ No newline at end of file
......
......@@ -41,7 +41,7 @@ body,html{
However, it wouldn't be complete without a classic "floating" window, so..
<br><br>
<!-- The widget type ("floating" - a built in type for displaying a window) and the content to put in it. -->
<a href='widget://floating/WindowExample/windowContent.html?hello=nitro'>Click here to open one!</a>
<a href='widget://floating/WindowExample/windowContent.html?hello=javascript'>Click here to open one!</a>
<br><br>
This link uses the <a href='http://powerui.kulestar.com/wiki/index.php?title=Widget_Protocol' target='_blank'>widget:// protocol</a>. There's also a <a href='http://powerui.kulestar.com/wiki/index.php?title=Widgets_(Web_API)' target='_blank'>web API</a> for opening, closing or cycling them too.
</div>
\ No newline at end of file
......