Major overhaul of plugin and module loading system and scriptcraft directory layout
This commit is contained in:
parent
4ffc5f6850
commit
a7dcb503aa
49 changed files with 5115 additions and 486 deletions
|
@ -1,486 +0,0 @@
|
|||
/*
|
||||
json2.js
|
||||
2012-10-08
|
||||
|
||||
Public Domain.
|
||||
|
||||
NO WARRANTY EXPRESSED OR IMPLIED. USE AT YOUR OWN RISK.
|
||||
|
||||
See http://www.JSON.org/js.html
|
||||
|
||||
|
||||
This code should be minified before deployment.
|
||||
See http://javascript.crockford.com/jsmin.html
|
||||
|
||||
USE YOUR OWN COPY. IT IS EXTREMELY UNWISE TO LOAD CODE FROM SERVERS YOU DO
|
||||
NOT CONTROL.
|
||||
|
||||
|
||||
This file creates a global JSON object containing two methods: stringify
|
||||
and parse.
|
||||
|
||||
JSON.stringify(value, replacer, space)
|
||||
value any JavaScript value, usually an object or array.
|
||||
|
||||
replacer an optional parameter that determines how object
|
||||
values are stringified for objects. It can be a
|
||||
function or an array of strings.
|
||||
|
||||
space an optional parameter that specifies the indentation
|
||||
of nested structures. If it is omitted, the text will
|
||||
be packed without extra whitespace. If it is a number,
|
||||
it will specify the number of spaces to indent at each
|
||||
level. If it is a string (such as '\t' or ' '),
|
||||
it contains the characters used to indent at each level.
|
||||
|
||||
This method produces a JSON text from a JavaScript value.
|
||||
|
||||
When an object value is found, if the object contains a toJSON
|
||||
method, its toJSON method will be called and the result will be
|
||||
stringified. A toJSON method does not serialize: it returns the
|
||||
value represented by the name/value pair that should be serialized,
|
||||
or undefined if nothing should be serialized. The toJSON method
|
||||
will be passed the key associated with the value, and this will be
|
||||
bound to the value
|
||||
|
||||
For example, this would serialize Dates as ISO strings.
|
||||
|
||||
Date.prototype.toJSON = function (key) {
|
||||
function f(n) {
|
||||
// Format integers to have at least two digits.
|
||||
return n < 10 ? '0' + n : n;
|
||||
}
|
||||
|
||||
return this.getUTCFullYear() + '-' +
|
||||
f(this.getUTCMonth() + 1) + '-' +
|
||||
f(this.getUTCDate()) + 'T' +
|
||||
f(this.getUTCHours()) + ':' +
|
||||
f(this.getUTCMinutes()) + ':' +
|
||||
f(this.getUTCSeconds()) + 'Z';
|
||||
};
|
||||
|
||||
You can provide an optional replacer method. It will be passed the
|
||||
key and value of each member, with this bound to the containing
|
||||
object. The value that is returned from your method will be
|
||||
serialized. If your method returns undefined, then the member will
|
||||
be excluded from the serialization.
|
||||
|
||||
If the replacer parameter is an array of strings, then it will be
|
||||
used to select the members to be serialized. It filters the results
|
||||
such that only members with keys listed in the replacer array are
|
||||
stringified.
|
||||
|
||||
Values that do not have JSON representations, such as undefined or
|
||||
functions, will not be serialized. Such values in objects will be
|
||||
dropped; in arrays they will be replaced with null. You can use
|
||||
a replacer function to replace those with JSON values.
|
||||
JSON.stringify(undefined) returns undefined.
|
||||
|
||||
The optional space parameter produces a stringification of the
|
||||
value that is filled with line breaks and indentation to make it
|
||||
easier to read.
|
||||
|
||||
If the space parameter is a non-empty string, then that string will
|
||||
be used for indentation. If the space parameter is a number, then
|
||||
the indentation will be that many spaces.
|
||||
|
||||
Example:
|
||||
|
||||
text = JSON.stringify(['e', {pluribus: 'unum'}]);
|
||||
// text is '["e",{"pluribus":"unum"}]'
|
||||
|
||||
|
||||
text = JSON.stringify(['e', {pluribus: 'unum'}], null, '\t');
|
||||
// text is '[\n\t"e",\n\t{\n\t\t"pluribus": "unum"\n\t}\n]'
|
||||
|
||||
text = JSON.stringify([new Date()], function (key, value) {
|
||||
return this[key] instanceof Date ?
|
||||
'Date(' + this[key] + ')' : value;
|
||||
});
|
||||
// text is '["Date(---current time---)"]'
|
||||
|
||||
|
||||
JSON.parse(text, reviver)
|
||||
This method parses a JSON text to produce an object or array.
|
||||
It can throw a SyntaxError exception.
|
||||
|
||||
The optional reviver parameter is a function that can filter and
|
||||
transform the results. It receives each of the keys and values,
|
||||
and its return value is used instead of the original value.
|
||||
If it returns what it received, then the structure is not modified.
|
||||
If it returns undefined then the member is deleted.
|
||||
|
||||
Example:
|
||||
|
||||
// Parse the text. Values that look like ISO date strings will
|
||||
// be converted to Date objects.
|
||||
|
||||
myData = JSON.parse(text, function (key, value) {
|
||||
var a;
|
||||
if (typeof value === 'string') {
|
||||
a =
|
||||
/^(\d{4})-(\d{2})-(\d{2})T(\d{2}):(\d{2}):(\d{2}(?:\.\d*)?)Z$/.exec(value);
|
||||
if (a) {
|
||||
return new Date(Date.UTC(+a[1], +a[2] - 1, +a[3], +a[4],
|
||||
+a[5], +a[6]));
|
||||
}
|
||||
}
|
||||
return value;
|
||||
});
|
||||
|
||||
myData = JSON.parse('["Date(09/09/2001)"]', function (key, value) {
|
||||
var d;
|
||||
if (typeof value === 'string' &&
|
||||
value.slice(0, 5) === 'Date(' &&
|
||||
value.slice(-1) === ')') {
|
||||
d = new Date(value.slice(5, -1));
|
||||
if (d) {
|
||||
return d;
|
||||
}
|
||||
}
|
||||
return value;
|
||||
});
|
||||
|
||||
|
||||
This is a reference implementation. You are free to copy, modify, or
|
||||
redistribute.
|
||||
*/
|
||||
|
||||
/*jslint evil: true, regexp: true */
|
||||
|
||||
/*members "", "\b", "\t", "\n", "\f", "\r", "\"", JSON, "\\", apply,
|
||||
call, charCodeAt, getUTCDate, getUTCFullYear, getUTCHours,
|
||||
getUTCMinutes, getUTCMonth, getUTCSeconds, hasOwnProperty, join,
|
||||
lastIndex, length, parse, prototype, push, replace, slice, stringify,
|
||||
test, toJSON, toString, valueOf
|
||||
*/
|
||||
|
||||
|
||||
// Create a JSON object only if one does not already exist. We create the
|
||||
// methods in a closure to avoid creating global variables.
|
||||
|
||||
if (typeof JSON !== 'object') {
|
||||
JSON = {};
|
||||
}
|
||||
|
||||
(function () {
|
||||
'use strict';
|
||||
|
||||
function f(n) {
|
||||
// Format integers to have at least two digits.
|
||||
return n < 10 ? '0' + n : n;
|
||||
}
|
||||
|
||||
if (typeof Date.prototype.toJSON !== 'function') {
|
||||
|
||||
Date.prototype.toJSON = function (key) {
|
||||
|
||||
return isFinite(this.valueOf())
|
||||
? this.getUTCFullYear() + '-' +
|
||||
f(this.getUTCMonth() + 1) + '-' +
|
||||
f(this.getUTCDate()) + 'T' +
|
||||
f(this.getUTCHours()) + ':' +
|
||||
f(this.getUTCMinutes()) + ':' +
|
||||
f(this.getUTCSeconds()) + 'Z'
|
||||
: null;
|
||||
};
|
||||
|
||||
String.prototype.toJSON =
|
||||
Number.prototype.toJSON =
|
||||
Boolean.prototype.toJSON = function (key) {
|
||||
return this.valueOf();
|
||||
};
|
||||
}
|
||||
|
||||
var cx = /[\u0000\u00ad\u0600-\u0604\u070f\u17b4\u17b5\u200c-\u200f\u2028-\u202f\u2060-\u206f\ufeff\ufff0-\uffff]/g,
|
||||
escapable = /[\\\"\x00-\x1f\x7f-\x9f\u00ad\u0600-\u0604\u070f\u17b4\u17b5\u200c-\u200f\u2028-\u202f\u2060-\u206f\ufeff\ufff0-\uffff]/g,
|
||||
gap,
|
||||
indent,
|
||||
meta = { // table of character substitutions
|
||||
'\b': '\\b',
|
||||
'\t': '\\t',
|
||||
'\n': '\\n',
|
||||
'\f': '\\f',
|
||||
'\r': '\\r',
|
||||
'"' : '\\"',
|
||||
'\\': '\\\\'
|
||||
},
|
||||
rep;
|
||||
|
||||
|
||||
function quote(string) {
|
||||
|
||||
// If the string contains no control characters, no quote characters, and no
|
||||
// backslash characters, then we can safely slap some quotes around it.
|
||||
// Otherwise we must also replace the offending characters with safe escape
|
||||
// sequences.
|
||||
|
||||
escapable.lastIndex = 0;
|
||||
return escapable.test(string) ? '"' + string.replace(escapable, function (a) {
|
||||
var c = meta[a];
|
||||
return typeof c === 'string'
|
||||
? c
|
||||
: '\\u' + ('0000' + a.charCodeAt(0).toString(16)).slice(-4);
|
||||
}) + '"' : '"' + string + '"';
|
||||
}
|
||||
|
||||
|
||||
function str(key, holder) {
|
||||
|
||||
// Produce a string from holder[key].
|
||||
|
||||
var i, // The loop counter.
|
||||
k, // The member key.
|
||||
v, // The member value.
|
||||
length,
|
||||
mind = gap,
|
||||
partial,
|
||||
value = holder[key];
|
||||
|
||||
// If the value has a toJSON method, call it to obtain a replacement value.
|
||||
|
||||
if (value && typeof value === 'object' &&
|
||||
typeof value.toJSON === 'function') {
|
||||
value = value.toJSON(key);
|
||||
}
|
||||
|
||||
// If we were called with a replacer function, then call the replacer to
|
||||
// obtain a replacement value.
|
||||
|
||||
if (typeof rep === 'function') {
|
||||
value = rep.call(holder, key, value);
|
||||
}
|
||||
|
||||
// What happens next depends on the value's type.
|
||||
|
||||
switch (typeof value) {
|
||||
case 'string':
|
||||
return quote(value);
|
||||
|
||||
case 'number':
|
||||
|
||||
// JSON numbers must be finite. Encode non-finite numbers as null.
|
||||
|
||||
return isFinite(value) ? String(value) : 'null';
|
||||
|
||||
case 'boolean':
|
||||
case 'null':
|
||||
|
||||
// If the value is a boolean or null, convert it to a string. Note:
|
||||
// typeof null does not produce 'null'. The case is included here in
|
||||
// the remote chance that this gets fixed someday.
|
||||
|
||||
return String(value);
|
||||
|
||||
// If the type is 'object', we might be dealing with an object or an array or
|
||||
// null.
|
||||
|
||||
case 'object':
|
||||
|
||||
// Due to a specification blunder in ECMAScript, typeof null is 'object',
|
||||
// so watch out for that case.
|
||||
|
||||
if (!value) {
|
||||
return 'null';
|
||||
}
|
||||
|
||||
// Make an array to hold the partial results of stringifying this object value.
|
||||
|
||||
gap += indent;
|
||||
partial = [];
|
||||
|
||||
// Is the value an array?
|
||||
|
||||
if (Object.prototype.toString.apply(value) === '[object Array]') {
|
||||
|
||||
// The value is an array. Stringify every element. Use null as a placeholder
|
||||
// for non-JSON values.
|
||||
|
||||
length = value.length;
|
||||
for (i = 0; i < length; i += 1) {
|
||||
partial[i] = str(i, value) || 'null';
|
||||
}
|
||||
|
||||
// Join all of the elements together, separated with commas, and wrap them in
|
||||
// brackets.
|
||||
|
||||
v = partial.length === 0
|
||||
? '[]'
|
||||
: gap
|
||||
? '[\n' + gap + partial.join(',\n' + gap) + '\n' + mind + ']'
|
||||
: '[' + partial.join(',') + ']';
|
||||
gap = mind;
|
||||
return v;
|
||||
}
|
||||
|
||||
// If the replacer is an array, use it to select the members to be stringified.
|
||||
|
||||
if (rep && typeof rep === 'object') {
|
||||
length = rep.length;
|
||||
for (i = 0; i < length; i += 1) {
|
||||
if (typeof rep[i] === 'string') {
|
||||
k = rep[i];
|
||||
v = str(k, value);
|
||||
if (v) {
|
||||
partial.push(quote(k) + (gap ? ': ' : ':') + v);
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
|
||||
// Otherwise, iterate through all of the keys in the object.
|
||||
|
||||
for (k in value) {
|
||||
if (Object.prototype.hasOwnProperty.call(value, k)) {
|
||||
v = str(k, value);
|
||||
if (v) {
|
||||
partial.push(quote(k) + (gap ? ': ' : ':') + v);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Join all of the member texts together, separated with commas,
|
||||
// and wrap them in braces.
|
||||
|
||||
v = partial.length === 0
|
||||
? '{}'
|
||||
: gap
|
||||
? '{\n' + gap + partial.join(',\n' + gap) + '\n' + mind + '}'
|
||||
: '{' + partial.join(',') + '}';
|
||||
gap = mind;
|
||||
return v;
|
||||
}
|
||||
}
|
||||
|
||||
// If the JSON object does not yet have a stringify method, give it one.
|
||||
|
||||
if (typeof JSON.stringify !== 'function') {
|
||||
JSON.stringify = function (value, replacer, space) {
|
||||
|
||||
// The stringify method takes a value and an optional replacer, and an optional
|
||||
// space parameter, and returns a JSON text. The replacer can be a function
|
||||
// that can replace values, or an array of strings that will select the keys.
|
||||
// A default replacer method can be provided. Use of the space parameter can
|
||||
// produce text that is more easily readable.
|
||||
|
||||
var i;
|
||||
gap = '';
|
||||
indent = '';
|
||||
|
||||
// If the space parameter is a number, make an indent string containing that
|
||||
// many spaces.
|
||||
|
||||
if (typeof space === 'number') {
|
||||
for (i = 0; i < space; i += 1) {
|
||||
indent += ' ';
|
||||
}
|
||||
|
||||
// If the space parameter is a string, it will be used as the indent string.
|
||||
|
||||
} else if (typeof space === 'string') {
|
||||
indent = space;
|
||||
}
|
||||
|
||||
// If there is a replacer, it must be a function or an array.
|
||||
// Otherwise, throw an error.
|
||||
|
||||
rep = replacer;
|
||||
if (replacer && typeof replacer !== 'function' &&
|
||||
(typeof replacer !== 'object' ||
|
||||
typeof replacer.length !== 'number')) {
|
||||
throw new Error('JSON.stringify');
|
||||
}
|
||||
|
||||
// Make a fake root object containing our value under the key of ''.
|
||||
// Return the result of stringifying the value.
|
||||
|
||||
return str('', {'': value});
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
// If the JSON object does not yet have a parse method, give it one.
|
||||
|
||||
if (typeof JSON.parse !== 'function') {
|
||||
JSON.parse = function (text, reviver) {
|
||||
|
||||
// The parse method takes a text and an optional reviver function, and returns
|
||||
// a JavaScript value if the text is a valid JSON text.
|
||||
|
||||
var j;
|
||||
|
||||
function walk(holder, key) {
|
||||
|
||||
// The walk method is used to recursively walk the resulting structure so
|
||||
// that modifications can be made.
|
||||
|
||||
var k, v, value = holder[key];
|
||||
if (value && typeof value === 'object') {
|
||||
for (k in value) {
|
||||
if (Object.prototype.hasOwnProperty.call(value, k)) {
|
||||
v = walk(value, k);
|
||||
if (v !== undefined) {
|
||||
value[k] = v;
|
||||
} else {
|
||||
delete value[k];
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return reviver.call(holder, key, value);
|
||||
}
|
||||
|
||||
|
||||
// Parsing happens in four stages. In the first stage, we replace certain
|
||||
// Unicode characters with escape sequences. JavaScript handles many characters
|
||||
// incorrectly, either silently deleting them, or treating them as line endings.
|
||||
|
||||
text = String(text);
|
||||
cx.lastIndex = 0;
|
||||
if (cx.test(text)) {
|
||||
text = text.replace(cx, function (a) {
|
||||
return '\\u' +
|
||||
('0000' + a.charCodeAt(0).toString(16)).slice(-4);
|
||||
});
|
||||
}
|
||||
|
||||
// In the second stage, we run the text against regular expressions that look
|
||||
// for non-JSON patterns. We are especially concerned with '()' and 'new'
|
||||
// because they can cause invocation, and '=' because it can cause mutation.
|
||||
// But just to be safe, we want to reject all unexpected forms.
|
||||
|
||||
// We split the second stage into 4 regexp operations in order to work around
|
||||
// crippling inefficiencies in IE's and Safari's regexp engines. First we
|
||||
// replace the JSON backslash pairs with '@' (a non-JSON character). Second, we
|
||||
// replace all simple value tokens with ']' characters. Third, we delete all
|
||||
// open brackets that follow a colon or comma or that begin the text. Finally,
|
||||
// we look to see that the remaining characters are only whitespace or ']' or
|
||||
// ',' or ':' or '{' or '}'. If that is so, then the text is safe for eval.
|
||||
|
||||
if (/^[\],:{}\s]*$/
|
||||
.test(text.replace(/\\(?:["\\\/bfnrt]|u[0-9a-fA-F]{4})/g, '@')
|
||||
.replace(/"[^"\\\n\r]*"|true|false|null|-?\d+(?:\.\d*)?(?:[eE][+\-]?\d+)?/g, ']')
|
||||
.replace(/(?:^|:|,)(?:\s*\[)+/g, ''))) {
|
||||
|
||||
// In the third stage we use the eval function to compile the text into a
|
||||
// JavaScript structure. The '{' operator is subject to a syntactic ambiguity
|
||||
// in JavaScript: it can begin a block or an object literal. We wrap the text
|
||||
// in parens to eliminate the ambiguity.
|
||||
|
||||
j = eval('(' + text + ')');
|
||||
|
||||
// In the optional fourth stage, we recursively walk the new structure, passing
|
||||
// each name/value pair to a reviver function for possible transformation.
|
||||
|
||||
return typeof reviver === 'function'
|
||||
? walk({'': j}, '')
|
||||
: j;
|
||||
}
|
||||
|
||||
// If the text is not JSON parseable, then a SyntaxError is thrown.
|
||||
|
||||
throw new SyntaxError('JSON.parse');
|
||||
};
|
||||
}
|
||||
}());
|
208
src/main/javascript/lib/plugin.js
Normal file
208
src/main/javascript/lib/plugin.js
Normal file
|
@ -0,0 +1,208 @@
|
|||
var File = java.io.File;
|
||||
var FileWriter = java.io.FileWriter;
|
||||
var PrintWriter = java.io.PrintWriter;
|
||||
|
||||
/*
|
||||
Save a javascript object to a file (saves using JSON notation)
|
||||
*/
|
||||
var _save = function(object, filename){
|
||||
var objectToStr = null;
|
||||
try{
|
||||
objectToStr = JSON.stringify(object);
|
||||
}catch(e){
|
||||
print("ERROR: " + e.getMessage() + " while saving " + filename);
|
||||
return;
|
||||
}
|
||||
var f = (filename instanceof File) ? filename : new File(filename);
|
||||
var out = new PrintWriter(new FileWriter(f));
|
||||
out.println( objectToStr );
|
||||
out.close();
|
||||
};
|
||||
/*
|
||||
plugin management
|
||||
*/
|
||||
var _plugins = {};
|
||||
|
||||
var _plugin = function(/* String */ moduleName, /* Object */ moduleObject, isPersistent)
|
||||
{
|
||||
//
|
||||
// don't load plugin more than once
|
||||
//
|
||||
if (typeof _plugins[moduleName] != "undefined")
|
||||
return _plugins[moduleName].module;
|
||||
|
||||
var pluginData = {persistent: isPersistent, module: moduleObject};
|
||||
moduleObject.store = moduleObject.store || {};
|
||||
_plugins[moduleName] = pluginData;
|
||||
|
||||
if (isPersistent){
|
||||
var loadedStore = load(dataDir.canonicalPath + "/" + moduleName + "-store.json");
|
||||
if (loadedStore){
|
||||
moduleObject.store = loadedStore;
|
||||
}else{
|
||||
if (!moduleObject.store){
|
||||
moduleObject.store = {};
|
||||
}
|
||||
}
|
||||
}
|
||||
return moduleObject;
|
||||
};
|
||||
/*
|
||||
allow for deferred execution (once all modules have loaded)
|
||||
*/
|
||||
var _deferred = [];
|
||||
var _ready = function( func ){
|
||||
_deferred.push(func);
|
||||
};
|
||||
var _cmdInterceptors = [];
|
||||
/*
|
||||
command management - allow for non-ops to execute approved javascript code.
|
||||
*/
|
||||
var _commands = {};
|
||||
exports.commands = _commands;
|
||||
var _command = function(name,func,options,intercepts)
|
||||
{
|
||||
if (typeof name == "undefined"){
|
||||
// it's an invocation from the Java Plugin!
|
||||
if (__cmdArgs.length === 0)
|
||||
throw new Error("Usage: jsp command-name command-parameters");
|
||||
var name = __cmdArgs[0];
|
||||
var cmd = _commands[name];
|
||||
if (typeof cmd === "undefined"){
|
||||
// it's not a global command - pass it on to interceptors
|
||||
var intercepted = false;
|
||||
for (var i = 0;i < _cmdInterceptors.length;i++){
|
||||
if (_cmdInterceptors[i](__cmdArgs))
|
||||
intercepted = true;
|
||||
}
|
||||
if (!intercepted)
|
||||
self.sendMessage("Command '" + name + "' is not recognised");
|
||||
}else{
|
||||
func = cmd.callback;
|
||||
var params = [];
|
||||
for (var i =1; i < __cmdArgs.length;i++){
|
||||
params.push("" + __cmdArgs[i]);
|
||||
}
|
||||
return func(params);
|
||||
}
|
||||
}else{
|
||||
if (typeof options == "undefined")
|
||||
options = [];
|
||||
_commands[name] = {callback: func, options: options};
|
||||
if (intercepts)
|
||||
_cmdInterceptors.push(func);
|
||||
return func;
|
||||
}
|
||||
};
|
||||
|
||||
exports.plugin = _plugin;
|
||||
exports.command = _command;
|
||||
exports.save = _save;
|
||||
|
||||
var scriptCraftDir = null;
|
||||
var pluginDir = null;
|
||||
var dataDir = null;
|
||||
|
||||
exports.autoload = function(dir) {
|
||||
|
||||
scriptCraftDir = dir;
|
||||
pluginDir = new File(dir, "plugins");
|
||||
dataDir = new File(dir, "data");
|
||||
|
||||
var _canonize = function(file){
|
||||
return "" + file.getCanonicalPath().replaceAll("\\\\","/");
|
||||
};
|
||||
/*
|
||||
recursively walk the given directory and return a list of all .js files
|
||||
*/
|
||||
var _listSourceFiles = function(store,dir)
|
||||
{
|
||||
var files = dir.listFiles();
|
||||
for (var i = 0;i < files.length; i++) {
|
||||
var file = files[i];
|
||||
if (file.isDirectory()){
|
||||
_listSourceFiles(store,file);
|
||||
}else{
|
||||
if ((file.getCanonicalPath().endsWith(".js")
|
||||
|| file.getCanonicalPath().endsWith(".coffee"))
|
||||
) {
|
||||
store.push(file);
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
/*
|
||||
sort so that .js files with same name as parent directory appear before
|
||||
other files in the same directory
|
||||
*/
|
||||
var sortByModule = function(a,b){
|
||||
a = _canonize(a);
|
||||
b = _canonize(b);
|
||||
var aparts = (""+a).split(/\//);
|
||||
var bparts = (""+b).split(/\//);
|
||||
//var adir = aparts[aparts.length-2];
|
||||
var adir = aparts.slice(0,aparts.length-1).join("/");
|
||||
var afile = aparts[aparts.length-1];
|
||||
//var bdir = bparts[bparts.length-2];
|
||||
var bdir = bparts.slice(0,bparts.length-1).join("/");
|
||||
var bfile = bparts[bparts.length-1];
|
||||
|
||||
if(adir<bdir) return -1;
|
||||
if(adir>bdir) return 1;
|
||||
|
||||
afile = afile.match(/[a-zA-Z0-9\-_]+/)[0];
|
||||
|
||||
if (adir.match(new RegExp(afile + "$")))
|
||||
return -1;
|
||||
else
|
||||
return 1;
|
||||
};
|
||||
/*
|
||||
Reload all of the .js files in the given directory
|
||||
*/
|
||||
var _reload = function(pluginDir)
|
||||
{
|
||||
_loaded = [];
|
||||
var sourceFiles = [];
|
||||
_listSourceFiles(sourceFiles,pluginDir);
|
||||
|
||||
//sourceFiles.sort(sortByModule);
|
||||
|
||||
//
|
||||
// script files whose name begins with _ (underscore)
|
||||
// will not be loaded automatically at startup.
|
||||
// These files are assumed to be dependencies/private to plugins
|
||||
//
|
||||
// E.g. If you have a plugin called myMiniGame.js in the myMiniGame directory
|
||||
// and which in addition to myMiniGame.js also includes _myMiniGame_currency.js _myMiniGame_events.js etc.
|
||||
// then it's assumed that _myMiniGame_currency.js and _myMiniGame_events.js will be loaded
|
||||
// as dependencies by myMiniGame.js and do not need to be loaded via js reload
|
||||
//
|
||||
var len = sourceFiles.length;
|
||||
if (config.verbose)
|
||||
logger.info(len + " scriptcraft plugins found.");
|
||||
for (var i = 0;i < len; i++){
|
||||
var pluginPath = _canonize(sourceFiles[i]);
|
||||
if (config.verbose)
|
||||
logger.info("Loading plugin: " + pluginPath);
|
||||
var module = require(pluginPath);
|
||||
for (var property in module){
|
||||
/*
|
||||
all exports in plugins become global
|
||||
*/
|
||||
global[property] = module[property];
|
||||
}
|
||||
}
|
||||
};
|
||||
_reload(pluginDir);
|
||||
};
|
||||
addUnloadHandler(function(){
|
||||
//
|
||||
// save all plugins which have persistent data
|
||||
//
|
||||
for (var moduleName in _plugins){
|
||||
var pluginData = _plugins[moduleName];
|
||||
if (pluginData.persistent)
|
||||
_save(pluginData.module.store, dataDir.canonicalPath + "/" + moduleName + "-store.json");
|
||||
}
|
||||
});
|
4
src/main/javascript/modules/fireworks/package.json
Normal file
4
src/main/javascript/modules/fireworks/package.json
Normal file
|
@ -0,0 +1,4 @@
|
|||
{
|
||||
name: 'fireworks',
|
||||
main: './fireworks.js'
|
||||
}
|
4
src/main/javascript/modules/http/package.json
Normal file
4
src/main/javascript/modules/http/package.json
Normal file
|
@ -0,0 +1,4 @@
|
|||
{
|
||||
"name": "http",
|
||||
"main": "./request.js"
|
||||
}
|
14
src/main/javascript/modules/partial.js
Normal file
14
src/main/javascript/modules/partial.js
Normal file
|
@ -0,0 +1,14 @@
|
|||
/**
|
||||
* Create a partial function
|
||||
*
|
||||
* Parameters:
|
||||
* func - base function
|
||||
* [remaining arguments] - arguments bound to the partial function
|
||||
*/
|
||||
module.exports = function (func /*, 0..n args */) {
|
||||
var args = Array.prototype.slice.call(arguments, 1);
|
||||
return function() {
|
||||
var allArguments = args.concat(Array.prototype.slice.call(arguments));
|
||||
return func.apply(this, allArguments);
|
||||
};
|
||||
}
|
4
src/main/javascript/modules/signs/package.json
Normal file
4
src/main/javascript/modules/signs/package.json
Normal file
|
@ -0,0 +1,4 @@
|
|||
{
|
||||
name: 'signs',
|
||||
main: './menu.js'
|
||||
}
|
4
src/main/javascript/modules/underscore/package.json
Normal file
4
src/main/javascript/modules/underscore/package.json
Normal file
|
@ -0,0 +1,4 @@
|
|||
{
|
||||
name: 'underscore',
|
||||
main: './underscore.js'
|
||||
}
|
1314
src/main/javascript/modules/underscore/underscore.js
Normal file
1314
src/main/javascript/modules/underscore/underscore.js
Normal file
File diff suppressed because it is too large
Load diff
4
src/main/javascript/modules/utils/package.json
Normal file
4
src/main/javascript/modules/utils/package.json
Normal file
|
@ -0,0 +1,4 @@
|
|||
{
|
||||
"name": 'utils',
|
||||
"main": './utils.js'
|
||||
}
|
275
src/main/javascript/plugins/drone/blocks.js
Normal file
275
src/main/javascript/plugins/drone/blocks.js
Normal file
|
@ -0,0 +1,275 @@
|
|||
/************************************************************************
|
||||
Blocks Module
|
||||
=============
|
||||
You hate having to lookup [Data Values][dv] when you use ScriptCraft's Drone() functions. So do I.
|
||||
So I created this blocks object which is a helper object for use in construction.
|
||||
|
||||
Examples
|
||||
--------
|
||||
|
||||
box( blocks.oak ); // creates a single oak wood block
|
||||
box( blocks.sand, 3, 2, 1 ); // creates a block of sand 3 wide x 2 high x 1 long
|
||||
box( blocks.wool.green, 2 ); // creates a block of green wool 2 blocks wide
|
||||
|
||||
Color aliased properties that were a direct descendant of the blocks object are no longer used to avoid confusion with carpet and stained clay blocks. In addition, there's a convenience array `blocks.rainbow` which is an array of the 7 colors of the rainbow (or closest approximations).
|
||||
|
||||
***/
|
||||
var blocks = {
|
||||
air: 0,
|
||||
stone: 1,
|
||||
grass: 2,
|
||||
dirt: 3,
|
||||
cobblestone: 4,
|
||||
oak: 5,
|
||||
spruce: '5:1',
|
||||
birch: '5:2',
|
||||
jungle: '5:3',
|
||||
sapling: {
|
||||
oak: 6,
|
||||
spruce: '6:1',
|
||||
birch: '62:2',
|
||||
jungle: '6:3'
|
||||
},
|
||||
bedrock: 7,
|
||||
water: 8,
|
||||
water_still: 9,
|
||||
lava: 10,
|
||||
lava_still: 11,
|
||||
sand: 12,
|
||||
gravel: 13,
|
||||
gold_ore: 14,
|
||||
iron_ore: 15,
|
||||
coal_ore: 16,
|
||||
wood: 17,
|
||||
leaves: 18,
|
||||
sponge: 19,
|
||||
glass: 20,
|
||||
lapis_lazuli_ore: 21,
|
||||
lapis_lazuli_block: 22,
|
||||
dispenser: 23,
|
||||
sandstone: 24,
|
||||
note: 25,
|
||||
bed: 26,
|
||||
powered_rail: 27,
|
||||
detector_rail: 28,
|
||||
sticky_piston: 29,
|
||||
cobweb: 30,
|
||||
grass_tall: 31,
|
||||
dead_bush: 32,
|
||||
piston: 33,
|
||||
piston_extn: 34,
|
||||
wool: {
|
||||
white: 35 // All other colors added below
|
||||
},
|
||||
dandelion: 37,
|
||||
flower_yellow: 37,
|
||||
rose: 38,
|
||||
flower_red: 38,
|
||||
mushroom_brown: 39,
|
||||
mushroom_red: 40,
|
||||
gold: 41,
|
||||
iron: 42,
|
||||
tnt: 46,
|
||||
bookshelf: 47,
|
||||
moss_stone: 48,
|
||||
obsidian: 49,
|
||||
torch: 50,
|
||||
fire: 51,
|
||||
monster_spawner: 52,
|
||||
stairs: {
|
||||
oak: 53,
|
||||
cobblestone: 67,
|
||||
brick: 108,
|
||||
stone: 109,
|
||||
nether: 114,
|
||||
sandstone: 128,
|
||||
spruce: 134,
|
||||
birch: 135,
|
||||
jungle: 136,
|
||||
quartz: 156
|
||||
},
|
||||
chest: 54,
|
||||
redstone_wire: 55,
|
||||
diamond_ore: 56,
|
||||
diamond: 57,
|
||||
crafting_table: 58,
|
||||
wheat_seeds: 59,
|
||||
farmland: 60,
|
||||
furnace: 61,
|
||||
furnace_burning: 62,
|
||||
sign_post: 63,
|
||||
door_wood: 64,
|
||||
ladder: 65,
|
||||
rail: 66,
|
||||
sign: 68,
|
||||
lever: 69,
|
||||
pressure_plate_stone: 70,
|
||||
door_iron: 71,
|
||||
pressure_plate_wood: 72,
|
||||
redstone_ore: 73,
|
||||
redstone_ore_glowing: 74,
|
||||
torch_redstone: 75,
|
||||
torch_redstone_active: 76,
|
||||
stone_button: 77,
|
||||
ice: 79,
|
||||
snow: 80,
|
||||
cactus: 81,
|
||||
clay: 82,
|
||||
sugar_cane: 83,
|
||||
jukebox: 84,
|
||||
fence: 85,
|
||||
pumpkin: 86,
|
||||
netherrack: 87,
|
||||
soulsand: 88,
|
||||
glowstone: 89,
|
||||
netherportal: 90,
|
||||
jackolantern: 91,
|
||||
cake: 92,
|
||||
redstone_repeater: 93,
|
||||
redeston_repeater_active: 94,
|
||||
chest_locked: 95,
|
||||
trapdoor: 96,
|
||||
monster_egg: 97,
|
||||
brick: {
|
||||
stone: 98,
|
||||
mossy: '98:1',
|
||||
cracked: '98:2',
|
||||
chiseled: '98:3',
|
||||
red: 45
|
||||
},
|
||||
mushroom_brown_huge: 99,
|
||||
mushroom_red_huge: 100,
|
||||
iron_bars: 101,
|
||||
glass_pane: 102,
|
||||
melon: 103,
|
||||
pumpkin_stem: 104,
|
||||
melon_stem: 105,
|
||||
vines: 106,
|
||||
fence_gate: 107,
|
||||
mycelium: 110,
|
||||
lily_pad: 111,
|
||||
nether: 112,
|
||||
nether_fence: 113,
|
||||
netherwart: 115,
|
||||
table_enchantment: 116,
|
||||
brewing_stand: 117,
|
||||
cauldron: 118,
|
||||
endportal: 119,
|
||||
endportal_frame: 120,
|
||||
endstone: 121,
|
||||
dragon_egg: 122,
|
||||
redstone_lamp: 123,
|
||||
redstone_lamp_active: 124,
|
||||
slab: {
|
||||
snow: 78,
|
||||
stone: 44,
|
||||
sandstone: '44:1',
|
||||
wooden: '44:2',
|
||||
cobblestone: '44:3',
|
||||
brick: '44:4',
|
||||
stonebrick: '44:5',
|
||||
netherbrick:'44:6',
|
||||
quartz: '44:7',
|
||||
oak: 126,
|
||||
spruce: '126:1',
|
||||
birch: '126:2',
|
||||
jungle: '126:3',
|
||||
upper: {
|
||||
stone: '44:8',
|
||||
sandstone: '44:9',
|
||||
wooden: '44:10',
|
||||
cobblestone: '44:11',
|
||||
brick: '44:12',
|
||||
stonebrick: '44:13',
|
||||
netherbrick:'44:14',
|
||||
quartz: '44:15',
|
||||
oak: '126:8',
|
||||
spruce: '126:9',
|
||||
birch: '126:10',
|
||||
jungle: '126:11',
|
||||
}
|
||||
},
|
||||
cocoa: 127,
|
||||
emerald_ore: 129,
|
||||
enderchest: 130,
|
||||
tripwire_hook: 131,
|
||||
tripwire: 132,
|
||||
emerald: 133,
|
||||
command: 137,
|
||||
beacon: 138,
|
||||
cobblestone_wall: 139,
|
||||
flowerpot: 140,
|
||||
carrots: 141,
|
||||
potatoes: 142,
|
||||
button_wood: 143,
|
||||
mobhead: 144,
|
||||
anvil: 145,
|
||||
chest_trapped: 146,
|
||||
pressure_plate_weighted_light: 147,
|
||||
pressure_plate_weighted_heavy: 148,
|
||||
redstone_comparator: 149,
|
||||
redstone_comparator_active: 150,
|
||||
daylight_sensor: 151,
|
||||
redstone: 152,
|
||||
netherquartzore: 153,
|
||||
hopper: 154,
|
||||
quartz: 155,
|
||||
rail_activator: 157,
|
||||
dropper: 158,
|
||||
stained_clay: {
|
||||
white: 159 // All other colors added below
|
||||
},
|
||||
hay: 170,
|
||||
carpet: {
|
||||
white: 171 // All other colors added below
|
||||
},
|
||||
hardened_clay: 172,
|
||||
coal_block: 173
|
||||
};
|
||||
|
||||
// Add all available colors to colorized block collections
|
||||
|
||||
var colors = {
|
||||
orange: ':1',
|
||||
magenta: ':2',
|
||||
lightblue: ':3',
|
||||
yellow: ':4',
|
||||
lime: ':5',
|
||||
pink: ':6',
|
||||
gray: ':7',
|
||||
lightgray: ':8',
|
||||
cyan: ':9',
|
||||
purple: ':10',
|
||||
blue: ':11',
|
||||
brown: ':12',
|
||||
green: ':13',
|
||||
red: ':14',
|
||||
black: ':15'
|
||||
};
|
||||
var colorized_blocks = ["wool", "stained_clay", "carpet"];
|
||||
|
||||
for (var i = 0, len = colorized_blocks.length; i < len; i++) {
|
||||
var block = colorized_blocks[i],
|
||||
data_value = blocks[block].white;
|
||||
|
||||
for (var color in colors) {
|
||||
blocks[block][color] = data_value + colors[color];
|
||||
}
|
||||
};
|
||||
|
||||
/*
|
||||
rainbow colors - a convenience
|
||||
Color aliased properties that were a direct descendant of the blocks
|
||||
object are no longer used to avoid confusion with carpet and stained
|
||||
clay blocks.
|
||||
*/
|
||||
blocks.rainbow = [blocks.wool.red,
|
||||
blocks.wool.orange,
|
||||
blocks.wool.yellow,
|
||||
blocks.wool.lime,
|
||||
blocks.wool.lightblue,
|
||||
blocks.wool.blue,
|
||||
blocks.wool.purple];
|
||||
|
||||
|
||||
module.exports = blocks;
|
376
src/main/javascript/plugins/drone/blocktype.js
Normal file
376
src/main/javascript/plugins/drone/blocktype.js
Normal file
|
@ -0,0 +1,376 @@
|
|||
var Drone = require('./drone');
|
||||
var blocks = require('./blocks');
|
||||
|
||||
module.exports = Drone;
|
||||
/************************************************************************
|
||||
Drone.blocktype() method
|
||||
========================
|
||||
Creates the text out of blocks. Useful for large-scale in-game signs.
|
||||
|
||||
Parameters
|
||||
----------
|
||||
|
||||
* message - The message to create - (use `\n` for newlines)
|
||||
* foregroundBlock (default: black wool) - The block to use for the foreground
|
||||
* backgroundBlock (default: none) - The block to use for the background
|
||||
|
||||
Example
|
||||
-------
|
||||
To create a 2-line high message using glowstone...
|
||||
|
||||
blocktype("Hello\nWorld",blocks.glowstone);
|
||||
|
||||
![blocktype example][imgbt1]
|
||||
|
||||
[imgbt1]: img/blocktype1.png
|
||||
|
||||
***/
|
||||
|
||||
var bitmaps = {
|
||||
raw: {
|
||||
'0':' ### '+
|
||||
' # # '+
|
||||
' # # '+
|
||||
' # # '+
|
||||
' ### ',
|
||||
|
||||
'1':' # '+
|
||||
' ## '+
|
||||
' # '+
|
||||
' # '+
|
||||
' ### ',
|
||||
|
||||
'2':' ### '+
|
||||
' # '+
|
||||
' ### '+
|
||||
' # '+
|
||||
' ### ',
|
||||
|
||||
'3':' ### '+
|
||||
' # '+
|
||||
' ## '+
|
||||
' # '+
|
||||
' ### ',
|
||||
|
||||
'4':' # '+
|
||||
' ## '+
|
||||
' # # '+
|
||||
' ### '+
|
||||
' # ',
|
||||
|
||||
'5':' ### '+
|
||||
' # '+
|
||||
' ### '+
|
||||
' # '+
|
||||
' ### ',
|
||||
|
||||
'6':' ### '+
|
||||
' # '+
|
||||
' ### '+
|
||||
' # # '+
|
||||
' ### ',
|
||||
|
||||
'7':' ### '+
|
||||
' # '+
|
||||
' # '+
|
||||
' # '+
|
||||
' # ',
|
||||
|
||||
'8':' ### '+
|
||||
' # # '+
|
||||
' ### '+
|
||||
' # # '+
|
||||
' ### ',
|
||||
|
||||
'9':' ### '+
|
||||
' # # '+
|
||||
' ### '+
|
||||
' # '+
|
||||
' ### ',
|
||||
|
||||
'a':' ### '+
|
||||
' # # '+
|
||||
' ### '+
|
||||
' # # '+
|
||||
' # # ',
|
||||
|
||||
'b':' ## '+
|
||||
' # # '+
|
||||
' ## '+
|
||||
' # # '+
|
||||
' ## ',
|
||||
|
||||
'c':' ## '+
|
||||
' # '+
|
||||
' # '+
|
||||
' # '+
|
||||
' ## ',
|
||||
|
||||
'd':' ## '+
|
||||
' # # '+
|
||||
' # # '+
|
||||
' # # '+
|
||||
' ## ',
|
||||
|
||||
'e':' ### '+
|
||||
' # '+
|
||||
' ## '+
|
||||
' # '+
|
||||
' ### ',
|
||||
|
||||
'f':' ### '+
|
||||
' # '+
|
||||
' ## '+
|
||||
' # '+
|
||||
' # ',
|
||||
|
||||
'g':' ### '+
|
||||
' # '+
|
||||
' # '+
|
||||
' # # '+
|
||||
' ### ',
|
||||
|
||||
'h':' # # '+
|
||||
' # # '+
|
||||
' ### '+
|
||||
' # # '+
|
||||
' # # ',
|
||||
|
||||
'i':' ### '+
|
||||
' # '+
|
||||
' # '+
|
||||
' # '+
|
||||
' ### ',
|
||||
|
||||
'j':' ### '+
|
||||
' # '+
|
||||
' # '+
|
||||
' # '+
|
||||
' # ',
|
||||
|
||||
'k':' # '+
|
||||
' # # '+
|
||||
' ## '+
|
||||
' # # '+
|
||||
' # # ',
|
||||
|
||||
'l':' # '+
|
||||
' # '+
|
||||
' # '+
|
||||
' # '+
|
||||
' ### ',
|
||||
|
||||
'm':' # # '+
|
||||
' ### '+
|
||||
' # # '+
|
||||
' # # '+
|
||||
' # # ',
|
||||
|
||||
'n':' ## '+
|
||||
' # # '+
|
||||
' # # '+
|
||||
' # # '+
|
||||
' # # ',
|
||||
|
||||
'o':' # '+
|
||||
' # # '+
|
||||
' # # '+
|
||||
' # # '+
|
||||
' # ',
|
||||
|
||||
'p':' ### '+
|
||||
' # # '+
|
||||
' ### '+
|
||||
' # '+
|
||||
' # ',
|
||||
|
||||
'q':' ### '+
|
||||
' # # '+
|
||||
' # # '+
|
||||
' ### '+
|
||||
' # ',
|
||||
|
||||
'r':' ## '+
|
||||
' # # '+
|
||||
' ## '+
|
||||
' # # '+
|
||||
' # # ',
|
||||
|
||||
's':' ## '+
|
||||
' # '+
|
||||
' ### '+
|
||||
' # '+
|
||||
' ## ',
|
||||
|
||||
't':' ### '+
|
||||
' # '+
|
||||
' # '+
|
||||
' # '+
|
||||
' # ',
|
||||
|
||||
'u':' # # '+
|
||||
' # # '+
|
||||
' # # '+
|
||||
' # # '+
|
||||
' ### ',
|
||||
|
||||
'v':' # # '+
|
||||
' # # '+
|
||||
' # # '+
|
||||
' # # '+
|
||||
' # ',
|
||||
|
||||
'w':' # # '+
|
||||
' # # '+
|
||||
' # # '+
|
||||
' ### '+
|
||||
' # # ',
|
||||
|
||||
'x':' # # '+
|
||||
' # # '+
|
||||
' # '+
|
||||
' # # '+
|
||||
' # # ',
|
||||
|
||||
'y':' # # '+
|
||||
' # # '+
|
||||
' # # '+
|
||||
' # '+
|
||||
' # ',
|
||||
|
||||
'z':' ### '+
|
||||
' # '+
|
||||
' # '+
|
||||
' # '+
|
||||
' ### ',
|
||||
|
||||
'!':' # '+
|
||||
' # '+
|
||||
' # '+
|
||||
' '+
|
||||
' # ',
|
||||
|
||||
':':' '+
|
||||
' # '+
|
||||
' '+
|
||||
' # '+
|
||||
' ',
|
||||
|
||||
';':' '+
|
||||
' # '+
|
||||
' '+
|
||||
' # '+
|
||||
' # ',
|
||||
|
||||
',':' '+
|
||||
' '+
|
||||
' '+
|
||||
' # '+
|
||||
' # ',
|
||||
|
||||
'/':' # '+
|
||||
' # '+
|
||||
' # '+
|
||||
' # '+
|
||||
' # ',
|
||||
|
||||
'+':' '+
|
||||
' # '+
|
||||
' ### '+
|
||||
' # '+
|
||||
' ',
|
||||
|
||||
'-':' '+
|
||||
' '+
|
||||
' ### '+
|
||||
' '+
|
||||
' ',
|
||||
|
||||
'.':' '+
|
||||
' '+
|
||||
' '+
|
||||
' '+
|
||||
' # ',
|
||||
|
||||
"'":' # '+
|
||||
' # '+
|
||||
' '+
|
||||
' '+
|
||||
' ',
|
||||
|
||||
' ':' '+
|
||||
' '+
|
||||
' '+
|
||||
' '+
|
||||
' '
|
||||
},
|
||||
computed: {}
|
||||
};
|
||||
/*
|
||||
wph 20130121 compute the width, and x,y coords of pixels ahead of time
|
||||
*/
|
||||
for (var c in bitmaps.raw){
|
||||
var bits = bitmaps.raw[c];
|
||||
var width = bits.length/5;
|
||||
var bmInfo = {"width": width,"pixels":[]}
|
||||
bitmaps.computed[c] = bmInfo;
|
||||
for (var j = 0; j < bits.length; j++){
|
||||
if (bits.charAt(j) != ' '){
|
||||
bmInfo.pixels.push([j%width,Math.ceil(j/width)]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//
|
||||
// message
|
||||
// string with text to be displayed
|
||||
// fg
|
||||
// foreground material. The material the text will be in.
|
||||
// bg
|
||||
// background material, optional. The negative space within the bounding box of the text.
|
||||
//
|
||||
Drone.extend('blocktype', function(message,fg,bg){
|
||||
|
||||
this.chkpt('blocktext');
|
||||
|
||||
if (typeof fg == "undefined")
|
||||
fg = blocks.wool.black;
|
||||
|
||||
var bmfg = this._getBlockIdAndMeta(fg);
|
||||
var bmbg = null;
|
||||
if (typeof bg != "undefined")
|
||||
bmbg = this._getBlockIdAndMeta(bg);
|
||||
var lines = message.split("\n");
|
||||
var lineCount = lines.length;
|
||||
for (var h = 0;h < lineCount; h++) {
|
||||
var line = lines[h];
|
||||
line = line.toLowerCase().replace(/[^0-9a-z \.\-\+\/\;\'\:\!]/g,"");
|
||||
this.up(7*(lineCount-(h+1)));
|
||||
|
||||
for (var i =0;i < line.length; i++) {
|
||||
var ch = line.charAt(i)
|
||||
var bits = bitmaps.computed[ch];
|
||||
if (typeof bits == "undefined"){
|
||||
bits = bitmaps.computed[' '];
|
||||
}
|
||||
var charWidth = bits.width;
|
||||
if (typeof bg != "undefined")
|
||||
this.cuboidX(bmbg[0],bmbg[1],charWidth,7,1);
|
||||
for (var j = 0;j < bits.pixels.length;j++){
|
||||
this.chkpt('btbl');
|
||||
var x = bits.pixels[j][0];
|
||||
var y = bits.pixels[j][1];
|
||||
this.up(6-y).right(x).cuboidX(bmfg[0],bmfg[1]);
|
||||
this.move('btbl');
|
||||
}
|
||||
this.right(charWidth-1);
|
||||
}
|
||||
this.move('blocktext');
|
||||
}
|
||||
|
||||
return this.move('blocktext');
|
||||
});
|
||||
|
||||
|
||||
|
51
src/main/javascript/plugins/drone/contrib/castle.js
Normal file
51
src/main/javascript/plugins/drone/contrib/castle.js
Normal file
|
@ -0,0 +1,51 @@
|
|||
var Drone = require('../drone');
|
||||
module.exports = Drone;
|
||||
//
|
||||
// a castle is just a big wide fort with 4 taller forts at each corner
|
||||
//
|
||||
Drone.extend('castle', function(side, height)
|
||||
{
|
||||
//
|
||||
// use sensible default parameter values
|
||||
// if no parameters are supplied
|
||||
//
|
||||
if (typeof side == "undefined")
|
||||
side = 24;
|
||||
if (typeof height == "undefined")
|
||||
height = 10;
|
||||
if (height < 8 || side < 20)
|
||||
throw new java.lang.RuntimeException("Castles must be at least 20 wide X 8 tall");
|
||||
//
|
||||
// remember where the drone is so it can return 'home'
|
||||
//
|
||||
this.chkpt('castle');
|
||||
//
|
||||
// how big the towers at each corner will be...
|
||||
//
|
||||
var towerSide = 10;
|
||||
var towerHeight = height+4;
|
||||
|
||||
//
|
||||
// the main castle building will be front and right of the first tower
|
||||
//
|
||||
this.fwd(towerSide/2).right(towerSide/2);
|
||||
//
|
||||
// the castle is really just a big fort with 4 smaller 'tower' forts at each corner
|
||||
//
|
||||
this.fort(side,height);
|
||||
//
|
||||
// move back to start position
|
||||
//
|
||||
this.move('castle');
|
||||
//
|
||||
// now place 4 towers at each corner (each tower is another fort)
|
||||
//
|
||||
for (var corner = 0; corner < 4; corner++)
|
||||
{
|
||||
// construct a 'tower' fort
|
||||
this.fort(towerSide,towerHeight);
|
||||
// move forward the length of the castle then turn right
|
||||
this.fwd(side+towerSide-1).turn();
|
||||
}
|
||||
return this.move('castle');
|
||||
});
|
37
src/main/javascript/plugins/drone/contrib/chessboard.js
Normal file
37
src/main/javascript/plugins/drone/contrib/chessboard.js
Normal file
|
@ -0,0 +1,37 @@
|
|||
var Drone = require('../drone');
|
||||
var blocks = require('../blocks');
|
||||
|
||||
module.exports = Drone;
|
||||
/**
|
||||
* Creates a tile pattern of given block types and size
|
||||
*
|
||||
* Paramters:
|
||||
* whiteBlock - blockId used for the traditional white portion of the chessboard
|
||||
* blackBlock - blockId used for the traditional black portion of the chessboard
|
||||
* width - width of the chessboard
|
||||
* height - height of the chessboard
|
||||
*/
|
||||
Drone.extend("chessboard", function(whiteBlock, blackBlock, width, depth) {
|
||||
this.chkpt('chessboard-start');
|
||||
if (typeof whiteBlock == "undefined")
|
||||
whiteBlock = blocks.wool.white;
|
||||
if (typeof blackBlock == "undefined")
|
||||
blackBlock = blocks.wool.black;
|
||||
if (typeof width == "undefined")
|
||||
width = 8;
|
||||
if (typeof depth == "undefined")
|
||||
depth = width;
|
||||
|
||||
for(var i = 0; i < width; ++i) {
|
||||
for(var j = 0; j < depth; ++j) {
|
||||
var block = blackBlock;
|
||||
if((i+j)%2 == 1) {
|
||||
block = whiteBlock;
|
||||
}
|
||||
this.box(block);
|
||||
this.right();
|
||||
}
|
||||
this.move('chessboard-start').fwd(i+1);
|
||||
}
|
||||
return this.move('chessboard-start');
|
||||
});
|
79
src/main/javascript/plugins/drone/contrib/cottage.js
Normal file
79
src/main/javascript/plugins/drone/contrib/cottage.js
Normal file
|
@ -0,0 +1,79 @@
|
|||
var Drone = require('../drone');
|
||||
module.exports = Drone;
|
||||
//
|
||||
// usage:
|
||||
// [1] to build a cottage at the player's current location or the cross-hairs location...
|
||||
//
|
||||
// /js cottage();
|
||||
//
|
||||
// [2] to build a cottage using an existing drone...
|
||||
//
|
||||
// /js drone.cottage();
|
||||
//
|
||||
|
||||
Drone.extend('cottage',function ()
|
||||
{
|
||||
this.chkpt('cottage')
|
||||
.box0(48,7,2,6) // 4 walls
|
||||
.right(3).door() // door front and center
|
||||
.up(1).left(2).box(102) // windows to left and right
|
||||
.right(4).box(102)
|
||||
.left(5).up().prism0(53,7,6);
|
||||
//
|
||||
// put up a sign near door.
|
||||
//
|
||||
this.down().right(4).sign(["Home","Sweet","Home"],68);
|
||||
|
||||
return this.move('cottage');
|
||||
});
|
||||
//
|
||||
// a more complex script that builds an tree-lined avenue with
|
||||
// cottages on both sides.
|
||||
//
|
||||
Drone.extend('cottage_road', function(numberCottages)
|
||||
{
|
||||
if (typeof numberCottages == "undefined"){
|
||||
numberCottages = 6;
|
||||
}
|
||||
var i=0, distanceBetweenTrees = 11;
|
||||
//
|
||||
// step 1 build the road.
|
||||
//
|
||||
var cottagesPerSide = Math.floor(numberCottages/2);
|
||||
this
|
||||
.chkpt("cottage_road") // make sure the drone's state is saved.
|
||||
.box(43,3,1,cottagesPerSide*(distanceBetweenTrees+1)) // build the road
|
||||
.up().right() // now centered in middle of road
|
||||
.chkpt("cr"); // will be returning to this position later
|
||||
|
||||
//
|
||||
// step 2 line the road with trees
|
||||
//
|
||||
for (; i < cottagesPerSide+1;i++){
|
||||
this
|
||||
.left(5).oak()
|
||||
.right(10).oak()
|
||||
.left(5) // return to middle of road
|
||||
.fwd(distanceBetweenTrees+1); // move forward.
|
||||
}
|
||||
this.move("cr").back(6); // move back 1/2 the distance between trees
|
||||
|
||||
// this function builds a path leading to a cottage.
|
||||
function pathAndCottage(d){
|
||||
return d.down().box(43,1,1,5).fwd(5).left(3).up().cottage();
|
||||
};
|
||||
//
|
||||
// step 3 build cottages on each side
|
||||
//
|
||||
for (i = 0;i < cottagesPerSide; i++)
|
||||
{
|
||||
this.fwd(distanceBetweenTrees+1).chkpt("r"+i);
|
||||
// build cottage on left
|
||||
pathAndCottage(this.turn(3)).move("r"+i);
|
||||
// build cottage on right
|
||||
pathAndCottage(this.turn()).move("r"+i);
|
||||
}
|
||||
// return drone to where it was at start of function
|
||||
return this.move("cottage_road");
|
||||
});
|
||||
|
38
src/main/javascript/plugins/drone/contrib/dancefloor.js
Normal file
38
src/main/javascript/plugins/drone/contrib/dancefloor.js
Normal file
|
@ -0,0 +1,38 @@
|
|||
var Drone = require('../drone');
|
||||
module.exports = Drone;
|
||||
//
|
||||
// Create a floor of colored tiles some of which emit light.
|
||||
// The tiles change color every second creating a strobe-lit dance-floor.
|
||||
//
|
||||
// See it in action here => http://www.youtube.com/watch?v=UEooBt6NTFo
|
||||
//
|
||||
Drone.extend('dancefloor',function(width,length)
|
||||
{
|
||||
if (typeof width == "undefined")
|
||||
width = 5;
|
||||
if (typeof length == "undefined")
|
||||
length = width;
|
||||
//
|
||||
// create a separate Drone object to lay down disco tiles
|
||||
//
|
||||
var disco = new Drone(this.x, this.y, this.z, this.dir, this.world);
|
||||
//
|
||||
// under-floor lighting
|
||||
//
|
||||
disco.down().box(89,width,1,length).up();
|
||||
var floorTiles = [35,35,'35:1','35:2','35:3','35:4','35:4','35:4','35:6',20,20];
|
||||
//
|
||||
// strobe gets called in a java thread - disco only lasts 30 seconds.
|
||||
//
|
||||
var discoTicks = 30;
|
||||
var task = null;
|
||||
var strobe = function() {
|
||||
disco.rand(floorTiles,width,1,length);
|
||||
if (!discoTicks--)
|
||||
task.cancel();
|
||||
};
|
||||
var now = 0;
|
||||
var everySecond = 20;
|
||||
task = server.scheduler.runTaskTimer(__plugin,strobe,now,everySecond);
|
||||
return this;
|
||||
});
|
68
src/main/javascript/plugins/drone/contrib/fort.js
Normal file
68
src/main/javascript/plugins/drone/contrib/fort.js
Normal file
|
@ -0,0 +1,68 @@
|
|||
var Drone = require('../drone');
|
||||
module.exports = Drone;
|
||||
//
|
||||
// constructs a medieval fort
|
||||
//
|
||||
Drone.extend('fort', function(side, height)
|
||||
{
|
||||
if (typeof side == "undefined")
|
||||
side = 18;
|
||||
if (typeof height == "undefined")
|
||||
height = 6;
|
||||
// make sure side is even
|
||||
if (side%2)
|
||||
side++;
|
||||
if (height < 4 || side < 10)
|
||||
throw new java.lang.RuntimeException("Forts must be at least 10 wide X 4 tall");
|
||||
var brick = 98;
|
||||
//
|
||||
// build walls.
|
||||
//
|
||||
this.chkpt('fort').box0(brick,side,height-1,side);
|
||||
//
|
||||
// build battlements
|
||||
//
|
||||
this.up(height-1);
|
||||
for (i = 0;i <= 3;i++){
|
||||
var turret = [];
|
||||
this.box(brick) // solid brick corners
|
||||
.up().box('50:5').down() // light a torch on each corner
|
||||
.fwd();
|
||||
turret.push('109:'+ Drone.PLAYER_STAIRS_FACING[this.dir]);
|
||||
turret.push('109:'+ Drone.PLAYER_STAIRS_FACING[(this.dir+2)%4]);
|
||||
try{
|
||||
this.boxa(turret,1,1,side-2).fwd(side-2).turn();
|
||||
}catch(e){
|
||||
self.sendMessage("ERROR: " + e.toString());
|
||||
}
|
||||
}
|
||||
//
|
||||
// build battlement's floor
|
||||
//
|
||||
this.move('fort');
|
||||
this.up(height-2).fwd().right().box('126:0',side-2,1,side-2);
|
||||
var battlementWidth = 3;
|
||||
if (side <= 12)
|
||||
battlementWidth = 2;
|
||||
|
||||
this.fwd(battlementWidth).right(battlementWidth)
|
||||
.box(0,side-((1+battlementWidth)*2),1,side-((1+battlementWidth)*2));
|
||||
//
|
||||
// add door
|
||||
//
|
||||
var torch = '50:' + Drone.PLAYER_TORCH_FACING[this.dir];
|
||||
this.move('fort').right((side/2)-1).door2() // double doors
|
||||
.back().left().up()
|
||||
.box(torch) // left torch
|
||||
.right(3)
|
||||
.box(torch); // right torch
|
||||
//
|
||||
// add ladder up to battlements
|
||||
//
|
||||
var ladder = '65:' + Drone.PLAYER_SIGN_FACING[(this.dir+2)%4];
|
||||
this.move('fort').right((side/2)-3).fwd(1) // move inside fort
|
||||
.box(ladder, 1,height-1,1);
|
||||
return this.move('fort');
|
||||
|
||||
});
|
||||
|
219
src/main/javascript/plugins/drone/contrib/logo.js
Normal file
219
src/main/javascript/plugins/drone/contrib/logo.js
Normal file
|
@ -0,0 +1,219 @@
|
|||
var Drone = require('../drone');
|
||||
module.exports = Drone;
|
||||
//
|
||||
// Constructs the JS logo
|
||||
// https://raw.github.com/voodootikigod/logo.js/master/js.png
|
||||
//
|
||||
// fg
|
||||
// the material that the letters JS will be made of
|
||||
// bg
|
||||
// the material that the square will be made of
|
||||
//
|
||||
Drone.extend('logojs', function(fg, bg) {
|
||||
|
||||
// foreground defaults to gray wool
|
||||
if (typeof fg == "undefined")
|
||||
fg = '35:7';
|
||||
// background defaults to gold blocks
|
||||
if (typeof bg == "undefined")
|
||||
bg = 41;
|
||||
|
||||
// Draw the sqaure
|
||||
this.chkpt('logojs-start')
|
||||
.up()
|
||||
.box(bg, 100, 100, 1);
|
||||
|
||||
// Draw the J, starting with the hook
|
||||
this.right(30).up(13)
|
||||
.box(fg)
|
||||
.right().down()
|
||||
.box(fg, 1, 3, 1)
|
||||
.right().down()
|
||||
.box(fg, 1, 5, 1)
|
||||
.right().down()
|
||||
.box(fg, 1, 7, 1)
|
||||
.right()
|
||||
.box(fg, 1, 8, 1)
|
||||
.right().down()
|
||||
.box(fg, 1, 10, 1)
|
||||
.right()
|
||||
.box(fg, 1, 9, 1)
|
||||
.right()
|
||||
.box(fg, 1, 8, 1)
|
||||
.right().down()
|
||||
.box(fg, 2, 8, 1)
|
||||
.right(2)
|
||||
.box(fg, 4, 7, 1)
|
||||
.right(4)
|
||||
.box(fg, 1, 8, 1)
|
||||
.right()
|
||||
.box(fg, 1, 9, 1)
|
||||
.right().up()
|
||||
.box(fg, 3, 10, 1)
|
||||
.right(3).up()
|
||||
.box(fg, 2, 9, 1)
|
||||
.right(2).up()
|
||||
.box(fg, 2, 8, 1)
|
||||
.right(2).up()
|
||||
.box(fg, 1, 7, 1)
|
||||
.right().up()
|
||||
.box(fg, 1, 6, 1)
|
||||
.right().up()
|
||||
.box(fg, 1, 5, 1)
|
||||
.right().up(2)
|
||||
.box(fg, 1, 3, 1)
|
||||
.left(9).up(3)
|
||||
.box(fg, 10, 31, 1)
|
||||
|
||||
// Draw the S
|
||||
// It's drawn in three strokes from bottom to top. Look for when
|
||||
// it switches from .right() to .left() then back again
|
||||
|
||||
// move to starting point for S
|
||||
.right(22).down(6)
|
||||
// stroke 1
|
||||
.box(fg)
|
||||
.right().down()
|
||||
.box(fg, 1, 3, 1)
|
||||
.right().down()
|
||||
.box(fg, 1, 5, 1)
|
||||
.right().down()
|
||||
.box(fg, 1, 7, 1)
|
||||
.right()
|
||||
.box(fg, 1, 8, 1)
|
||||
.right().down()
|
||||
.box(fg, 1, 10, 1)
|
||||
.right()
|
||||
.box(fg, 1, 9, 1)
|
||||
.right()
|
||||
.box(fg, 1, 8, 1)
|
||||
.right().down()
|
||||
.box(fg, 2, 8, 1)
|
||||
.right(2)
|
||||
.box(fg, 4, 7, 1)
|
||||
.right(4)
|
||||
.box(fg, 2, 8, 1)
|
||||
.right(2)
|
||||
.box(fg, 1, 9, 1)
|
||||
.right().up()
|
||||
.box(fg, 1, 9, 1)
|
||||
.right()
|
||||
.box(fg, 1, 10, 1)
|
||||
.right()
|
||||
.box(fg, 1, 22, 1)
|
||||
.right().up()
|
||||
.box(fg, 2, 20, 1)
|
||||
.right().up()
|
||||
.box(fg, 1, 18, 1)
|
||||
.right().up()
|
||||
.box(fg, 1, 17, 1)
|
||||
.right().up()
|
||||
.box(fg, 1, 15, 1)
|
||||
.right().up()
|
||||
.box(fg, 1, 13, 1)
|
||||
.right().up(2)
|
||||
.box(fg, 1, 9, 1)
|
||||
.right().up(2)
|
||||
.box(fg, 1, 5, 1)
|
||||
// stroke 2
|
||||
.left(8).up(4)
|
||||
.box(fg, 1, 9, 1)
|
||||
.left().up()
|
||||
.box(fg, 1, 9, 1)
|
||||
.left().up()
|
||||
.box(fg, 1, 8, 1)
|
||||
.left(2).up()
|
||||
.box(fg, 2, 8, 1)
|
||||
.left(2).up()
|
||||
.box(fg, 2, 7, 1)
|
||||
.left(2).up()
|
||||
.box(fg, 2, 7, 1)
|
||||
.left()
|
||||
.box(fg, 1, 8, 1)
|
||||
.left().up()
|
||||
.box(fg, 1, 8, 1)
|
||||
.left()
|
||||
.box(fg, 1, 9, 1)
|
||||
.left(2).up()
|
||||
.box(fg, 2, 19, 1)
|
||||
.left().up()
|
||||
.box(fg, 1, 17, 1)
|
||||
.left()
|
||||
.box(fg, 1, 16, 1)
|
||||
.left().up()
|
||||
.box(fg, 1, 14, 1)
|
||||
.left().up(2)
|
||||
.box(fg, 1, 10, 1)
|
||||
.left().up(2)
|
||||
.box(fg, 1, 6, 1)
|
||||
// stroke 3
|
||||
.right(7).up(6)
|
||||
.box(fg, 1, 8, 1)
|
||||
.right().up()
|
||||
.box(fg, 1, 7, 1)
|
||||
.right().up()
|
||||
.box(fg, 2, 7, 1)
|
||||
.right(2).up()
|
||||
.box(fg, 4, 6, 1)
|
||||
.right(4).down()
|
||||
.box(fg, 2, 7, 1)
|
||||
.right().down()
|
||||
.box(fg, 1, 8, 1)
|
||||
.right()
|
||||
.box(fg, 1, 7, 1)
|
||||
.right().down()
|
||||
.box(fg, 1, 8, 1)
|
||||
.right().down()
|
||||
.box(fg, 1, 9, 1)
|
||||
.right().down()
|
||||
.box(fg, 1, 9, 1)
|
||||
.right().up()
|
||||
.box(fg, 1, 8, 1)
|
||||
.right().up()
|
||||
.box(fg, 1, 6, 1)
|
||||
.right().up()
|
||||
.box(fg, 1, 5, 1)
|
||||
.right().up()
|
||||
.box(fg, 1, 3, 1)
|
||||
.right().up()
|
||||
.box(fg);
|
||||
|
||||
this.move('logojs-start');
|
||||
|
||||
return this;
|
||||
});
|
||||
//
|
||||
// Makes a cube of JS logos!
|
||||
// This is a wrapper for logojs() so look at its docs
|
||||
//
|
||||
// Until the drone can rotate on its Z axis we can't
|
||||
// use logojs() to create top/bottom sides of cube.
|
||||
//
|
||||
Drone.extend('logojscube', function(fg, bg) {
|
||||
|
||||
this.chkpt('jscube-start')
|
||||
.logojs(fg, bg);
|
||||
|
||||
this.move('jscube-start')
|
||||
.right(100)
|
||||
.turn(3)
|
||||
.logojs(fg, bg);
|
||||
|
||||
this.move('jscube-start')
|
||||
.right(100)
|
||||
.turn(3)
|
||||
.right(100)
|
||||
.turn(3)
|
||||
.logojs(fg, bg);
|
||||
|
||||
this.move('jscube-start')
|
||||
.right(100)
|
||||
.turn(3)
|
||||
.right(100)
|
||||
.turn(3)
|
||||
.right(100)
|
||||
.turn(3)
|
||||
.logojs(fg, bg);
|
||||
|
||||
return this;
|
||||
});
|
44
src/main/javascript/plugins/drone/contrib/rainbow.js
Normal file
44
src/main/javascript/plugins/drone/contrib/rainbow.js
Normal file
|
@ -0,0 +1,44 @@
|
|||
var Drone = require('../drone');
|
||||
var blocks = require('../blocks');
|
||||
module.exports = Drone;
|
||||
/************************************************************************
|
||||
Drone.rainbow() method
|
||||
======================
|
||||
Creates a Rainbow.
|
||||
|
||||
Parameters
|
||||
----------
|
||||
|
||||
* radius (optional - default:18) - The radius of the rainbow
|
||||
|
||||
Example
|
||||
-------
|
||||
|
||||
var d = new Drone();
|
||||
d.rainbow(30);
|
||||
|
||||
![rainbow example](img/rainbowex1.png)
|
||||
|
||||
***/
|
||||
Drone.extend('rainbow', function(radius){
|
||||
if (typeof radius == "undefined")
|
||||
radius = 18;
|
||||
|
||||
this.chkpt('rainbow');
|
||||
this.down(radius);
|
||||
// copy blocks.rainbow and add air at end (to compensate for strokewidth)
|
||||
var colors = blocks.rainbow.slice(0);
|
||||
colors.push(blocks.air);
|
||||
for (var i = 0;i < colors.length; i++) {
|
||||
var bm = this._getBlockIdAndMeta(colors[i]);
|
||||
this.arc({
|
||||
blockType: bm[0],
|
||||
meta: bm[1],
|
||||
radius: radius-i,
|
||||
strokeWidth: 2,
|
||||
quadrants: {topright: true,
|
||||
topleft: true},
|
||||
orientation: 'vertical'}).right().up();
|
||||
}
|
||||
return this.move('rainbow');
|
||||
});
|
34
src/main/javascript/plugins/drone/contrib/rboxcall.js
Normal file
34
src/main/javascript/plugins/drone/contrib/rboxcall.js
Normal file
|
@ -0,0 +1,34 @@
|
|||
var Drone = require('../drone');
|
||||
module.exports = Drone;
|
||||
/**
|
||||
* Iterates over each cube in a cubic region. For each cube has a chance to callback your
|
||||
* function and provide a new drone to it.
|
||||
*
|
||||
* Parameters:
|
||||
* callback - any function that accepts a drone as its first argument
|
||||
* probability - chance to invoke your callback on each iteration
|
||||
* width - width of the region
|
||||
* height - (Optional) height of the region, defaults to width
|
||||
* depth - (Optional) depth of the cube, defaults to width
|
||||
*/
|
||||
|
||||
Drone.extend("rboxcall", function(callback, probability, width, height, depth) {
|
||||
this.chkpt('rboxcall-start');
|
||||
|
||||
for(var i = 0; i < width; ++i) {
|
||||
this.move('rboxcall-start').right(i);
|
||||
for(var j = 0; j < depth; ++j) {
|
||||
this.move('rboxcall-start').right(i).fwd(j);
|
||||
for(var k = 0; k < height; ++k) {
|
||||
if(Math.random()*100 < probability) {
|
||||
callback.call(null, new Drone(this.x, this.y, this.z));
|
||||
}
|
||||
this.up();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
this.move('rboxcall-start');
|
||||
|
||||
return this;
|
||||
});
|
108
src/main/javascript/plugins/drone/contrib/redstonewire.js
Normal file
108
src/main/javascript/plugins/drone/contrib/redstonewire.js
Normal file
|
@ -0,0 +1,108 @@
|
|||
var Drone = require('../drone');
|
||||
var blocks = require('../blocks');
|
||||
module.exports = Drone;
|
||||
//
|
||||
// usage:
|
||||
// [1] to place a new block with redstone wire on it (block on bottom, redstone on top)
|
||||
// /js wireblock(blocks.sandstone);
|
||||
//
|
||||
// [2] to drop wire on to an existing block
|
||||
// /js wire()
|
||||
//
|
||||
// [3] to place a (redstone) torch on a new block
|
||||
// /js torchblock(blocks.sandstone)
|
||||
//
|
||||
// [4] to place a repeater on a new block
|
||||
// /js repeaterblock(blocks.sandstone)
|
||||
//
|
||||
// [5] To create a long redstone wire (with necessary repeaters, powererd by a single torch)
|
||||
// /js wirestraight(blocks.sandstone, distance)
|
||||
//
|
||||
// [6] To create a 'road' with redstone torches and wire lining each side
|
||||
// /js redstoneroad(blocks.stone, blocks.sandstone, 25)
|
||||
|
||||
Drone.extend('wireblock',function(blockType)
|
||||
{
|
||||
this.chkpt('wireblock')
|
||||
.box(blockType,1,2,1) // 2 blocks tall, top block will be wire dropped on lower
|
||||
.up();
|
||||
|
||||
this.world.getBlockAt(this.x,this.y,this.z).setTypeId(55); //apply wire
|
||||
|
||||
return this.move('wireblock');
|
||||
});
|
||||
|
||||
Drone.extend('wire',function ()
|
||||
{
|
||||
this.chkpt('wire')
|
||||
.up();
|
||||
|
||||
this.world.getBlockAt(this.x,this.y,this.z).setTypeId(55); // apply wire
|
||||
|
||||
return this.move('wire');
|
||||
});
|
||||
|
||||
Drone.extend('torchblock', function(blockType)
|
||||
{
|
||||
this.box(blockType,1,2,1) // 2 blocks tall
|
||||
.up();
|
||||
|
||||
this.world.getBlockAt(this.x,this.y,this.z).setTypeId(76); // apply torch
|
||||
|
||||
return this.down();
|
||||
});
|
||||
|
||||
Drone.extend('repeaterblock',function(blockType)
|
||||
{
|
||||
this.chkpt('repeaterblock')
|
||||
.box(blockType,1,2,1)
|
||||
.up();
|
||||
|
||||
var block = this.world.getBlockAt(this.x,this.y,this.z);
|
||||
block.setTypeId(94); // apply repeater
|
||||
|
||||
// redstone repeater dirs: north=0,east=1,south=2,west=3
|
||||
var direction = [1,2,3,0][this.dir]; // convert drone dir to repeater dir.
|
||||
block.setData(direction);
|
||||
|
||||
return this.move('repeaterblock');
|
||||
});
|
||||
|
||||
|
||||
Drone.extend('wirestraight',function (blockType,distance)
|
||||
{
|
||||
this.chkpt('wirestraight');
|
||||
|
||||
this.torchblock(blockType);
|
||||
this.fwd();
|
||||
|
||||
for (var i = 1; i < distance; i++) {
|
||||
if(i % 14 == 0)
|
||||
{
|
||||
this.repeaterblock(blockType);
|
||||
}
|
||||
else
|
||||
{
|
||||
this.wireblock(blockType);
|
||||
}
|
||||
|
||||
this.fwd();
|
||||
};
|
||||
|
||||
return this.move('wirestraight');
|
||||
});
|
||||
|
||||
|
||||
Drone.extend('redstoneroad', function (roadBlockType, redstoneunderBlockType, distance)
|
||||
{
|
||||
return this.down()
|
||||
.wirestraight(redstoneunderBlockType, distance)
|
||||
.right()
|
||||
.box(roadBlockType, 4,1,distance)
|
||||
.right(4)
|
||||
.wirestraight(redstoneunderBlockType, distance)
|
||||
.up();
|
||||
});
|
||||
|
||||
|
||||
|
|
@ -0,0 +1,19 @@
|
|||
var Drone = require('../drone');
|
||||
var blocks = require('../blocks');
|
||||
|
||||
module.exports = Drone;
|
||||
Drone.extend('skyscraper',function(floors){
|
||||
|
||||
if (typeof floors == "undefined")
|
||||
floors = 10;
|
||||
this.chkpt('skyscraper');
|
||||
for (var i = 0;i < floors; i++)
|
||||
{
|
||||
this
|
||||
.box(blocks.iron,20,1,20)
|
||||
.up()
|
||||
.box0(blocks.glass_pane,20,3,20)
|
||||
.up(3);
|
||||
}
|
||||
return this.move('skyscraper');
|
||||
});
|
48
src/main/javascript/plugins/drone/contrib/spiral_stairs.js
Normal file
48
src/main/javascript/plugins/drone/contrib/spiral_stairs.js
Normal file
|
@ -0,0 +1,48 @@
|
|||
var Drone = require('../drone');
|
||||
var blocks = require('../blocks');
|
||||
|
||||
module.exports = Drone;
|
||||
/************************************************************************
|
||||
Drone.spiral_stairs() method
|
||||
============================
|
||||
Constructs a spiral staircase with slabs at each corner.
|
||||
|
||||
Parameters
|
||||
----------
|
||||
|
||||
* stairBlock - The block to use for stairs, should be one of the following...
|
||||
- 'oak'
|
||||
- 'spruce'
|
||||
- 'birch'
|
||||
- 'jungle'
|
||||
- 'cobblestone'
|
||||
- 'brick'
|
||||
- 'stone'
|
||||
- 'nether'
|
||||
- 'sandstone'
|
||||
- 'quartz'
|
||||
* flights - The number of flights of stairs to build.
|
||||
|
||||
![Spiral Staircase](img/spiralstair1.png)
|
||||
|
||||
Example
|
||||
-------
|
||||
To construct a spiral staircase 5 floors high made of oak...
|
||||
|
||||
spiral_stairs('oak', 5);
|
||||
|
||||
***/
|
||||
Drone.extend("spiral_stairs",function(stairBlock, flights){
|
||||
this.chkpt('spiral_stairs');
|
||||
|
||||
for (var i = 0; i < flights; i++){
|
||||
this
|
||||
.box(blocks.stairs[stairBlock] + ':' + Drone.PLAYER_STAIRS_FACING[this.dir])
|
||||
.up().fwd()
|
||||
.box(blocks.stairs[stairBlock] + ':' + Drone.PLAYER_STAIRS_FACING[this.dir])
|
||||
.up().fwd()
|
||||
.box(blocks.slab[stairBlock])
|
||||
.turn().fwd();
|
||||
}
|
||||
return this.move('spiral_stairs');
|
||||
});
|
32
src/main/javascript/plugins/drone/contrib/streamer.js
Normal file
32
src/main/javascript/plugins/drone/contrib/streamer.js
Normal file
|
@ -0,0 +1,32 @@
|
|||
var Drone = require('../drone');
|
||||
module.exports = Drone;
|
||||
/**
|
||||
* Creates a stream of blocks in a given direction until it hits something other than air
|
||||
*
|
||||
* Parameters:
|
||||
* block - blockId
|
||||
* dir - "up", "down", "left", "right", "fwd", "back
|
||||
* maxIterations - (Optional) maximum number of cubes to generate, defaults to 1000
|
||||
*/
|
||||
Drone.extend("streamer", function(block, dir, maxIterations) {
|
||||
if (typeof maxIterations == "undefined")
|
||||
maxIterations = 1000;
|
||||
|
||||
var usage = "Usage: streamer({block-type}, {direction: 'up', 'down', 'fwd', 'back', 'left', 'right'}, {maximum-iterations: default 1000})\nE.g.\n" +
|
||||
"streamer(5, 'up', 200)";
|
||||
if (typeof dir == "undefined"){
|
||||
throw new Error(usage);
|
||||
}
|
||||
if (typeof block == "undefined") {
|
||||
throw new Error(usage);
|
||||
}
|
||||
for ( var i = 0; i < maxIterations||1000; ++i ) {
|
||||
this.box(block);
|
||||
this[dir].call(this);
|
||||
var block = this.world.getBlockAt(this.x, this.y, this.z);
|
||||
if ( block.typeId != 0 && block.data != 0) {
|
||||
break
|
||||
}
|
||||
}
|
||||
return this;
|
||||
});
|
25
src/main/javascript/plugins/drone/contrib/temple.js
Normal file
25
src/main/javascript/plugins/drone/contrib/temple.js
Normal file
|
@ -0,0 +1,25 @@
|
|||
var Drone = require('../drone');
|
||||
module.exports = Drone;
|
||||
//
|
||||
// constructs a mayan temple
|
||||
//
|
||||
Drone.extend('temple', function(side) {
|
||||
if (!side) {
|
||||
side = 20;
|
||||
}
|
||||
var stone = '98:1';
|
||||
var stair = '109:' + Drone.PLAYER_STAIRS_FACING[this.dir];
|
||||
|
||||
this.chkpt('temple');
|
||||
|
||||
while (side > 4) {
|
||||
var middle = Math.round((side-2)/2);
|
||||
this.chkpt('corner')
|
||||
.box(stone, side, 1, side)
|
||||
.right(middle).box(stair).right().box(stair)
|
||||
.move('corner').up().fwd().right();
|
||||
side = side - 2;
|
||||
}
|
||||
|
||||
return this.move('temple');
|
||||
});
|
25
src/main/javascript/plugins/drone/drone-exts.js
Normal file
25
src/main/javascript/plugins/drone/drone-exts.js
Normal file
|
@ -0,0 +1,25 @@
|
|||
var Drone = require('./drone');
|
||||
var utils = require('../utils/utils');
|
||||
|
||||
var files = [];
|
||||
|
||||
var filter = function(file,name){
|
||||
name = "" + name;
|
||||
if (name.match(/drone\.js$/))
|
||||
return false;
|
||||
if (name.match(/drone\-exts\.js$/))
|
||||
return false;
|
||||
if (name.match(/\.js$/))
|
||||
return true;
|
||||
if (file.isDirectory())
|
||||
return true;
|
||||
return false;
|
||||
};
|
||||
|
||||
var files = utils.find(__dirname, filter);
|
||||
|
||||
utils.foreach(files, function (file){
|
||||
require(file);
|
||||
});
|
||||
|
||||
module.exports = Drone;
|
6
src/main/javascript/plugins/drone/drone-firework.js
Normal file
6
src/main/javascript/plugins/drone/drone-firework.js
Normal file
|
@ -0,0 +1,6 @@
|
|||
var fireworks = require('fireworks');
|
||||
var Drone = require('./drone').Drone;
|
||||
Drone.extend('firework',function() {
|
||||
fireworks.firework(this.getLocation());
|
||||
});
|
||||
|
1740
src/main/javascript/plugins/drone/drone.js
Normal file
1740
src/main/javascript/plugins/drone/drone.js
Normal file
File diff suppressed because it is too large
Load diff
268
src/main/javascript/plugins/drone/sphere.js
Normal file
268
src/main/javascript/plugins/drone/sphere.js
Normal file
|
@ -0,0 +1,268 @@
|
|||
var Drone = require('./drone');
|
||||
module.exports = Drone;
|
||||
|
||||
/************************************************************************
|
||||
Drone.sphere() method
|
||||
=====================
|
||||
Creates a sphere.
|
||||
|
||||
Parameters
|
||||
----------
|
||||
|
||||
* block - The block the sphere will be made of.
|
||||
* radius - The radius of the sphere.
|
||||
|
||||
Example
|
||||
-------
|
||||
To create a sphere of Iron with a radius of 10 blocks...
|
||||
|
||||
sphere( blocks.iron, 10);
|
||||
|
||||
![sphere example](img/sphereex1.png)
|
||||
|
||||
Spheres are time-consuming to make. You *can* make large spheres (250 radius) but expect the
|
||||
server to be very busy for a couple of minutes while doing so.
|
||||
|
||||
***/
|
||||
Drone.extend('sphere', function(block,radius)
|
||||
{
|
||||
var lastRadius = radius;
|
||||
var slices = [[radius,0]];
|
||||
var diameter = radius*2;
|
||||
var bm = this._getBlockIdAndMeta(block);
|
||||
|
||||
var r2 = radius*radius;
|
||||
for (var i = 0; i <= radius;i++){
|
||||
var newRadius = Math.round(Math.sqrt(r2 - i*i));
|
||||
if (newRadius == lastRadius)
|
||||
slices[slices.length-1][1]++;
|
||||
else
|
||||
slices.push([newRadius,1]);
|
||||
lastRadius = newRadius;
|
||||
}
|
||||
this.chkpt('sphere');
|
||||
//
|
||||
// mid section
|
||||
//
|
||||
this.up(radius - slices[0][1])
|
||||
.cylinder(block,radius,(slices[0][1]*2)-1,{blockType: bm[0],meta: bm[1]})
|
||||
.down(radius-slices[0][1]);
|
||||
|
||||
var yOffset = -1;
|
||||
for (var i = 1; i < slices.length;i++)
|
||||
{
|
||||
yOffset += slices[i-1][1];
|
||||
var sr = slices[i][0];
|
||||
var sh = slices[i][1];
|
||||
var v = radius + yOffset, h = radius-sr;
|
||||
// northern hemisphere
|
||||
this.up(v).fwd(h).right(h)
|
||||
.cylinder(block,sr,sh,{blockType: bm[0],meta: bm[1]})
|
||||
.left(h).back(h).down(v);
|
||||
|
||||
// southern hemisphere
|
||||
v = radius - (yOffset+sh+1);
|
||||
this.up(v).fwd(h).right(h)
|
||||
.cylinder(block,sr,sh,{blockType: bm[0],meta: bm[1]})
|
||||
.left(h).back(h). down(v);
|
||||
}
|
||||
return this.move('sphere');
|
||||
});
|
||||
/************************************************************************
|
||||
Drone.sphere0() method
|
||||
======================
|
||||
Creates an empty sphere.
|
||||
|
||||
Parameters
|
||||
----------
|
||||
|
||||
* block - The block the sphere will be made of.
|
||||
* radius - The radius of the sphere.
|
||||
|
||||
Example
|
||||
-------
|
||||
To create a sphere of Iron with a radius of 10 blocks...
|
||||
|
||||
sphere0( blocks.iron, 10);
|
||||
|
||||
Spheres are time-consuming to make. You *can* make large spheres (250 radius) but expect the
|
||||
server to be very busy for a couple of minutes while doing so.
|
||||
|
||||
***/
|
||||
Drone.extend('sphere0', function(block,radius)
|
||||
{
|
||||
/*
|
||||
this.sphere(block,radius)
|
||||
.fwd().right().up()
|
||||
.sphere(0,radius-1)
|
||||
.back().left().down();
|
||||
|
||||
*/
|
||||
|
||||
var lastRadius = radius;
|
||||
var slices = [[radius,0]];
|
||||
var diameter = radius*2;
|
||||
var bm = this._getBlockIdAndMeta(block);
|
||||
|
||||
var r2 = radius*radius;
|
||||
for (var i = 0; i <= radius;i++){
|
||||
var newRadius = Math.round(Math.sqrt(r2 - i*i));
|
||||
if (newRadius == lastRadius)
|
||||
slices[slices.length-1][1]++;
|
||||
else
|
||||
slices.push([newRadius,1]);
|
||||
lastRadius = newRadius;
|
||||
}
|
||||
this.chkpt('sphere0');
|
||||
//
|
||||
// mid section
|
||||
//
|
||||
//.cylinder(block,radius,(slices[0][1]*2)-1,{blockType: bm[0],meta: bm[1]})
|
||||
this.up(radius - slices[0][1])
|
||||
.arc({blockType: bm[0],
|
||||
meta: bm[1],
|
||||
radius: radius,
|
||||
strokeWidth: 2,
|
||||
stack: (slices[0][1]*2)-1,
|
||||
fill: false
|
||||
})
|
||||
.down(radius-slices[0][1]);
|
||||
|
||||
var yOffset = -1;
|
||||
var len = slices.length;
|
||||
for (var i = 1; i < len;i++)
|
||||
{
|
||||
yOffset += slices[i-1][1];
|
||||
var sr = slices[i][0];
|
||||
var sh = slices[i][1];
|
||||
var v = radius + yOffset, h = radius-sr;
|
||||
// northern hemisphere
|
||||
// .cylinder(block,sr,sh,{blockType: bm[0],meta: bm[1]})
|
||||
this.up(v).fwd(h).right(h)
|
||||
.arc({
|
||||
blockType: bm[0],
|
||||
meta: bm[1],
|
||||
radius: sr,
|
||||
stack: sh,
|
||||
fill: false,
|
||||
strokeWidth: i<len-1?1+(sr-slices[i+1][0]):1
|
||||
})
|
||||
.left(h).back(h).down(v);
|
||||
|
||||
// southern hemisphere
|
||||
v = radius - (yOffset+sh+1);
|
||||
//.cylinder(block,sr,sh,{blockType: bm[0],meta: bm[1]})
|
||||
this.up(v).fwd(h).right(h)
|
||||
.arc({
|
||||
blockType: bm[0],
|
||||
meta: bm[1],
|
||||
radius: sr,
|
||||
stack: sh,
|
||||
fill: false,
|
||||
strokeWidth: i<len-1?1+(sr-slices[i+1][0]):1
|
||||
})
|
||||
.left(h).back(h). down(v);
|
||||
}
|
||||
this.move('sphere0');
|
||||
|
||||
return this;
|
||||
|
||||
});
|
||||
/************************************************************************
|
||||
Drone.hemisphere() method
|
||||
=========================
|
||||
Creates a hemisphere. Hemispheres can be either north or south.
|
||||
|
||||
Parameters
|
||||
----------
|
||||
|
||||
* block - the block the hemisphere will be made of.
|
||||
* radius - the radius of the hemisphere
|
||||
* northSouth - whether the hemisphere is 'north' or 'south'
|
||||
|
||||
Example
|
||||
-------
|
||||
To create a wood 'north' hemisphere with a radius of 7 blocks...
|
||||
|
||||
hemisphere(blocks.oak, 7, 'north');
|
||||
|
||||
![hemisphere example](img/hemisphereex1.png)
|
||||
|
||||
***/
|
||||
Drone.extend('hemisphere', function(block,radius, northSouth){
|
||||
var lastRadius = radius;
|
||||
var slices = [[radius,0]];
|
||||
var diameter = radius*2;
|
||||
var bm = this._getBlockIdAndMeta(block);
|
||||
|
||||
var r2 = radius*radius;
|
||||
for (var i = 0; i <= radius;i++){
|
||||
var newRadius = Math.round(Math.sqrt(r2 - i*i));
|
||||
if (newRadius == lastRadius)
|
||||
slices[slices.length-1][1]++;
|
||||
else
|
||||
slices.push([newRadius,1]);
|
||||
lastRadius = newRadius;
|
||||
}
|
||||
this.chkpt('hsphere');
|
||||
//
|
||||
// mid section
|
||||
//
|
||||
if (northSouth == "north"){
|
||||
this.cylinder(block,radius,slices[0][1],{blockType: bm[0],meta: bm[1]});
|
||||
} else {
|
||||
this.up(radius - slices[0][1])
|
||||
.cylinder(block,radius,slices[0][1],{blockType: bm[0],meta: bm[1]})
|
||||
.down(radius - slices[0][1]);
|
||||
}
|
||||
|
||||
var yOffset = -1;
|
||||
for (var i = 1; i < slices.length;i++)
|
||||
{
|
||||
yOffset += slices[i-1][1];
|
||||
var sr = slices[i][0];
|
||||
var sh = slices[i][1];
|
||||
var v = yOffset, h = radius-sr;
|
||||
if (northSouth == "north") {
|
||||
// northern hemisphere
|
||||
this.up(v).fwd(h).right(h)
|
||||
.cylinder(block,sr,sh,{blockType: bm[0],meta: bm[1]})
|
||||
.left(h).back(h).down(v);
|
||||
}else{
|
||||
// southern hemisphere
|
||||
v = radius - (yOffset+sh+1);
|
||||
this.up(v).fwd(h).right(h)
|
||||
.cylinder(block,sr,sh,{blockType: bm[0],meta: bm[1]})
|
||||
.left(h).back(h). down(v);
|
||||
}
|
||||
}
|
||||
return this.move('hsphere');
|
||||
|
||||
});
|
||||
/************************************************************************
|
||||
Drone.hemisphere0() method
|
||||
=========================
|
||||
Creates a hollow hemisphere. Hemispheres can be either north or south.
|
||||
|
||||
Parameters
|
||||
----------
|
||||
|
||||
* block - the block the hemisphere will be made of.
|
||||
* radius - the radius of the hemisphere
|
||||
* northSouth - whether the hemisphere is 'north' or 'south'
|
||||
|
||||
Example
|
||||
-------
|
||||
To create a glass 'north' hemisphere with a radius of 20 blocks...
|
||||
|
||||
hemisphere0(blocks.glass, 20, 'north');
|
||||
|
||||
![hemisphere example](img/hemisphereex2.png)
|
||||
|
||||
***/
|
||||
Drone.extend('hemisphere0', function(block,radius,northSouth){
|
||||
return this.hemisphere(block,radius,northSouth)
|
||||
.fwd().right().up(northSouth=="north"?0:1)
|
||||
.hemisphere(0,radius-1,northSouth)
|
||||
.back().left().down(northSouth=="north"?0:1);
|
||||
});
|
23
src/main/javascript/plugins/drone/test.js
Normal file
23
src/main/javascript/plugins/drone/test.js
Normal file
|
@ -0,0 +1,23 @@
|
|||
var Drone = require('./drone');
|
||||
|
||||
Drone.prototype.testHorizontalStrokeWidth = function(){
|
||||
this.arc({
|
||||
blockType: 42,
|
||||
meta: 0,
|
||||
radius: 8,
|
||||
orientation: 'horizontal',
|
||||
strokeWidth: 3,
|
||||
quadrants: {topright:true,topleft:true,bottomleft:true,bottomright:true}
|
||||
});
|
||||
};
|
||||
|
||||
Drone.prototype.testVerticalStrokeWidth = function(){
|
||||
this.arc({
|
||||
blockType: 42,
|
||||
meta: 0,
|
||||
radius: 8,
|
||||
orientation: 'vertical',
|
||||
strokeWidth: 3,
|
||||
quadrants: {topright:true,topleft:true,bottomleft:true,bottomright:true}
|
||||
});
|
||||
};
|
12
src/main/javascript/plugins/example-1.js
Normal file
12
src/main/javascript/plugins/example-1.js
Normal file
|
@ -0,0 +1,12 @@
|
|||
/*
|
||||
A simple minecraft plugin.
|
||||
Usage: At the in-game prompt type ...
|
||||
|
||||
/js hello()
|
||||
|
||||
... and a message `Hello {player-name}` will appear (where {player-name} is
|
||||
replaced by your own name).
|
||||
*/
|
||||
exports.hello = function(){
|
||||
echo("Hello " + self.name);
|
||||
};
|
32
src/main/javascript/plugins/signs/examples.js
Normal file
32
src/main/javascript/plugins/signs/examples.js
Normal file
|
@ -0,0 +1,32 @@
|
|||
var signs = require('./menu');
|
||||
//
|
||||
// Usage:
|
||||
//
|
||||
// In game, create a sign , target it and type ...
|
||||
//
|
||||
// /js var signExamples = require('./signs/examples');
|
||||
// /js signExamples.testMenu()
|
||||
//
|
||||
exports.testMenu = signs
|
||||
.menu("Dinner",
|
||||
["Lamb","Pork","Chicken","Duck","Beef"],
|
||||
function(event){
|
||||
event.player.sendMessage("You chose " + event.text);
|
||||
});
|
||||
//
|
||||
// This is an example sign that displays a menu of times of day
|
||||
// interacting with the sign will change the time of day accordingly.
|
||||
//
|
||||
// In game, create a sign , target it and type ...
|
||||
//
|
||||
// /js var signExamples = require('./signs/examples');
|
||||
// /js signExamples.timeOfDay()
|
||||
//
|
||||
exports.timeOfDay = signs
|
||||
.menu("Time",
|
||||
["Dawn","Midday","Dusk","Midnight"],
|
||||
function(event){
|
||||
event.player.location.world.setTime( event.number * 6000 );
|
||||
});
|
||||
|
||||
|
Reference in a new issue