Package gamedata

Class ConversionMap


  • public class ConversionMap
    extends java.lang.Object
    Represents the possible game component conversion options available in the ConvertMenu and stores the data needed to initiate the conversions. Primarily, this class is used by extensions to register new conversion options from a conversion map file. This class can also be used to examine conversion map file entries programmatically. For example, the following script code prints a list of direct conversion options for the my.example.CustomComponent component type:
     var className = 'my.example.CustomComponent';
     var conversionMap = gamedata.ConversionMap.shared;
     for( let entry in Iterator( conversionMap.getDirectConversions(className) ) ) {
         println( entry.name + ' -> ' + entry.targetClassName );
     }
     
    Author:
    Henrik Rostedt
    • Constructor Summary

      Constructors 
      Constructor Description
      ConversionMap​(java.lang.String... resources)
      Creates a new conversion map containing the entries parsed from the specified conversion map resources.
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      static void add​(java.lang.String resource)
      Adds the specified conversion map resource to the list of such files that is used to generate the contents of the convert menu options.
      java.util.Set<ConversionMap.Conversion> getDirectConversions​(java.lang.String sourceClassName)
      Returns the direct conversions from the specified component type.
      java.util.Map<ConversionMap.Group,​java.util.Set<ConversionMap.Conversion>> getGroupConversions​(java.lang.String sourceClassName)
      Returns the group conversions from the specified component type.
      static ConversionMap getShared()
      Returns a shared instance of ConversionMap that can be used to look up conversion options.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • ConversionMap

        public ConversionMap​(java.lang.String... resources)
                      throws java.io.IOException
        Creates a new conversion map containing the entries parsed from the specified conversion map resources. Groups entries are cached statically, however, the group members are tracked per instance. An extension wanting to inspect the manual conversion options should generally use getShared() instead.
        Parameters:
        resources - the conversion map resources to parse
        Throws:
        java.io.IOException - if any of the resources can not be read
    • Method Detail

      • getDirectConversions

        public java.util.Set<ConversionMap.Conversion> getDirectConversions​(java.lang.String sourceClassName)
        Returns the direct conversions from the specified component type. Only conversions for installed extensions are included. The returned set is immutable and only calculated once per component type.
        Parameters:
        sourceClassName - the class name of the source component type
        Returns:
        the direct conversions from the component type
      • getGroupConversions

        public java.util.Map<ConversionMap.Group,​java.util.Set<ConversionMap.Conversion>> getGroupConversions​(java.lang.String sourceClassName)
        Returns the group conversions from the specified component type. Only conversions for installed extensions are included. The returned map is immutable and only calculated once per component type.
        Parameters:
        sourceClassName - the class name of the source component type
        Returns:
        the group conversions from the component type
      • add

        public static void add​(java.lang.String resource)
        Adds the specified conversion map resource to the list of such files that is used to generate the contents of the convert menu options. The sample conversion map (/resources/projects/new-conversionmap.txt) describes the format of these files.
        Parameters:
        resource - a relative URL within resources/ that points to the file to add
      • getShared

        public static ConversionMap getShared()
                                       throws java.io.IOException
        Returns a shared instance of ConversionMap that can be used to look up conversion options. The instance is created the first time this is called. Must not be called before all extensions have been loaded.
        Returns:
        the shared ConversionMap instance
        Throws:
        java.io.IOException - if the shared instance could not be created