Quellcode durchsuchen

✨ Add Resource base class

Pedro Schneider vor 3 Jahren
Ursprung
Commit
335a55728d

+ 1 - 0
build

@@ -21,6 +21,7 @@ cat pandora/components/Rect.js >> build.js
 cat pandora/components/Ellipse.js >> build.js
 
 # Package resources
+cat pandora/resources/Resource.js >> build.js
 cat pandora/resources/AudioRes.js >> build.js
 cat pandora/resources/FontRes.js >> build.js
 cat pandora/resources/TextureRes.js >> build.js

Datei-Diff unterdrückt, da er zu groß ist
+ 1 - 1
pandora.min.js


+ 3 - 2
pandora/resources/AudioRes.js

@@ -27,7 +27,7 @@
  * 
  * @class
  */
-class AudioRes
+class AudioRes extends Resource
 {
     /**
      * Initializes an audio resource with the given parameters.
@@ -39,7 +39,8 @@ class AudioRes
      */
     constructor(name = "", p5Audio = null)
     {
-        this.name = name;
+        super(name);
+
         this.P5Audio = p5Audio;
     }
 }

+ 3 - 2
pandora/resources/FontRes.js

@@ -27,7 +27,7 @@
  * 
  * @class
  */
-class FontRes
+class FontRes extends Resource
 {
     /**
      * Initializes a font resource with the given parameters.
@@ -39,7 +39,8 @@ class FontRes
      */
     constructor(name = "", p5Font = null)
     {
-        this.name = name;
+        super(name);
+
         this.P5Font = p5Font;
     }
 }

+ 43 - 0
pandora/resources/Resource.js

@@ -0,0 +1,43 @@
+/************************************************************************
+ * Resource.js
+ ************************************************************************
+ * Copyright (c) 2021 Pedro Tonini Rosenberg Schneider.
+ *
+ * This file is part of Pandora.
+ *
+ * Pandora is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * Pandora is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *     
+ * You should have received a copy of the GNU General Public License     
+ * along with Pandora.  If not, see <https://www.gnu.org/licenses/>.
+ *************************************************************************/
+
+/**
+ * This {@code Resource} class represents the base class all Resources inherit from.
+ * 
+ * ! This is an empty class the serves only to be inherited from to organize the hierarchy.
+ * ! This class should not bet used by the user.
+ * 
+ * @author Pedro Schneider
+ * 
+ * @class
+ */
+class Resource
+{
+    /**
+     * Creates an empty Resource.
+     * 
+     * @constructor
+     */
+    constructor(name = "")
+    {
+        this.name = name;
+    }
+}

+ 6 - 3
pandora/resources/SpriteFrames.js

@@ -30,7 +30,7 @@
  * 
  * @class
  */
-class SpriteAnimation
+class SpriteAnimation extends Resource
 {
     /**
      * Initialize a SpriteAnimation with the given parameters.
@@ -47,7 +47,8 @@ class SpriteAnimation
      */
     constructor(name = "default", p5Image, rows, cols, indices, fps)
     {
-        this.name = name;
+        super(name);
+
         this.fullP5Image = p5Image;
         this.rows = rows;
         this.columns = cols;
@@ -146,7 +147,7 @@ class SpriteAnimation
  * 
  * @class
  */
-class SpriteFrames
+class SpriteFrames extends Resource
 {
     /**
      * Initializes an empty SpriteFrames.
@@ -155,6 +156,8 @@ class SpriteFrames
      */
     constructor()
     {
+        super();
+        
         this.animations = [];
         this.numAnimations = 0;
     }

+ 4 - 3
pandora/resources/TextureRes.js

@@ -20,14 +20,14 @@
  *************************************************************************/
 
 /**
- * This {@code Textureres} class provides an interface to store a texture resource into
+ * This {@code TextureRes} class provides an interface to store a texture resource into
  * memory to be accessed later.
  * 
  * @author Pedro Schneider
  * 
  * @class
  */
-class TextureRes
+class TextureRes extends Resource
 {
     /**
      * Initializes a texture resource with the given parameters.
@@ -39,7 +39,8 @@ class TextureRes
      */
     constructor(name = "", p5Image = null)
     {
-        this.name = name;
+        super(name);
+
         this.P5Image = p5Image;
     }
 }