From bbe469d29b5d44a52f7866375a89e70e61ac19c6 Mon Sep 17 00:00:00 2001 From: Devine Lu Linvega <aliceffekt@gmail.com> Date: Tue, 26 Sep 2017 11:00:54 +1300 Subject: [PATCH] Moved scaling stuff into a module --- sources/index.html | 9 +++++---- sources/scripts/hint.js | 8 +++++++- sources/scripts/module.js | 16 ++++++++++++++++ sources/scripts/{ => modules}/brush.js | 9 ++++++++- sources/scripts/{ => modules}/eraser.js | 2 ++ sources/scripts/modules/frame.js | 4 ++++ sources/scripts/ronin.js | 9 ++++++--- 7 files changed, 48 insertions(+), 9 deletions(-) create mode 100644 sources/scripts/module.js rename sources/scripts/{ => modules}/brush.js (81%) rename sources/scripts/{ => modules}/eraser.js (93%) create mode 100644 sources/scripts/modules/frame.js diff --git a/sources/index.html b/sources/index.html index b415981..0b1dad2 100644 --- a/sources/index.html +++ b/sources/index.html @@ -1,17 +1,18 @@ <html> <head> + <script type="text/javascript" src="scripts/module.js"></script> + <script type="text/javascript" src="scripts/modules/frame.js"></script> + <script type="text/javascript" src="scripts/modules/brush.js"></script> + <script type="text/javascript" src="scripts/modules/eraser.js"></script> + <script type="text/javascript" src="scripts/io.js"></script> <script type="text/javascript" src="scripts/query.js"></script> <script type="text/javascript" src="scripts/keyboard.js"></script> <script type="text/javascript" src="scripts/cursor.js"></script> - <script type="text/javascript" src="scripts/brush.js"></script> - <script type="text/javascript" src="scripts/eraser.js"></script> <script type="text/javascript" src="scripts/hint.js"></script> <script type="text/javascript" src="scripts/render.js"></script> <script type="text/javascript" src="scripts/commander.js"></script> <script type="text/javascript" src="scripts/ronin.js"></script> - - <script type="text/javascript" src="scripts/modules/rescale.js"></script> <link rel="stylesheet" type="text/css" href="links/reset.css"/> <link rel="stylesheet" type="text/css" href="links/fonts.css"/> diff --git a/sources/scripts/hint.js b/sources/scripts/hint.js index e1e543f..98ee06c 100644 --- a/sources/scripts/hint.js +++ b/sources/scripts/hint.js @@ -11,7 +11,13 @@ function Hint() this.update = function(e = null) { - this.el.innerHTML = this.pad(ronin.commander.input_el.value)+"brush:"+ronin.brush.settings.size+"&"+ronin.brush.settings.color+""; + var html = "" + + for(module_id in ronin.modules){ + var module = ronin.modules[module_id]; + html += module.hint()+" "; + } + this.el.innerHTML = this.pad(ronin.commander.input_el.value)+html; } this.pad = function(input) diff --git a/sources/scripts/module.js b/sources/scripts/module.js new file mode 100644 index 0000000..40fa335 --- /dev/null +++ b/sources/scripts/module.js @@ -0,0 +1,16 @@ +function Module(name) +{ + this.name = name; + + this.hint = function() + { + var html = ""; + + for(setting_id in this.settings){ + var setting_value = this.settings[setting_id]; + html += setting_id+"="+setting_value+" "; + } + + return this.name+"["+html.trim()+"]"; + } +} \ No newline at end of file diff --git a/sources/scripts/brush.js b/sources/scripts/modules/brush.js similarity index 81% rename from sources/scripts/brush.js rename to sources/scripts/modules/brush.js index b9d6caf..89fb14c 100644 --- a/sources/scripts/brush.js +++ b/sources/scripts/modules/brush.js @@ -1,5 +1,7 @@ function Brush() { + Module.call(this,"brush"); + this.settings = {size:10,color:"#f00"}; this.thickness = function(line) @@ -26,7 +28,12 @@ function Brush() this.mod_size = function(mod) { - this.settings.size += mod; + this.settings.size = clamp(this.settings.size+mod,1,100); + } + + function clamp(v, min, max) + { + return v < min ? min : v > max ? max : v; } function distance_between(a,b) diff --git a/sources/scripts/eraser.js b/sources/scripts/modules/eraser.js similarity index 93% rename from sources/scripts/eraser.js rename to sources/scripts/modules/eraser.js index 32beb91..d78e176 100644 --- a/sources/scripts/eraser.js +++ b/sources/scripts/modules/eraser.js @@ -1,5 +1,7 @@ function Eraser() { + Module.call(this,"eraser"); + this.thickness = function(line) { return ronin.brush.thickness(line); diff --git a/sources/scripts/modules/frame.js b/sources/scripts/modules/frame.js new file mode 100644 index 0000000..5e1ca3d --- /dev/null +++ b/sources/scripts/modules/frame.js @@ -0,0 +1,4 @@ +function Frame() +{ + Module.call(this,"frame"); +} \ No newline at end of file diff --git a/sources/scripts/ronin.js b/sources/scripts/ronin.js index 81bb4aa..672f67f 100644 --- a/sources/scripts/ronin.js +++ b/sources/scripts/ronin.js @@ -8,13 +8,16 @@ function Ronin() this.commander = new Commander(); this.cursor = new Cursor(); this.render = new Render(); - this.brush = new Brush(); - this.eraser = new Eraser(); this.hint = new Hint(); + this.brush = new Brush(); + this.eraser = new Eraser(); + this.frame = new Frame(); + this.modules = { - rescale : new Rescale(), brush : this.brush, + eraser : this.eraser, + frame : this.frame, }; this.install = function()