Skip to content

Commit f363293

Browse files
author
Simon Hobbs
committed
Initial checkin
1 parent a69363a commit f363293

File tree

8 files changed

+296
-0
lines changed

8 files changed

+296
-0
lines changed

README.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,17 @@ RandomArray2
22
============
33

44
Construct 2 random array generator
5+
6+
Installation:
7+
=============
8+
1) download the .c2addon file
9+
2) drag and drop it on your C2 installation.
10+
11+
Usage:
12+
======
13+
1) Download the text.capx, and view the usage.
14+
2) Run the capx and see the console log output in your browser (hint: hit F12 in Chrome), go to console tab, then click "Logs" at the bottom of the window.
15+
16+
The original Plugin:
17+
====================
18+
http://www.scirra.com/forum/plugin-randomarray_topic45277.html

RandomArray2.c2addon

4.82 KB
Binary file not shown.

files/RandomArray2/PluginIcon.ico

4.06 KB
Binary file not shown.

files/RandomArray2/common.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
// Scripts in this file are included in both the IDE and runtime, so you only
2+
// need to write scripts common to both once.

files/RandomArray2/edittime.js

Lines changed: 115 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,115 @@
1+
function GetPluginSettings()
2+
{
3+
return {
4+
"name": "Random Array2",
5+
"id": "rA2",
6+
"version": "1.2",
7+
"description": "Give you an array with random numbers.",
8+
"author": "Joe7",
9+
"help url": "http://dev.liebhard.net/",
10+
"category": "Data & Storage",
11+
"type": "object", // not in layout
12+
"rotatable": false,
13+
"flags": 0
14+
};
15+
};
16+
17+
//////////////////////////////////////////////////////////////
18+
// Conditions
19+
AddNumberParam("Index", "Index of the array value to compare.", "0");
20+
AddCmpParam("Comparison", "How to compare the value.");
21+
AddAnyTypeParam("Value", "The value to compare the array value to.", "0");
22+
AddCondition(0, 0, "Compare at ", "Array", "Value at <b>{0}</b> {1} <b>{2}</b>", "Compare the value at an specified position in the array.", "CompareX");
23+
24+
25+
26+
//////////////////////////////////////////////////////////////
27+
// Actions
28+
AddAction(0, 0, "New scramble", "Array", "New scramble", "Get new random Numbers.", "NewScramble");
29+
AddNumberParam("Size", "Set a new size for the array.", "10");
30+
AddAction(1, 0, "New size", "Array", "Set size to <b>{0}</b>.", "New size", "NewSize");
31+
AddNumberParam("Start", "Set a new Start for the array.", "1");
32+
AddAction(2, 0, "New Start", "Array", "Set Start to <b>{0}</b>.", "New Start", "NewStart");
33+
34+
35+
//////////////////////////////////////////////////////////////
36+
// Expressions
37+
AddNumberParam("Index", "The index of the array value to get.", "0");
38+
AddExpression(0, ef_return_number, "Get value at", "Array", "At", "Get a value at a certain position from the array.");
39+
40+
AddExpression(1, ef_return_number, "Get width", "Array", "Width", "Get the number of elements of the array.");
41+
42+
AddExpression(2, ef_return_number, "Get start", "Array", "StartValue", "Get the startvalue.");
43+
44+
ACESDone();
45+
46+
// Property grid properties for this plugin
47+
var property_list = [
48+
new cr.Property(ept_integer, "Width", 10, "Initial number of elements."),
49+
50+
new cr.Property(ept_integer, "StartValue", 1, "Initial start number for random."),
51+
];
52+
53+
// Called by IDE when a new object type is to be created
54+
function CreateIDEObjectType()
55+
{
56+
return new IDEObjectType();
57+
}
58+
59+
// Class representing an object type in the IDE
60+
function IDEObjectType()
61+
{
62+
assert2(this instanceof arguments.callee, "Constructor called as a function");
63+
}
64+
65+
// Called by IDE when a new object instance of this type is to be created
66+
IDEObjectType.prototype.CreateInstance = function(instance)
67+
{
68+
return new IDEInstance(instance, this);
69+
}
70+
71+
// Class representing an individual instance of an object in the IDE
72+
function IDEInstance(instance, type)
73+
{
74+
assert2(this instanceof arguments.callee, "Constructor called as a function");
75+
76+
// Save the constructor parameters
77+
this.instance = instance;
78+
this.type = type;
79+
80+
// Set the default property values from the property table
81+
this.properties = {};
82+
83+
for (var i = 0; i < property_list.length; i++)
84+
this.properties[property_list[i].name] = property_list[i].initial_value;
85+
}
86+
87+
// Called by the IDE after all initialization on this instance has been completed
88+
IDEInstance.prototype.OnCreate = function()
89+
{
90+
}
91+
92+
// Called by the IDE after a property has been changed
93+
IDEInstance.prototype.OnPropertyChanged = function(property_name)
94+
{
95+
if (this.properties["Width"] < 1)
96+
this.properties["Width"] = 1;
97+
98+
if (this.properties["Height"] < 1)
99+
this.properties["Height"] = 1;
100+
101+
if (this.properties["Depth"] < 1)
102+
this.properties["Depth"] = 1;
103+
}
104+
105+
// Called by the IDE to draw this instance in the editor
106+
IDEInstance.prototype.Draw = function(renderer)
107+
{
108+
}
109+
110+
// Called by the IDE when the renderer has been released (ie. editor closed)
111+
// All handles to renderer-created resources (fonts, textures etc) must be dropped.
112+
// Don't worry about releasing them - the renderer will free them - just null out references.
113+
IDEInstance.prototype.OnRendererReleased = function()
114+
{
115+
}

files/RandomArray2/runtime.js

Lines changed: 155 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,155 @@
1+
// ECMAScript 5 strict mode
2+
"use strict";
3+
4+
assert2(cr, "cr namespace not created");
5+
assert2(cr.plugins_, "cr.plugins_ not created");
6+
7+
/////////////////////////////////////
8+
// Plugin class
9+
cr.plugins_.rA2 = function(runtime)
10+
{
11+
this.runtime = runtime;
12+
};
13+
14+
(function ()
15+
{
16+
var pluginProto = cr.plugins_.rA2.prototype;
17+
18+
/////////////////////////////////////
19+
// Object type class
20+
pluginProto.Type = function(plugin)
21+
{
22+
this.plugin = plugin;
23+
this.runtime = plugin.runtime;
24+
};
25+
26+
var typeProto = pluginProto.Type.prototype;
27+
28+
typeProto.onCreate = function()
29+
{
30+
};
31+
32+
/////////////////////////////////////
33+
// Instance class
34+
pluginProto.Instance = function(type)
35+
{
36+
this.type = type;
37+
this.runtime = type.runtime;
38+
};
39+
40+
var instanceProto = pluginProto.Instance.prototype;
41+
42+
instanceProto.onCreate = function()
43+
{
44+
this.cx = this.properties[0];
45+
46+
this.start= this.properties[1]; /* start Value */
47+
48+
/* create the random array */
49+
this.arr= new Array(this.cx);
50+
51+
this.scramble();
52+
};
53+
54+
instanceProto.scramble= function() // the scramble function
55+
{
56+
for (var i= 0; i< this.arr.length; i++)
57+
{
58+
var randomNumber= Math.floor(Math.random() * this.arr.length);
59+
this.arr[i]= randomNumber + this.start;
60+
for (var j= 0; j< i; j++)
61+
{
62+
if (this.arr[j] == (randomNumber + this.start))
63+
{
64+
j= -1;
65+
randomNumber= Math.floor(Math.random() * this.arr.length);
66+
this.arr[i]= randomNumber + this.start;
67+
}
68+
}
69+
}
70+
}
71+
72+
instanceProto.at = function (x)
73+
{
74+
x = Math.floor(x);
75+
76+
if (x < 0)
77+
return 0;
78+
if (x > this.cx - 1)
79+
return 0;
80+
81+
return this.arr[x];
82+
};
83+
84+
//////////////////////////////////////
85+
// Conditions
86+
pluginProto.cnds = {};
87+
var cnds = pluginProto.cnds;
88+
89+
cnds.CompareX = function (x, cmp, val)
90+
{
91+
return cr.do_cmp(this.at(x), cmp, val);
92+
};
93+
94+
//////////////////////////////////////
95+
// Actions
96+
pluginProto.acts = {};
97+
var acts = pluginProto.acts;
98+
99+
acts.NewScramble = function ()
100+
{
101+
this.scramble();
102+
};
103+
acts.NewSize = function (newSize)
104+
{
105+
if (newSize <= 0) return; // change nothing
106+
107+
var oldSize= this.cx;
108+
this.cx = newSize;
109+
110+
var tempArray = this.arr; // save the current array
111+
this.arr= new Array(newSize); // recreate the random array
112+
for (var i= 0; i< newSize; i++)
113+
{
114+
if (i < oldSize)
115+
{
116+
this.arr[i]= tempArray[i]; // save the old values
117+
}
118+
else // new size is bigger than the old size
119+
{
120+
this.arr[i]= 0;
121+
}
122+
}
123+
};
124+
125+
acts.NewStart = function (newStart)
126+
{
127+
this.start=newStart;
128+
};
129+
130+
//////////////////////////////////////
131+
// Expressions
132+
pluginProto.exps = {};
133+
var exps = pluginProto.exps;
134+
135+
exps.At = function (ret, x )
136+
{
137+
var val = this.at(x);
138+
139+
if (typeof val === "string")
140+
ret.set_string(val);
141+
else
142+
ret.set_float(val);
143+
};
144+
145+
exps.Width = function (ret)
146+
{
147+
ret.set_int(this.cx);
148+
};
149+
150+
exps.StartValue = function (ret) /* random */
151+
{
152+
ret.set_int(this.start);
153+
};
154+
155+
}());

info.xml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<c2addon>
2+
<!-- One of: plugin, behavior, effect -->
3+
<type>plugin</type>
4+
<name>RandomArray2</name>
5+
<version>1.1</version>
6+
<author>Joe7 modified by nutmix</author>
7+
<website>https://github.com/nutmix/RandomArray2</website>
8+
<documentation>https://github.com/nutmix/RandomArray2</documentation>
9+
<description>A modification of the RandomArray plugin by Joe7. </description>
10+
</c2addon>

testRandomArray2.capx

75.2 KB
Binary file not shown.

0 commit comments

Comments
 (0)