//
// $Id: CharacterDescriptor.java,v 1.7 2002/05/06 18:08:31 mdb Exp $

package com.threerings.cast;

import java.util.Arrays;
import com.samskivert.util.StringUtil;
import com.threerings.media.util.Colorization;

/**
 * The character descriptor object details the components that are
 * pieced together to create a single character image.
 */
public class CharacterDescriptor
{
    /**
     * Constructs a character descriptor.
     *
     * @param components the component ids of the individual components
     * that make up this character.
     * @param zations the colorizations to apply to each of the character
     * component images when compositing actions (an array of
     * colorizations for each component, elements of which can be null to
     * make it easier to support per-component specialized colorizations).
     * This can be null if image recolorization is not desired.
     */
    public CharacterDescriptor (int[] components, Colorization[][] zations)
    {
        _components = components;
        _zations = zations;
    }

    /**
     * Returns an array of the component identifiers comprising the
     * character described by this descriptor.
     */
    public int[] getComponentIds ()
    {
        return _components;
    }

    /**
     * Returns an array of colorization arrays to be applied to the
     * components when compositing action images (one array per
     * component).
     */
    public Colorization[][] getColorizations ()
    {
        return _zations;
    }

    /**
     * Compute a sensible hashcode for this object.
     */
    public int hashCode ()
    {
        int code = 0, clength = _components.length;
        for (int i = 0; i < clength; i++) {
            code ^= _components[i];
        }
        return code;
    }

    /**
     * Compares this character descriptor to another.
     */
    public boolean equals (Object other)
    {
        if (!(other instanceof CharacterDescriptor)) {
            return false;
        }

        // both the component ids and the colorizations must be equal
        CharacterDescriptor odesc = (CharacterDescriptor)other;
        if (!Arrays.equals(_components, odesc._components)) {
            return false;
        }

        // if neither has colorizations, we're clear
        Colorization[][] zations = odesc._zations;
        if (zations == null && _zations == null) {
            return true;
        }

        // otherwise, all of the colorizations must be equal as well
        int zlength = _zations.length;
        if (zlength != zations.length) {
            return false;
        }
        for (int i = 0; i < zlength; i++) {
            if (!Arrays.equals(_zations[i], zations[i])) {
                return false;
            }
        }

        return true;
    }

    /**
     * Returns a string representation of this character descriptor.
     */
    public String toString ()
    {
        return "[cids=" + StringUtil.toString(_components) +
            ", colors=" + StringUtil.toString(_zations) + "]";
    }

    /** The component identifiers comprising the character. */
    protected int[] _components;

    /** The colorizations to apply when compositing this character. */
    protected Colorization[][] _zations;
}

@@ -37,33 +37,36 @@
 v 1.
-7
+8
  2002/0
-5/06 18:08:31 mdb
+6/18 04:55:44 shaper
  Exp
@@ -2215,32 +2215,138 @@
 lse;%0A        %7D%0A%0A
+        Colorization%5B%5D%5B%5D zations = odesc._zations;%0A        if (zations == null && _zations == null) %7B%0A    
         // if ne
@@ -2394,50 +2394,25 @@
     
-Colorization%5B%5D%5B%5D zations = odesc._zations;
+    return true;%0A
 %0A   
@@ -2408,32 +2408,39 @@
  true;%0A%0A        
+%7D else 
 if (zations == n
@@ -2435,34 +2435,34 @@
 zations == null 
-&&
+%7C%7C
  _zations == nul
@@ -2474,34 +2474,136 @@
             
-return tru
+// if one has colorizations whilst the other doesn't, they%0A            // can't be equal%0A            return fals
 e;%0A        %7D
@@ -2695,17 +2695,16 @@
 ength = 
-_
 zations.
@@ -2734,16 +2734,17 @@
 ngth != 
+_
 zations.
@@ -2807,23 +2807,25 @@
 r (int i
+i
  = 0; i
+i
  %3C zleng
@@ -2820,32 +2820,33 @@
 ; ii %3C zlength; 
+i
 i++) %7B%0A         
@@ -2877,16 +2877,17 @@
 ations%5Bi
+i
 %5D, zatio
@@ -2890,16 +2890,17 @@
 ations%5Bi
+i
 %5D)) %7B%0A  

Descriptors are inequal if one has colorizations and the other doesn't.