From b0e4b99528bb2b53efb7502823bfee6fc4562636 Mon Sep 17 00:00:00 2001 From: Paul Liverman III Date: Sat, 8 Apr 2017 13:44:31 -0700 Subject: [PATCH] improvements and changes for SCP-Clicker and in general --- docs/classes/element.html | 73 +++++++++++++++++- docs/classes/window.html | 151 ++++++++++++++++++++++++++++++++++++++ docs/index.html | 7 +- docs/modules/Element.html | 3 +- docs/modules/main.html | 36 ++++++++- docs/modules/pop.html | 41 +++++++---- docs/modules/util.html | 3 +- elements/element.lua | 11 +++ elements/element.moon | 7 ++ elements/text.lua | 16 +++- elements/text.moon | 10 ++- init.lua | 59 +++++++++++---- init.moon | 78 ++++++++++++++------ lib/inspect.lua | 1 - 14 files changed, 428 insertions(+), 68 deletions(-) create mode 100644 docs/classes/window.html delete mode 160000 lib/inspect.lua diff --git a/docs/classes/element.html b/docs/classes/element.html index 080462d..d783c9b 100644 --- a/docs/classes/element.html +++ b/docs/classes/element.html @@ -32,6 +32,7 @@

Contents

@@ -39,6 +40,7 @@

Classes

Modules

+

Issues

+ + + + + +
element.debugDraw-todo7doc me

Methods

@@ -98,12 +107,34 @@ + + + +
element.getHeight (self) Returns an element's height.
element.move (self, x, y)Moves an element by specified x/y.


+

Issues

+ +
+
+ + element.debugDraw-todo7 +
+
+ doc me + + + + + + + +
+

Methods

@@ -169,7 +200,7 @@ element.setSize (w, h)
- Sets an element's width/height. + Sets an element's width/height. Fixes alignment if needed.

Parameters:

@@ -335,6 +366,44 @@ +
+
+ + element.move (self, x, y) +
+
+ Moves an element by specified x/y. + + +

Parameters:

+
    +
  • self + + + +
  • +
  • x + + + +
  • +
  • y + + + +
  • +
+ +

Returns:

+
    + + element + self +
+ + + +
@@ -343,7 +412,7 @@
generated by LDoc 1.4.3 -Last updated 2016-10-30 23:39:49 +Last updated 2017-04-08 13:43:44
diff --git a/docs/classes/window.html b/docs/classes/window.html new file mode 100644 index 0000000..4b20f86 --- /dev/null +++ b/docs/classes/window.html @@ -0,0 +1,151 @@ + + + + + Documentation + + + + +
+ +
+ +
+
+
+ + +
+ + + + + + +
+ +

Class window

+

A generic window element.

+

Built-in support for minimize, maximize, and close + buttons, as well as drag-to-resize and drag-to-move. Title bar customizable.

+

Info:

+
    +
  • Copyright: Paul Liverman III (2016)
  • +
  • License: The MIT License (MIT)
  • +
+ + +

Issues

+ + + + + +
window.new-todo8if data, do stuff about it
+

Methods

+ + + + + +
window.new (self, @, @)Constructor expects nothing, or a data table describing it.
+ +
+
+ + +

Issues

+ +
+
+ + window.new-todo8 +
+
+ if data, do stuff about it + + + + + + + +
+
+

Methods

+ +
+
+ + window.new (self, @, @) +
+
+ Constructor expects nothing, or a data table describing it. + + +

Parameters:

+
    +
  • self + + + +
  • +
  • @ + + + +
  • +
  • @ + + + +
  • +
+ + + + + +
+
+ + +
+
+
+generated by LDoc 1.4.3 +Last updated 2017-04-08 13:43:44 +
+
+ + diff --git a/docs/index.html b/docs/index.html index c83d07a..7085441 100644 --- a/docs/index.html +++ b/docs/index.html @@ -39,6 +39,7 @@

Classes

@@ -73,13 +74,17 @@ element A generic element every element must inherit from. + + window + A generic window element. +
generated by LDoc 1.4.3 -Last updated 2016-10-30 23:39:49 +Last updated 2017-04-08 13:43:44
diff --git a/docs/modules/Element.html b/docs/modules/Element.html index e0dde20..bbb56ed 100644 --- a/docs/modules/Element.html +++ b/docs/modules/Element.html @@ -48,6 +48,7 @@

