mirror of https://gitee.com/bigwinds/arangodb
remove dysfunctional contrib files (#4976)
This commit is contained in:
parent
65bfeb7054
commit
c03bb12216
|
@ -771,34 +771,6 @@ static void JS_StopOutputPager(
|
|||
TRI_V8_TRY_CATCH_END
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
/// @brief start the invasion
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
static void JS_StartFlux(v8::FunctionCallbackInfo<v8::Value> const& args) {
|
||||
TRI_V8_TRY_CATCH_BEGIN(isolate);
|
||||
v8::HandleScope scope(isolate);
|
||||
|
||||
v8::Local<v8::External> wrap = v8::Local<v8::External>::Cast(args.Data());
|
||||
V8ShellFeature* shell = static_cast<V8ShellFeature*>(wrap->Value());
|
||||
|
||||
linenoiseEnableRawMode();
|
||||
TRI_SetStdinVisibility(false);
|
||||
TRI_DEFER(
|
||||
linenoiseDisableRawMode();
|
||||
TRI_SetStdinVisibility(true););
|
||||
|
||||
|
||||
auto path = FileUtils::buildFilename(shell->startupDirectory(),
|
||||
"contrib/flux/flux.js");
|
||||
|
||||
TRI_ExecuteGlobalJavaScriptFile(isolate, path.c_str(), true);
|
||||
|
||||
TRI_V8_RETURN_UNDEFINED();
|
||||
TRI_V8_TRY_CATCH_END
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
/// @brief normalizes UTF 16 strings
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
@ -959,12 +931,6 @@ void V8ShellFeature::initGlobals() {
|
|||
_isolate, TRI_V8_ASCII_STRING(_isolate, "SYS_STOP_PAGER"),
|
||||
v8::FunctionTemplate::New(_isolate, JS_StopOutputPager, console)
|
||||
->GetFunction());
|
||||
|
||||
v8::Local<v8::Value> shell = v8::External::New(_isolate, this);
|
||||
TRI_AddGlobalVariableVocbase(
|
||||
_isolate, TRI_V8_ASCII_STRING(_isolate, "SYS_START_FLUX"),
|
||||
v8::FunctionTemplate::New(_isolate, JS_StartFlux, shell)
|
||||
->GetFunction());
|
||||
}
|
||||
|
||||
void V8ShellFeature::initMode(ShellFeature::RunMode runMode,
|
||||
|
|
|
@ -6,7 +6,6 @@ install(
|
|||
DIRECTORY
|
||||
${ARANGODB_SOURCE_DIR}/js/common
|
||||
${ARANGODB_SOURCE_DIR}/js/client
|
||||
${ARANGODB_SOURCE_DIR}/js/contrib
|
||||
DESTINATION
|
||||
${CMAKE_INSTALL_DATAROOTDIR_ARANGO}/js
|
||||
FILES_MATCHING
|
||||
|
|
|
@ -1878,10 +1878,5 @@ global.DEFINE_MODULE('internal', (function () {
|
|||
delete global.SYS_TERMINAL_SIZE;
|
||||
}
|
||||
|
||||
if (global.SYS_START_FLUX) {
|
||||
exports.startFlux = global.SYS_START_FLUX;
|
||||
delete global.SYS_START_FLUX;
|
||||
}
|
||||
|
||||
return exports;
|
||||
}()));
|
||||
|
|
|
@ -1,421 +0,0 @@
|
|||
/**
|
||||
* @license
|
||||
* Copyright (c) 2012 Nathan Rajlich <nathan@tootallnate.net>
|
||||
*
|
||||
* (The MIT License)
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated
|
||||
* documentation files (the 'Software'), to deal in the Software without restriction, including without limitation the
|
||||
* rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit
|
||||
* persons to whom the Software is furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT
|
||||
* NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
|
||||
* DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
|
||||
|
||||
/**
|
||||
* References:
|
||||
*
|
||||
* - http://en.wikipedia.org/wiki/ANSI_escape_code
|
||||
* - http://www.termsys.demon.co.uk/vtansi.htm
|
||||
*
|
||||
*/
|
||||
|
||||
/**
|
||||
* Module dependencies.
|
||||
*/
|
||||
|
||||
var prefix = '\x1b[' // For all escape codes
|
||||
, suffix = 'm' // Only for color codes
|
||||
|
||||
/**
|
||||
* The ANSI escape sequences.
|
||||
*/
|
||||
|
||||
var codes = {
|
||||
up: 'A'
|
||||
, down: 'B'
|
||||
, forward: 'C'
|
||||
, back: 'D'
|
||||
, nextLine: 'E'
|
||||
, previousLine: 'F'
|
||||
, horizontalAbsolute: 'G'
|
||||
, eraseData: 'J'
|
||||
, eraseLine: 'K'
|
||||
, scrollUp: 'S'
|
||||
, scrollDown: 'T'
|
||||
, savePosition: 's'
|
||||
, restorePosition: 'u'
|
||||
, queryPosition: '6n'
|
||||
, hide: '?25l'
|
||||
, show: '?25h'
|
||||
}
|
||||
|
||||
/**
|
||||
* Rendering ANSI codes.
|
||||
*/
|
||||
|
||||
var styles = {
|
||||
bold: 1
|
||||
, italic: 3
|
||||
, underline: 4
|
||||
, inverse: 7
|
||||
}
|
||||
|
||||
/**
|
||||
* The negating ANSI code for the rendering modes.
|
||||
*/
|
||||
|
||||
var reset = {
|
||||
bold: 22
|
||||
, italic: 23
|
||||
, underline: 24
|
||||
, inverse: 27
|
||||
}
|
||||
|
||||
/**
|
||||
* The standard, styleable ANSI colors.
|
||||
*/
|
||||
|
||||
var colors = {
|
||||
white: 37
|
||||
, black: 30
|
||||
, blue: 34
|
||||
, cyan: 36
|
||||
, green: 32
|
||||
, magenta: 35
|
||||
, red: 31
|
||||
, yellow: 33
|
||||
, grey: 90
|
||||
, brightBlack: 90
|
||||
, brightRed: 91
|
||||
, brightGreen: 92
|
||||
, brightYellow: 93
|
||||
, brightBlue: 94
|
||||
, brightMagenta: 95
|
||||
, brightCyan: 96
|
||||
, brightWhite: 97
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Creates a Cursor instance based off the given `writable stream` instance.
|
||||
*/
|
||||
|
||||
function ansi (stream, options) {
|
||||
if (stream._ansicursor) {
|
||||
return stream._ansicursor
|
||||
} else {
|
||||
return stream._ansicursor = new Cursor(stream, options)
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* The `Cursor` class.
|
||||
*/
|
||||
|
||||
function Cursor (stream, options) {
|
||||
if (!(this instanceof Cursor)) {
|
||||
return new Cursor(stream, options)
|
||||
}
|
||||
if (typeof stream != 'object' || typeof stream.write != 'function') {
|
||||
throw new Error('a valid Stream instance must be passed in')
|
||||
}
|
||||
|
||||
// the stream to use
|
||||
this.stream = stream
|
||||
|
||||
// when 'enabled' is false then all the functions are no-ops except for write()
|
||||
this.enabled = options && options.enabled
|
||||
if (typeof this.enabled === 'undefined') {
|
||||
this.enabled = stream.isTTY
|
||||
}
|
||||
this.enabled = !!this.enabled
|
||||
|
||||
// then `buffering` is true, then `write()` calls are buffered in
|
||||
// memory until `flush()` is invoked
|
||||
this.buffering = !!(options && options.buffering)
|
||||
this._buffer = []
|
||||
|
||||
// controls the foreground and background colors
|
||||
this.fg = this.foreground = new Colorer(this, 0)
|
||||
this.bg = this.background = new Colorer(this, 10)
|
||||
|
||||
// defaults
|
||||
this.Bold = false
|
||||
this.Italic = false
|
||||
this.Underline = false
|
||||
this.Inverse = false
|
||||
|
||||
// keep track of the number of "newlines" that get encountered
|
||||
this.newlines = 0
|
||||
}
|
||||
exports.Cursor = Cursor
|
||||
|
||||
/**
|
||||
* Helper function that calls `write()` on the underlying Stream.
|
||||
* Returns `this` instead of the write() return value to keep
|
||||
* the chaining going.
|
||||
*/
|
||||
|
||||
Cursor.prototype.write = function (data) {
|
||||
if (this.buffering) {
|
||||
this._buffer.push(arguments)
|
||||
} else {
|
||||
this.stream.write.apply(this.stream, arguments)
|
||||
}
|
||||
return this
|
||||
}
|
||||
|
||||
/**
|
||||
* Buffer `write()` calls into memory.
|
||||
*
|
||||
* @api public
|
||||
*/
|
||||
|
||||
Cursor.prototype.buffer = function () {
|
||||
this.buffering = true
|
||||
return this
|
||||
}
|
||||
|
||||
/**
|
||||
* Write out the in-memory buffer.
|
||||
*
|
||||
* @api public
|
||||
*/
|
||||
|
||||
Cursor.prototype.flush = function () {
|
||||
this.buffering = false
|
||||
var str = this._buffer.map(function (args) {
|
||||
if (args.length != 1) throw new Error('unexpected args length! ' + args.length);
|
||||
return args[0];
|
||||
}).join('');
|
||||
this._buffer.splice(0); // empty
|
||||
this.write(str);
|
||||
return this
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* The `Colorer` class manages both the background and foreground colors.
|
||||
*/
|
||||
|
||||
function Colorer (cursor, base) {
|
||||
this.current = null
|
||||
this.cursor = cursor
|
||||
this.base = base
|
||||
}
|
||||
exports.Colorer = Colorer
|
||||
|
||||
/**
|
||||
* Write an ANSI color code, ensuring that the same code doesn't get rewritten.
|
||||
*/
|
||||
|
||||
Colorer.prototype._setColorCode = function setColorCode (code) {
|
||||
var c = String(code)
|
||||
if (this.current === c) return
|
||||
this.cursor.enabled && this.cursor.write(prefix + c + suffix)
|
||||
this.current = c
|
||||
return this
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Set up the positional ANSI codes.
|
||||
*/
|
||||
|
||||
Object.keys(codes).forEach(function (name) {
|
||||
var code = String(codes[name])
|
||||
Cursor.prototype[name] = function () {
|
||||
var c = code
|
||||
if (arguments.length > 0) {
|
||||
c = toArray(arguments).map(Math.round).join(';') + code
|
||||
}
|
||||
this.enabled && this.write(prefix + c)
|
||||
return this
|
||||
}
|
||||
})
|
||||
|
||||
/**
|
||||
* Set up the functions for the rendering ANSI codes.
|
||||
*/
|
||||
|
||||
Object.keys(styles).forEach(function (style) {
|
||||
var name = style[0].toUpperCase() + style.substring(1)
|
||||
, c = styles[style]
|
||||
, r = reset[style]
|
||||
|
||||
Cursor.prototype[style] = function () {
|
||||
if (this[name]) return this
|
||||
this.enabled && this.write(prefix + c + suffix)
|
||||
this[name] = true
|
||||
return this
|
||||
}
|
||||
|
||||
Cursor.prototype['reset' + name] = function () {
|
||||
if (!this[name]) return this
|
||||
this.enabled && this.write(prefix + r + suffix)
|
||||
this[name] = false
|
||||
return this
|
||||
}
|
||||
})
|
||||
|
||||
/**
|
||||
* Setup the functions for the standard colors.
|
||||
*/
|
||||
|
||||
Object.keys(colors).forEach(function (color) {
|
||||
var code = colors[color]
|
||||
|
||||
Colorer.prototype[color] = function () {
|
||||
this._setColorCode(this.base + code)
|
||||
return this.cursor
|
||||
}
|
||||
|
||||
Cursor.prototype[color] = function () {
|
||||
return this.foreground[color]()
|
||||
}
|
||||
})
|
||||
|
||||
/**
|
||||
* Makes a beep sound!
|
||||
*/
|
||||
|
||||
Cursor.prototype.beep = function () {
|
||||
this.enabled && this.write('\x07')
|
||||
return this
|
||||
}
|
||||
|
||||
/**
|
||||
* Moves cursor to specific position
|
||||
*/
|
||||
|
||||
Cursor.prototype.goto = function (x, y) {
|
||||
x = x | 0
|
||||
y = y | 0
|
||||
this.enabled && this.write(prefix + y + ';' + x + 'H')
|
||||
return this
|
||||
}
|
||||
|
||||
/**
|
||||
* Resets the color.
|
||||
*/
|
||||
|
||||
Colorer.prototype.reset = function () {
|
||||
this._setColorCode(this.base + 39)
|
||||
return this.cursor
|
||||
}
|
||||
|
||||
/**
|
||||
* Resets all ANSI formatting on the stream.
|
||||
*/
|
||||
|
||||
Cursor.prototype.reset = function () {
|
||||
this.enabled && this.write(prefix + '0' + suffix)
|
||||
this.Bold = false
|
||||
this.Italic = false
|
||||
this.Underline = false
|
||||
this.Inverse = false
|
||||
this.foreground.current = null
|
||||
this.background.current = null
|
||||
return this
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the foreground color with the given RGB values.
|
||||
* The closest match out of the 216 colors is picked.
|
||||
*/
|
||||
|
||||
Colorer.prototype.rgb = function (r, g, b) {
|
||||
var base = this.base + 38
|
||||
, code = rgb(r, g, b)
|
||||
this._setColorCode(base + ';5;' + code)
|
||||
return this.cursor
|
||||
}
|
||||
|
||||
/**
|
||||
* Same as `cursor.fg.rgb(r, g, b)`.
|
||||
*/
|
||||
|
||||
Cursor.prototype.rgb = function (r, g, b) {
|
||||
return this.foreground.rgb(r, g, b)
|
||||
}
|
||||
|
||||
/**
|
||||
* Accepts CSS color codes for use with ANSI escape codes.
|
||||
* For example: `#FF000` would be bright red.
|
||||
*/
|
||||
|
||||
Colorer.prototype.hex = function (color) {
|
||||
return this.rgb.apply(this, hex(color))
|
||||
}
|
||||
|
||||
/**
|
||||
* Same as `cursor.fg.hex(color)`.
|
||||
*/
|
||||
|
||||
Cursor.prototype.hex = function (color) {
|
||||
return this.foreground.hex(color)
|
||||
}
|
||||
|
||||
|
||||
// UTIL FUNCTIONS //
|
||||
|
||||
/**
|
||||
* Translates a 255 RGB value to a 0-5 ANSI RGV value,
|
||||
* then returns the single ANSI color code to use.
|
||||
*/
|
||||
|
||||
function rgb (r, g, b) {
|
||||
var red = r / 255 * 5
|
||||
, green = g / 255 * 5
|
||||
, blue = b / 255 * 5
|
||||
return rgb5(red, green, blue)
|
||||
}
|
||||
|
||||
/**
|
||||
* Turns rgb 0-5 values into a single ANSI color code to use.
|
||||
*/
|
||||
|
||||
function rgb5 (r, g, b) {
|
||||
var red = Math.round(r)
|
||||
, green = Math.round(g)
|
||||
, blue = Math.round(b)
|
||||
return 16 + (red*36) + (green*6) + blue
|
||||
}
|
||||
|
||||
/**
|
||||
* Accepts a hex CSS color code string (# is optional) and
|
||||
* translates it into an Array of 3 RGB 0-255 values, which
|
||||
* can then be used with rgb().
|
||||
*/
|
||||
|
||||
function hex (color) {
|
||||
var c = color[0] === '#' ? color.substring(1) : color
|
||||
, r = c.substring(0, 2)
|
||||
, g = c.substring(2, 4)
|
||||
, b = c.substring(4, 6)
|
||||
return [parseInt(r, 16), parseInt(g, 16), parseInt(b, 16)]
|
||||
}
|
||||
|
||||
/**
|
||||
* Turns an array-like object into a real array.
|
||||
*/
|
||||
|
||||
function toArray (a) {
|
||||
var i = 0
|
||||
, l = a.length
|
||||
, rtn = []
|
||||
for (; i<l; i++) {
|
||||
rtn.push(a[i])
|
||||
}
|
||||
return rtn
|
||||
}
|
||||
|
||||
module.exports = exports = ansi
|
|
@ -1,234 +0,0 @@
|
|||
/**
|
||||
* @license
|
||||
* Copyright (c) 2014 Alistair G MacDonald
|
||||
*
|
||||
* (The MIT License)
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated
|
||||
* documentation files (the 'Software'), to deal in the Software without restriction, including without limitation the
|
||||
* rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit
|
||||
* persons to whom the Software is furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT
|
||||
* NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
|
||||
* DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
(function() {
|
||||
|
||||
var internal = require('internal');
|
||||
//const Writable = require('stream').Writable;
|
||||
class StdoutWritable {//extends Writable
|
||||
constructor(options) {
|
||||
// Calls the stream.Writable() constructor
|
||||
//super(options);
|
||||
|
||||
this._type = 'tty';
|
||||
this.isTTY = internal.COLOR_OUTPUT;
|
||||
}
|
||||
|
||||
get rows() {
|
||||
var size = internal.terminalSize();
|
||||
return size[0];
|
||||
}
|
||||
|
||||
get columns() {
|
||||
var size = internal.terminalSize();
|
||||
return size[1];
|
||||
}
|
||||
|
||||
write(chunk, encoding, callback) {
|
||||
internal.output(chunk);
|
||||
if (callback) {callback();}
|
||||
}
|
||||
}
|
||||
|
||||
// Requires
|
||||
var ansi = require('./ansi')
|
||||
, stdo = new StdoutWritable()
|
||||
, cursor = ansi(stdo)
|
||||
, cols = stdo.columns
|
||||
, rows = stdo.rows
|
||||
, defaultChar = ' '
|
||||
|
||||
, PI2 = Math.PI*2
|
||||
|
||||
, color = {
|
||||
fg:{ r: 255, g: 255, b: 255 },
|
||||
bg:{ r: 255, g: 255, b: 255 }
|
||||
}
|
||||
;
|
||||
|
||||
|
||||
|
||||
var axel = {
|
||||
|
||||
// Clears a block
|
||||
scrub: function(x1, y1, w, h){
|
||||
|
||||
// Turn off the color settings while we scrub
|
||||
var oldBrush = this.defaultChar;
|
||||
cursor.reset();
|
||||
this.defaultChar = ' ';
|
||||
|
||||
this.box(x1, y1, w, h);
|
||||
|
||||
// Put the colors back after
|
||||
cursor.fg.rgb(color.fg.r, color.fg.g, color.fg.b);
|
||||
cursor.bg.rgb(color.bg.r, color.bg.g, color.bg.b);
|
||||
this.defaultChar = oldBrush;
|
||||
},
|
||||
|
||||
|
||||
clear:function () {
|
||||
console.log('\033[2J');
|
||||
},
|
||||
|
||||
|
||||
// Changes the foreground character █ default is [space]
|
||||
set brush (character){
|
||||
defaultChar = character || ' ';
|
||||
},
|
||||
|
||||
get brush (){
|
||||
return defaultChar;
|
||||
},
|
||||
|
||||
|
||||
cursorInterface: {
|
||||
on: function () { cursor.show(); },
|
||||
off: function () { cursor.hide(); },
|
||||
|
||||
// Resets background & foreground colors
|
||||
reset: function () { cursor.reset(); },
|
||||
|
||||
// Restores colors and places cursor after the graphics
|
||||
// so that the drawing does not get drawn over when the
|
||||
// program ends
|
||||
restore: function () {
|
||||
cursor.reset();
|
||||
cursor.goto(axel.cols, axel.rows-1);
|
||||
}
|
||||
},
|
||||
|
||||
|
||||
get cursor() {
|
||||
return this.cursorInterface;
|
||||
},
|
||||
|
||||
get rows (){
|
||||
return stdo.rows;
|
||||
},
|
||||
|
||||
get cols (){
|
||||
return stdo.columns;
|
||||
},
|
||||
|
||||
goto: function(x, y){
|
||||
cursor.goto(parseInt(x), parseInt(y));
|
||||
},
|
||||
|
||||
point: function (x, y, char){
|
||||
if(!(
|
||||
x < 0 || y < 0 ||
|
||||
x > stdo.columns || y > stdo.rows ||
|
||||
x < 0 || y < 0 ||
|
||||
x > stdo.columns || y > stdo.rows
|
||||
)){
|
||||
cursor.goto(parseInt(x), parseInt(y)).write(char || defaultChar);
|
||||
}
|
||||
},
|
||||
|
||||
|
||||
// Get in interpolation point between two points at a given magnitude
|
||||
lerp: function (p1, p2, m) {
|
||||
return ((p2 - p1) * m) + p1;
|
||||
},
|
||||
|
||||
|
||||
circ: function (x, y, m) {
|
||||
var res = m*PI2
|
||||
, i
|
||||
;
|
||||
|
||||
for(i=0; i< res; i+=1){
|
||||
var loc = PI2/res * i;
|
||||
this.point(x+Math.sin(loc)*m,y+Math.cos(loc)*m/2);
|
||||
}
|
||||
},
|
||||
|
||||
|
||||
box: function (x1, y1, w, h) {
|
||||
var line = ''
|
||||
, x
|
||||
, y
|
||||
;
|
||||
|
||||
for (x=0; x< w; x+=1) {
|
||||
line+=this.brush;
|
||||
}
|
||||
|
||||
for (y=0; y< h; y+=1) {
|
||||
cursor.goto(x1,y1+y).write(line);
|
||||
}
|
||||
},
|
||||
|
||||
|
||||
// Get the distance between two points
|
||||
dist: function (x1, y1, x2, y2){
|
||||
return Math.sqrt(Math.pow(x2-x1,2) + Math.pow(y2-y1,2));
|
||||
},
|
||||
|
||||
|
||||
// Get all the points along a line and draw them
|
||||
line: function (x1, y1, x2, y2) {
|
||||
var D = this.dist(x1, y1, x2, y2)+1;
|
||||
|
||||
// this.point(x1, y1);
|
||||
for(var i=0; i< D; i++){
|
||||
var m = 1 / D * i
|
||||
, x = this.lerp(x1, x2, m)
|
||||
, y = this.lerp(y1, y2, m)
|
||||
;
|
||||
this.point(x, y);
|
||||
}
|
||||
// this.point(x2, y2);
|
||||
},
|
||||
|
||||
color: function (hex, g, b, a) {
|
||||
// if
|
||||
},
|
||||
|
||||
text: function(x, y, text){
|
||||
cursor.goto(x,y).write(text);
|
||||
},
|
||||
|
||||
|
||||
// moveTo: function (x, y) {
|
||||
// cursor.moveTo()
|
||||
// },
|
||||
|
||||
|
||||
// Changes foreground color
|
||||
fg: function (r, g, b) {
|
||||
cursor.fg.rgb(r,g,b);
|
||||
},
|
||||
|
||||
// Changes background color
|
||||
bg: function (r, g, b) {
|
||||
cursor.bg.rgb(r,g,b);
|
||||
},
|
||||
|
||||
draw: function(cb){
|
||||
with(this){
|
||||
cb();
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
module.exports = axel;
|
||||
|
||||
}());
|
|
@ -1,315 +0,0 @@
|
|||
'use strict';
|
||||
|
||||
/**
|
||||
* @license
|
||||
* Copyright (c) 2014 Alistair G MacDonald
|
||||
*
|
||||
* (The MIT License)
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated
|
||||
* documentation files (the 'Software'), to deal in the Software without restriction, including without limitation the
|
||||
* rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit
|
||||
* persons to whom the Software is furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT
|
||||
* NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
|
||||
* DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
|
||||
//Requires
|
||||
var c = require('js/contrib/flux/axel')
|
||||
, internal = require('internal')
|
||||
, int = parseInt
|
||||
, sin = Math.sin
|
||||
// , cos = Math.cos
|
||||
// , floor = Math.floor
|
||||
// , ceil = Math.ceil
|
||||
// , pow = Math.pow
|
||||
, score = 0
|
||||
, bullets = []
|
||||
, maxBullets = 20
|
||||
, bulletSpeed = 0.425
|
||||
, width = c.cols
|
||||
, height = c.rows
|
||||
, p1x = c.cols/2
|
||||
, p1y = c.rows-2
|
||||
, lp1x = p1x
|
||||
, lp1y = p1y
|
||||
, interval = 20
|
||||
, isEnabled = true
|
||||
, tick =0
|
||||
, enemies = []
|
||||
, maxEnemies = 24
|
||||
, enemySpeed = 0.025
|
||||
;
|
||||
|
||||
// var theBrush = '█';
|
||||
var theBrush = ' ';
|
||||
|
||||
genEnemies();
|
||||
function genEnemies(){
|
||||
for (var y=0; y< c.rows; y+=3){
|
||||
for (var x=0; x< c.cols*0.75; x+=4){
|
||||
enemies.push({
|
||||
x: 2+x,
|
||||
y: y
|
||||
});
|
||||
if (enemies.length>=maxEnemies) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
function shoot(){
|
||||
var newBullet = {
|
||||
x: p1x,
|
||||
y: p1y-3,
|
||||
speed: bulletSpeed
|
||||
};
|
||||
|
||||
bullets.push(newBullet);
|
||||
|
||||
if(bullets.length>maxBullets){
|
||||
bullets.shift();
|
||||
}
|
||||
}
|
||||
|
||||
function updateBullets(){
|
||||
bullets.forEach(function(bullet){
|
||||
|
||||
// Set last positions
|
||||
bullet.lx = bullet.x;
|
||||
bullet.ly = bullet.y;
|
||||
|
||||
// Move and accelarate
|
||||
bullet.y-=bullet.speed;
|
||||
bullet.speed+=bullet.speed*0.025;
|
||||
|
||||
|
||||
|
||||
if( int(bullet.x)!==int(bullet.lx) ||
|
||||
int(bullet.y)!==int(bullet.ly))
|
||||
{
|
||||
// Draw off
|
||||
c.cursor.reset();
|
||||
c.brush = ' ';
|
||||
c.point(bullet.lx, bullet.ly);
|
||||
|
||||
// Draw on
|
||||
c.brush = theBrush;
|
||||
c.bg(0,255,0);
|
||||
c.point(bullet.x, bullet.y);
|
||||
}
|
||||
|
||||
function destroyBullet(){
|
||||
c.cursor.reset();
|
||||
c.brush = ' ';
|
||||
c.point(bullet.x, bullet.y);
|
||||
bullets.shift();
|
||||
return;
|
||||
}
|
||||
|
||||
enemies.forEach(function(enemy,i){
|
||||
var D = c.dist(enemy.x, enemy.y, bullet.x, bullet.y);
|
||||
if(D<5){
|
||||
genExplosion(enemy.x,enemy.y);
|
||||
destroyBullet();
|
||||
enemies.splice(i,1);
|
||||
updateScore(12.34*bullet.speed);
|
||||
}
|
||||
});
|
||||
|
||||
if(bullet.y<1){
|
||||
destroyBullet();
|
||||
}
|
||||
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
var explosions = [];
|
||||
function genExplosion(x,y){
|
||||
explosions.push({
|
||||
x:x,
|
||||
y:y,
|
||||
size:0,
|
||||
lsize:0,
|
||||
rate: 1,
|
||||
max: 5
|
||||
});
|
||||
}
|
||||
function updateExplosions(){
|
||||
explosions.forEach(function(exp){
|
||||
exp.lsize = exp.size;
|
||||
|
||||
c.cursor.reset();
|
||||
c.brush = ' ';
|
||||
c.circ(exp.x, exp.y, exp.lsize);
|
||||
|
||||
c.bg(255,128,0);
|
||||
c.brush = theBrush;
|
||||
c.circ(exp.x, exp.y, exp.size);
|
||||
|
||||
exp.size+=exp.rate;
|
||||
if(exp.size>exp.max){
|
||||
c.cursor.reset();
|
||||
c.circ(exp.x, exp.y, exp.lsize);
|
||||
explosions.shift();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
function updateEnemies(){
|
||||
enemies.forEach(function(enemy){
|
||||
enemy.ly = enemy.y;
|
||||
enemy.lx = enemy.x;
|
||||
enemy.y+=enemySpeed;
|
||||
enemy.x=enemy.x+(sin(tick/10)/1.5);
|
||||
|
||||
// Only draw enemies again if they have moved
|
||||
if(int(enemy.y)!==int(enemy.ly) ||
|
||||
int(enemy.x)!==int(enemy.lx))
|
||||
{
|
||||
c.cursor.reset();
|
||||
c.brush = ' ';
|
||||
drawEnemy(int(enemy.lx), int(enemy.ly));
|
||||
|
||||
c.bg(255,0,0);
|
||||
c.brush = theBrush;
|
||||
drawEnemy(int(enemy.x), int(enemy.y));
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
function updateScore(add){
|
||||
score+=add;
|
||||
c.cursor.reset();
|
||||
c.fg(255,255,255);
|
||||
c.text(0, c.rows, "Score: "+ int(score));
|
||||
}
|
||||
|
||||
function drawPlayer(x, y){
|
||||
c.brush = theBrush;
|
||||
c.bg(0,255,0);
|
||||
c.line(x-2, y, x+2, y);
|
||||
c.line(x, y, x, y-3);
|
||||
c.line(x-2, y, x-2, y-2);
|
||||
c.line(x+2, y, x+2, y-2);
|
||||
}
|
||||
|
||||
function erasePlayer(x, y){
|
||||
c.brush = ' ';
|
||||
c.cursor.reset();
|
||||
c.line(x-2, y, x+2, y);
|
||||
c.line(x, y, x, y-3);
|
||||
c.line(x-2, y, x-2, y-2);
|
||||
c.line(x+2, y, x+2, y-2);
|
||||
}
|
||||
|
||||
function drawEnemy(x,y){
|
||||
c.line(x-1, y, x+1, y);
|
||||
c.line(x-1, y, x-1, y+2);
|
||||
c.line(x+1, y, x+1, y+2);
|
||||
}
|
||||
|
||||
|
||||
function eachLoop(){
|
||||
tick+=1;
|
||||
|
||||
width = c.cols;
|
||||
height = c.rows;
|
||||
|
||||
pollKeyboard();
|
||||
|
||||
updateBullets();
|
||||
updateEnemies();
|
||||
updateExplosions();
|
||||
checkKeyDown();
|
||||
|
||||
erasePlayer(lp1x,lp1y);
|
||||
drawPlayer(p1x,p1y);
|
||||
}
|
||||
|
||||
|
||||
function endGame(){
|
||||
isEnabled = false;
|
||||
c.cursor.on();
|
||||
c.cursor.restore();
|
||||
internal.print(" Good Bye!");
|
||||
}
|
||||
|
||||
|
||||
function start(){
|
||||
c.cursor.off();
|
||||
c.clear();
|
||||
c.scrub(1, 1, c.cols, c.rows);
|
||||
while (isEnabled) {
|
||||
eachLoop();
|
||||
internal.sleep(1 / 45);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
start();
|
||||
|
||||
|
||||
function left(){
|
||||
lp1x = p1x;
|
||||
p1x-=p1x>4?1:0;
|
||||
}
|
||||
function right(){
|
||||
lp1x = p1x;
|
||||
p1x+=p1x<width-4?1:0;
|
||||
}
|
||||
|
||||
|
||||
//// KEYBOARD EVENTS ///////////////////////////////////////////////////////
|
||||
|
||||
|
||||
var keyDown = null;
|
||||
var lastChecked = now();
|
||||
var releaseTime = 25;
|
||||
|
||||
function now(){
|
||||
return (+new Date());
|
||||
};
|
||||
|
||||
|
||||
var dir;
|
||||
function checkKeyDown(){
|
||||
// if (now()-lastChecked>30){
|
||||
// keyDown =null;
|
||||
// }
|
||||
|
||||
switch(dir){
|
||||
case 'left':
|
||||
left();
|
||||
break;
|
||||
case 'right':
|
||||
right();
|
||||
break;
|
||||
}
|
||||
|
||||
lastChecked = now();
|
||||
}
|
||||
|
||||
function pollKeyboard() {
|
||||
var code = internal.pollStdin();
|
||||
|
||||
if (code) {
|
||||
if (code == 27) endGame();// esc
|
||||
if (code == 3) endGame();// esc
|
||||
if (code == 113 || code == 81) endGame();// q
|
||||
if (code == 97 || code == 65 || code == 37) dir = 'left';// a
|
||||
if (code == 100 || code == 68 || code == 39) dir = 'right';// d
|
||||
if (code == 32 || code == 119 || code == 38) shoot();// w / space
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue