load drone.js
This commit is contained in:
parent
fa03eb6ccd
commit
a8f0d0bdf9
7 changed files with 159 additions and 152 deletions
|
@ -8,10 +8,10 @@
|
|||
plugin (name, interface, isPersistent)
|
||||
- defines a new plugin. If isPersistent is true then
|
||||
the plugin doesn't have to worry about loading and saving
|
||||
state - that will be done by the framework. Just make sure
|
||||
that anything you want to save (and restore) is in the 'store'
|
||||
property - this will be created automatically if not already defined.
|
||||
(its type is object {} )
|
||||
state - that will be done by the framework. Just make sure
|
||||
that anything you want to save (and restore) is in the 'store'
|
||||
property - this will be created automatically if not already defined.
|
||||
(its type is object {} )
|
||||
|
||||
ready (function) - specifies code to be executed only when all the plugins have loaded.
|
||||
|
||||
|
@ -58,8 +58,8 @@ var verbose = verbose || false;
|
|||
__engine.put("__folder",(parent?_canonize(parent):"")+"/");
|
||||
result = __engine.eval(reader);
|
||||
}else{
|
||||
if (warnOnFileNotFound)
|
||||
__plugin.logger.warning(canonizedFilename + " not found");
|
||||
if (warnOnFileNotFound)
|
||||
__plugin.logger.warning(canonizedFilename + " not found");
|
||||
}
|
||||
return result;
|
||||
};
|
||||
|
@ -104,7 +104,7 @@ var verbose = verbose || false;
|
|||
// as dependencies by myMiniGame.js and do not need to be loaded via js reload
|
||||
//
|
||||
for (var i = 0;i < jsFiles.length; i++){
|
||||
load(_canonize(jsFiles[i]));
|
||||
load(_canonize(jsFiles[i]),true);
|
||||
}
|
||||
};
|
||||
|
||||
|
@ -113,13 +113,13 @@ var verbose = verbose || false;
|
|||
*/
|
||||
var _save = function(object, filename){
|
||||
print(filename);
|
||||
var objectToStr = null;
|
||||
try{
|
||||
objectToStr = JSON.stringify(object);
|
||||
}catch(e){
|
||||
print("ERROR: " + e.getMessage() + " while saving " + filename);
|
||||
return;
|
||||
}
|
||||
var objectToStr = null;
|
||||
try{
|
||||
objectToStr = JSON.stringify(object);
|
||||
}catch(e){
|
||||
print("ERROR: " + e.getMessage() + " while saving " + filename);
|
||||
return;
|
||||
}
|
||||
var f = new java.io.File(filename);
|
||||
var out = new java.io.PrintWriter(new java.io.FileWriter(f));
|
||||
out.println("__data = " + objectToStr);
|
||||
|
@ -154,7 +154,7 @@ var verbose = verbose || false;
|
|||
var _ready = function( func ){
|
||||
_deferred.push(func);
|
||||
};
|
||||
var _cmdInterceptors = [];
|
||||
var _cmdInterceptors = [];
|
||||
/*
|
||||
command management - allow for non-ops to execute approved javascript code.
|
||||
*/
|
||||
|
@ -165,36 +165,36 @@ var verbose = verbose || false;
|
|||
if (__cmdArgs.length === 0)
|
||||
throw new Error("Usage: jsp command-name command-parameters");
|
||||
var name = __cmdArgs[0];
|
||||
var cmd = _commands[name];
|
||||
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]);
|
||||
}
|
||||
// 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 = [];
|
||||
if (typeof options == "undefined")
|
||||
options = [];
|
||||
_commands[name] = {callback: func, options: options};
|
||||
if (intercepts)
|
||||
_cmdInterceptors.push(func);
|
||||
if (intercepts)
|
||||
_cmdInterceptors.push(func);
|
||||
return func;
|
||||
}
|
||||
};
|
||||
var _rmCommand = function(name){
|
||||
delete _commands[name];
|
||||
};
|
||||
var _rmCommand = function(name){
|
||||
delete _commands[name];
|
||||
};
|
||||
/*
|
||||
Tab Completion of the /js and /jsp commands
|
||||
*/
|
||||
|
@ -250,13 +250,13 @@ var verbose = verbose || false;
|
|||
var __onTabCompleteJSP = function() {
|
||||
var result = global.__onTC_result;
|
||||
var args = global.__onTC_args;
|
||||
var cmd = _commands[args[0]];
|
||||
if (cmd)
|
||||
for (var i = 0;i < cmd.options.length; i++)
|
||||
result.add(cmd.options[i]);
|
||||
else
|
||||
for (var i in _commands)
|
||||
result.add(i);
|
||||
var cmd = _commands[args[0]];
|
||||
if (cmd)
|
||||
for (var i = 0;i < cmd.options.length; i++)
|
||||
result.add(cmd.options[i]);
|
||||
else
|
||||
for (var i in _commands)
|
||||
result.add(i);
|
||||
return result;
|
||||
};
|
||||
/*
|
||||
|
@ -343,13 +343,13 @@ var verbose = verbose || false;
|
|||
return JSON.stringify([""+location.world.name,location.x, location.y, location.z]);
|
||||
};
|
||||
|
||||
var _getPlayerObject = function(player){
|
||||
if (typeof player == "undefined")
|
||||
return __self;
|
||||
if (typeof player == "string")
|
||||
return org.bukkit.Bukkit.getPlayer(player);
|
||||
return player;
|
||||
};
|
||||
var _getPlayerObject = function(player){
|
||||
if (typeof player == "undefined")
|
||||
return __self;
|
||||
if (typeof player == "string")
|
||||
return org.bukkit.Bukkit.getPlayer(player);
|
||||
return player;
|
||||
};
|
||||
global.load = _load;
|
||||
global.save = _save;
|
||||
global.reload = _reload;
|
||||
|
@ -358,7 +358,7 @@ var verbose = verbose || false;
|
|||
global.command = _command;
|
||||
global._onTabComplete = __onTabCompleteJS;
|
||||
global.locationToString = _locToString;
|
||||
global.getPlayerObject = _getPlayerObject;
|
||||
global.getPlayerObject = _getPlayerObject;
|
||||
//
|
||||
// assumes this was loaded from js-plugins/core/
|
||||
// load all of the plugins.
|
||||
|
|
|
@ -1,49 +1,50 @@
|
|||
load(__folder + "drone.js");
|
||||
//
|
||||
// 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;
|
||||
//
|
||||
// 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');
|
||||
//
|
||||
// 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');
|
||||
});
|
||||
|
|
|
@ -1,3 +1,4 @@
|
|||
load(__folder + "drone.js");
|
||||
//
|
||||
// need to use the drone module to create buildings easily
|
||||
// it can be done using calls to putBlock(), putSign(), getPlayerPos() and getMousePos()
|
||||
|
|
|
@ -1,3 +1,4 @@
|
|||
load(__folder + "drone.js")
|
||||
//
|
||||
// Create a floor of colored tiles some of which emit light.
|
||||
// The tiles change color every second creating a strobe-lit dance-floor.
|
||||
|
@ -22,11 +23,11 @@ Drone.extend('dancefloor',function(width,length)
|
|||
//
|
||||
// strobe gets called in a java thread - disco only lasts 30 seconds.
|
||||
//
|
||||
var discoTicks = 30;
|
||||
var discoTicks = 30;
|
||||
var strobe = function()
|
||||
{
|
||||
{
|
||||
while(discoTicks--)
|
||||
{
|
||||
{
|
||||
disco.rand(floorTiles,width,1,length);
|
||||
java.lang.Thread.sleep(1000);
|
||||
}
|
||||
|
|
|
@ -1,60 +1,61 @@
|
|||
load(__folder + "drone.js");
|
||||
//
|
||||
// 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]);
|
||||
this.box(turret,1,1,side-2).fwd(side-2).turn();
|
||||
}
|
||||
//
|
||||
// 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;
|
||||
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]);
|
||||
this.box(turret,1,1,side-2).fwd(side-2).turn();
|
||||
}
|
||||
//
|
||||
// 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');
|
||||
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');
|
||||
|
||||
});
|
||||
|
||||
|
|
|
@ -1,3 +1,5 @@
|
|||
load(__folder + "drone.js");
|
||||
|
||||
Drone.extend('sphere', function(block,radius)
|
||||
{
|
||||
var lastRadius = radius;
|
||||
|
|
|
@ -1,3 +1,4 @@
|
|||
load(__folder + "drone.js")
|
||||
//
|
||||
// constructs a mayan temple
|
||||
//
|
||||
|
|
Reference in a new issue