Classes

@@ -490,7 +491,7 @@
generated by LDoc 1.4.3 -Last updated 2016-10-30 23:39:49 +Last updated 2017-04-08 13:43:44
diff --git a/docs/modules/main.html b/docs/modules/main.html index 7d4e2a6..f2de0a9 100644 --- a/docs/modules/main.html +++ b/docs/modules/main.html @@ -30,6 +30,10 @@
  • Index
  • +

    Contents

    +

    Modules

    @@ -42,6 +46,7 @@

    Classes

    @@ -60,18 +65,47 @@ +

    Functions

    + + + + + +
    love.draw () + +


    +

    Functions

    + +
    +
    + + love.draw () +
    +
    + + + + + + + + + + +
    +
    generated by LDoc 1.4.3 -Last updated 2016-10-30 23:39:49 +Last updated 2017-04-08 13:43:44
    diff --git a/docs/modules/pop.html b/docs/modules/pop.html index a51b943..1ca6652 100644 --- a/docs/modules/pop.html +++ b/docs/modules/pop.html @@ -48,6 +48,7 @@

    Classes

    @@ -70,8 +71,8 @@

    Functions

    - - + + @@ -149,11 +150,11 @@ table.insert element.parent, element.parent\removeChild(element), - + - + @@ -170,22 +171,31 @@ table.insert element.parent, element.parent\removeChild(element),
    - load () + load (The)
    - Loads elements, skins, extensions, and initializes pop.screen.

    + Loads elements, skins, extensions from a specified path. Initializes + pop.screen on first call.

    -

    IMPORTANT: Intended to only be called once, and is automatically called - when you require Pop.Box. +

    Automatically called when you require Pop.Box for its internals. Subsequent + calls can be used to add more elements/skins/extensions. +

    Parameters:

    +
      +
    • The + string[opt] + path to load from. Within this path should be + elements, skins, and extensions directories, containing whatever items you + want to load. +
    • +

    See also:

    @@ -566,6 +576,11 @@ table.insert element.parent, element.parent\removeChild(element),

    Fields:

      +
    • For + constants + now, just stores values to be used with mouse clicks + for compatibility with differing LOVE versions. +
    • elements table All GUI classes are stored here. @@ -657,7 +672,7 @@ table.insert element.parent, element.parent\removeChild(element), textinput-todo4
      - doc me + document pop.import @@ -671,7 +686,7 @@ table.insert element.parent, element.parent\removeChild(element), textinput-todo4-todo5
      - doc me + document pop.export @@ -701,7 +716,7 @@ table.insert element.parent, element.parent\removeChild(element),
      generated by LDoc 1.4.3 -Last updated 2016-10-30 23:39:49 +Last updated 2017-04-08 13:43:44
      diff --git a/docs/modules/util.html b/docs/modules/util.html index e072ab5..bf4c965 100644 --- a/docs/modules/util.html +++ b/docs/modules/util.html @@ -46,6 +46,7 @@

      Classes

      @@ -125,7 +126,7 @@
      generated by LDoc 1.4.3 -Last updated 2016-10-30 23:39:49 +Last updated 2017-04-08 13:43:44
      diff --git a/elements/element.lua b/elements/element.lua index ebaeaf3..f11194e 100644 --- a/elements/element.lua +++ b/elements/element.lua @@ -75,6 +75,17 @@ do end, getHeight = function(self) return self.data.h + end, + move = function(self, x, y) + if x == nil then + x = 0 + end + if y == nil then + y = 0 + end + self.data.x = self.data.x + x + self.data.y = self.data.y + y + return self end } _base_0.__index = _base_0 diff --git a/elements/element.moon b/elements/element.moon index 088c1a4..76d156b 100644 --- a/elements/element.moon +++ b/elements/element.moon @@ -116,3 +116,10 @@ class element --- @treturn integer Height. getHeight: => return @data.h + + --- Moves an element by specified x/y. + --- @treturn element self + move: (x=0, y=0) => + @data.x += x + @data.y += y + return @ diff --git a/elements/text.lua b/elements/text.lua index e46e46c..e182bfe 100644 --- a/elements/text.lua +++ b/elements/text.lua @@ -38,9 +38,15 @@ do self.parent, self.data = parent, data _class_0.__parent.__init(self, self.parent, self.data) self.data.type = "text" - self.data.text = text - self.data.fontFile = fontFile - self.data.fontSize = fontSize + if not (self.data.text) then + self.data.text = text + end + if not (self.data.fontFile) then + self.data.fontFile = fontFile + end + if not (self.data.fontSize) then + self.data.fontSize = fontSize + end if not (self.data.color) then self.data.color = { 255, @@ -49,8 +55,10 @@ do 255 } end - if self.data.fontFile then + if "string" == type(self.data.fontFile) then self.font = graphics.newFont(self.data.fontFile, self.data.fontSize) + elseif "number" == type(self.data.fontFile) then + self.font = graphics.newFont(self.data.fontFile) else self.font = graphics.newFont(self.data.fontSize) end diff --git a/elements/text.moon b/elements/text.moon index a96c446..3d0757f 100644 --- a/elements/text.moon +++ b/elements/text.moon @@ -13,13 +13,15 @@ class text extends element super @parent, @data @data.type = "text" - @data.text = text - @data.fontFile = fontFile - @data.fontSize = fontSize + @data.text = text unless @data.text + @data.fontFile = fontFile unless @data.fontFile + @data.fontSize = fontSize unless @data.fontSize @data.color = {255, 255, 255, 255} unless @data.color - if @data.fontFile + if "string" == type @data.fontFile @font = graphics.newFont(@data.fontFile, @data.fontSize) + elseif "number" == type @data.fontFile + @font = graphics.newFont(@data.fontFile) else @font = graphics.newFont(@data.fontSize) diff --git a/init.lua b/init.lua index 9d33935..7ffc430 100644 --- a/init.lua +++ b/init.lua @@ -34,26 +34,51 @@ do local _obj_0 = require(tostring(path) .. "/lib/bitser/bitser") dumps, loads = _obj_0.dumps, _obj_0.loads end +local major, minor, revision = love.getVersion() +if major == 0 and minor == 9 then + pop.constants = { + left_mouse = "l", + middle_mouse = "m", + right_mouse = "r", + button_4 = "x1", + button_5 = "x2", + mouse_wheel_down = "wd", + mouse_wheel_up = "wu" + } +elseif major == 0 and minor == 10 then + pop.constants = { + left_mouse = 1, + middle_mouse = 2, + right_mouse = 3, + button_4 = 4, + button_5 = 5 + } +else + pop.constants = { } +end pop.elements = { } pop.skins = { } pop.extensions = { } pop.screen = false pop.focused = false pop.log = log -pop.load = function() - log("Loading elements from \"" .. tostring(path) .. "/elements\"") - local elements = filesystem.getDirectoryItems(tostring(path) .. "/elements") +pop.load = function(load_path) + if load_path == nil then + load_path = path + end + log("Loading elements from \"" .. tostring(load_path) .. "/elements\"") + local elements = filesystem.getDirectoryItems(tostring(load_path) .. "/elements") for i = 1, #elements do local _continue_0 = false repeat if not (elements[i]:sub(-4) == ".lua") then - log("Ignored non-Lua file \"" .. tostring(path) .. "/elements/" .. tostring(elements[i]) .. "\"") + log("Ignored non-Lua file \"" .. tostring(load_path) .. "/elements/" .. tostring(elements[i]) .. "\"") _continue_0 = true break end local name = elements[i]:sub(1, -5) - log("Requiring \"" .. tostring(name) .. "\" from \"" .. tostring(path) .. "/elements/" .. tostring(name) .. "\"") - pop.elements[name] = require(tostring(path) .. "/elements/" .. tostring(name)) + log("Requiring \"" .. tostring(name) .. "\" from \"" .. tostring(load_path) .. "/elements/" .. tostring(name) .. "\"") + pop.elements[name] = require(tostring(load_path) .. "/elements/" .. tostring(name)) if pop.elements[name].load then pop.elements[name].load(pop) end @@ -74,18 +99,18 @@ pop.load = function() break end end - local skins = filesystem.getDirectoryItems(tostring(path) .. "/skins") + local skins = filesystem.getDirectoryItems(tostring(load_path) .. "/skins") for i = 1, #skins do local _continue_0 = false repeat if not (skins[i]:sub(-4) == ".lua") then - log("Ignored non-Lua file \"" .. tostring(path) .. "/skins/" .. tostring(skins[i]) .. "\"") + log("Ignored non-Lua file \"" .. tostring(load_path) .. "/skins/" .. tostring(skins[i]) .. "\"") _continue_0 = true break end local name = skins[i]:sub(1, -5) - log("Requiring \"" .. tostring(name) .. "\" from \"" .. tostring(path) .. "/skins/" .. tostring(name) .. "\"") - pop.skins[name] = require(tostring(path) .. "/skins/" .. tostring(name)) + log("Requiring \"" .. tostring(name) .. "\" from \"" .. tostring(load_path) .. "/skins/" .. tostring(name) .. "\"") + pop.skins[name] = require(tostring(load_path) .. "/skins/" .. tostring(name)) if pop.skins[name].load then pop.skins[name].load(pop) end @@ -96,18 +121,18 @@ pop.load = function() break end end - local extensions = filesystem.getDirectoryItems(tostring(path) .. "/extensions") + local extensions = filesystem.getDirectoryItems(tostring(load_path) .. "/extensions") for i = 1, #extensions do local _continue_0 = false repeat if not (extensions[i]:sub(-4) == ".lua") then - log("Ignored non-Lua file \"" .. tostring(path) .. "/extensions/" .. tostring(extensions[i]) .. "\"") + log("Ignored non-Lua file \"" .. tostring(load_path) .. "/extensions/" .. tostring(extensions[i]) .. "\"") _continue_0 = true break end local name = extensions[i]:sub(1, -5) - log("Requiring \"" .. tostring(name) .. "\" from \"" .. tostring(path) .. "/extensions/" .. tostring(name) .. "\"") - pop.extensions[name] = require(tostring(path) .. "/extensions/" .. tostring(name)) + log("Requiring \"" .. tostring(name) .. "\" from \"" .. tostring(load_path) .. "/extensions/" .. tostring(name) .. "\"") + pop.extensions[name] = require(tostring(load_path) .. "/extensions/" .. tostring(name)) if pop.extensions[name].load then pop.extensions[name].load(pop) end @@ -118,8 +143,10 @@ pop.load = function() break end end - pop.screen = pop.create("element", false):setSize(graphics.getWidth(), graphics.getHeight()) - return log("Created \"pop.screen\"") + if not (pop.screen) then + pop.screen = pop.create("element", false):setSize(graphics.getWidth(), graphics.getHeight()) + return log("Created \"pop.screen\"") + end end pop.create = function(element, parent, data, ...) if parent == nil then diff --git a/init.moon b/init.moon index 5d8cca2..4a83aeb 100644 --- a/init.moon +++ b/init.moon @@ -33,6 +33,8 @@ import inheritsFromElement from require "#{path}/util" import dumps, loads from require "#{path}/lib/bitser/bitser" --- @table pop +--- @tfield constants For now, just stores values to be used with mouse clicks +--- for compatibility with differing LOVE versions. --- @tfield table elements All GUI classes are stored here. --- @tfield table skins All skins are stored here. --- @tfield table extensions All extensions are loaded here. @@ -43,6 +45,31 @@ import dumps, loads from require "#{path}/lib/bitser/bitser" --- @see pop.load --- @see Element +major, minor, revision = love.getVersion! +if major == 0 and minor == 9 + pop.constants = { + left_mouse: "l" + middle_mouse: "m" + right_mouse: "r" + + button_4: "x1" + button_5: "x2" + + mouse_wheel_down: "wd" + mouse_wheel_up: "wu" + } +elseif major == 0 and minor == 10 + pop.constants = { + left_mouse: 1 + middle_mouse: 2 + right_mouse: 3 + button_4: 4 + button_5: 5 + --no mouse wheel, may lead to problems? + } +else + pop.constants = {} -- this would be an unsupported version currently + pop.elements = {} pop.skins = {} pop.extensions = {} @@ -52,29 +79,31 @@ pop.log = log ---- Loads elements, skins, extensions, and initializes `pop.screen`. +--- Loads elements, skins, extensions from a specified path. Initializes +--- `pop.screen` on first call. --- ---- **IMPORTANT**: Intended to only be called once, and is automatically called ---- when you require Pop.Box. +--- Automatically called when you require Pop.Box for its internals. Subsequent +--- calls can be used to add more elements/skins/extensions. --- @function load ---- @see pop +--- @tparam string[opt] The path to load from. Within this path should be +--- elements, skins, and extensions directories, containing whatever items you +--- want to load. --- @see Element +--- @todo @ see Skins, see Extensions -pop.load = -> - --@todo @ see Skins - --@todo @ see Extensions - log "Loading elements from \"#{path}/elements\"" - elements = filesystem.getDirectoryItems "#{path}/elements" +pop.load = (load_path=path) -> + log "Loading elements from \"#{load_path}/elements\"" + elements = filesystem.getDirectoryItems "#{load_path}/elements" for i = 1, #elements -- ignore non-Lua files unless elements[i]\sub(-4) == ".lua" - log "Ignored non-Lua file \"#{path}/elements/#{elements[i]}\"" + log "Ignored non-Lua file \"#{load_path}/elements/#{elements[i]}\"" continue -- require into pop.elements table by filename name = elements[i]\sub 1, -5 - log "Requiring \"#{name}\" from \"#{path}/elements/#{name}\"" - pop.elements[name] = require "#{path}/elements/#{name}" + log "Requiring \"#{name}\" from \"#{load_path}/elements/#{name}\"" + pop.elements[name] = require "#{load_path}/elements/#{name}" -- call the element's load function if it exists if pop.elements[name].load @@ -93,17 +122,17 @@ pop.load = -> log "Wrapper created: \"pop.#{name}()\"" - skins = filesystem.getDirectoryItems "#{path}/skins" + skins = filesystem.getDirectoryItems "#{load_path}/skins" for i = 1, #skins -- ignore non-Lua files unless skins[i]\sub(-4) == ".lua" - log "Ignored non-Lua file \"#{path}/skins/#{skins[i]}\"" + log "Ignored non-Lua file \"#{load_path}/skins/#{skins[i]}\"" continue -- require into pop.skins table by filename name = skins[i]\sub 1, -5 - log "Requiring \"#{name}\" from \"#{path}/skins/#{name}\"" - pop.skins[name] = require "#{path}/skins/#{name}" + log "Requiring \"#{name}\" from \"#{load_path}/skins/#{name}\"" + pop.skins[name] = require "#{load_path}/skins/#{name}" -- call the skin's load function if it exists if pop.skins[name].load @@ -112,17 +141,17 @@ pop.load = -> log "Skin loaded: \"#{name}\"" - extensions = filesystem.getDirectoryItems "#{path}/extensions" + extensions = filesystem.getDirectoryItems "#{load_path}/extensions" for i = 1, #extensions -- ignore non-Lua files unless extensions[i]\sub(-4) == ".lua" - log "Ignored non-Lua file \"#{path}/extensions/#{extensions[i]}\"" + log "Ignored non-Lua file \"#{load_path}/extensions/#{extensions[i]}\"" continue -- require into pop.extensions by filename name = extensions[i]\sub 1, -5 - log "Requiring \"#{name}\" from \"#{path}/extensions/#{name}\"" - pop.extensions[name] = require "#{path}/extensions/#{name}" + log "Requiring \"#{name}\" from \"#{load_path}/extensions/#{name}\"" + pop.extensions[name] = require "#{load_path}/extensions/#{name}" -- call the extension's load function if it exists if pop.extensions[name].load @@ -132,8 +161,9 @@ pop.load = -> -- Initialize pop.screen (top element, GUI area) - pop.screen = pop.create("element", false)\setSize(graphics.getWidth!, graphics.getHeight!) - log "Created \"pop.screen\"" + unless pop.screen + pop.screen = pop.create("element", false)\setSize(graphics.getWidth!, graphics.getHeight!) + log "Created \"pop.screen\"" @@ -383,7 +413,7 @@ pop.textinput = (text) -> ---- @todo doc me +--- @todo document pop.import pop.import = (data, parent=pop.screen) -> local element @@ -399,7 +429,7 @@ pop.import = (data, parent=pop.screen) -> ---- @todo doc me +--- @todo document pop.export pop.export = (element=pop.screen) -> return dumps(element.data) diff --git a/lib/inspect.lua b/lib/inspect.lua deleted file mode 160000 index a384174..0000000 --- a/lib/inspect.lua +++ /dev/null @@ -1 +0,0 @@ -Subproject commit a384174649e8429cc3270a46cfacc37acaf6e042
    load ()Loads elements, skins, extensions, and initializes pop.screen.load (The)Loads elements, skins, extensions from a specified path.
    create (element, parent, ...)
    textinput-todo4doc medocument pop.import
    textinput-todo4-todo5doc medocument pop.export
    printElementTree-todo6