View Javadoc

1   /*
2    * Entreri, an entity-component framework in Java
3    *
4    * Copyright (c) 2013, Michael Ludwig
5    * All rights reserved.
6    *
7    * Redistribution and use in source and binary forms, with or without modification,
8    * are permitted provided that the following conditions are met:
9    *
10   *     Redistributions of source code must retain the above copyright notice,
11   *         this list of conditions and the following disclaimer.
12   *     Redistributions in binary form must reproduce the above copyright notice,
13   *         this list of conditions and the following disclaimer in the
14   *         documentation and/or other materials provided with the distribution.
15   *
16   * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
17   * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18   * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19   * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
20   * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
21   * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
22   * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
23   * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24   * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
25   * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26   */
27  package com.lhkbob.entreri.property;
28  
29  /**
30   * <p/>
31   * A PropertyFactory is a simple factory that can be used to create Property instances.
32   * Additionally, it is used when decorating a ComponentData type in an EntitySystem to
33   * ensure that each decoration event gets a unique property instance.
34   * <p/>
35   * PropertyFactory implementations must have a no-argument constructor or a constructor
36   * that takes an {@link Attributes} as its only argument. The constructor does not need to
37   * be public.
38   *
39   * @param <T> The Property type created
40   *
41   * @author Michael Ludwig
42   */
43  public interface PropertyFactory<T extends Property> {
44      /**
45       * Return a new Property instance. This must be a new instance that has not been
46       * returned previously or the entity framework will have undefined behavior.
47       *
48       * @return A new Property of type T
49       */
50      public T create();
51  
52      /**
53       * Set the default value that the component at the specified <var>index</var> will see
54       * before it's init() method is invoked. In some cases, this could be used in-place of
55       * initializing in init() method.
56       *
57       * @param property The property whose value will be updated
58       * @param index    The component index to be updated
59       */
60      public void setDefaultValue(T property, int index);
61  
62      /**
63       * Copy the value from <var>src</var> at component index, <var>srcIndex</var> to
64       * <var>dst</var> at <var>dstIndex</var>. This is used when a component is created and
65       * cloned from a template with {@link com.lhkbob.entreri.Entity#add(com.lhkbob.entreri.Component)}.
66       * For many cases a plain copy-by-value or copy-by-reference is sufficient, but some
67       * component types might require more complicated cloning rules.
68       *
69       * @param src      The source property that is being cloned
70       * @param srcIndex The index into src of the component being cloned
71       * @param dst      The destination property created from the template
72       * @param dstIndex The index into dst of the component being created
73       */
74      public void clone(T src, int srcIndex, T dst, int dstIndex);
75  }