import struct

import DNANode


class DNAStreet(DNANode.DNANode):
    COMPONENT_CODE = 19

    def __init__(self, name):
        DNANode.DNANode.__init__(self, name)

        self.code = ''
        self.streetTexture = ''
        self.sideWalkTexture = ''
        self.curbTexture = ''
        self.streetColor = (1, 1, 1, 1)
        self.sidewalkColor = (1, 1, 1, 1)
        self.curbColor = (1, 1, 1, 1)
        self._setTextureCount = 0
        self._setColorCount = 0

    def setCode(self, code):
        self.code = code

    def setStreetTexture(self, texture):
        self.streetTexture = texture

    def setSidewalkTexture(self, texture):
        self.sidewalkTexture = texture

    def setCurbTexture(self, texture):
        self.curbTexture = texture

    def setStreetColor(self, color):
        self.streetColor = color

    def setSidewalkColor(self, color):
        self.sidewalkColor = color

    def setCurbColor(self, color):
        self.curbColor = color

    def setTexture(self, texture):
        if self._setTextureCount == 0:
            self.streetTexture = texture
        elif self._setTextureCount == 1:
            self.sidewalkTexture = texture
        elif self._setTextureCount == 2:
            self.curbTexture = texture
        self._setTextureCount += 1

    def setColor(self, color):
        if self._setColorCount == 0:
            self.streetColor = color
        elif self._setColorCount == 1:
            self.sidewalkColor = color
        elif self._setColorCount == 2:
            self.curbColor = color
        self._setColorCount += 1

    def debug(self, message):
        if self.verbose:
            print 'DNAStreet:', message

    def traverse(self, recursive=True, verbose=False):
        data = DNANode.DNANode.traverse(self, recursive=False, verbose=verbose)

        self.debug('packing... code length: {0}'.format(len(self.code)))
        data += struct.pack('<B', len(self.code))  # Code length
        self.debug('packing... code: {0}'.format(self.code))
        data += self.code  # Code

        self.debug('packing... street texture length: {0}'.format(len(self.streetTexture)))
        data += struct.pack('<B', len(self.streetTexture))  # Street texture length
        self.debug('packing... street texture: {0}'.format(self.streetTexture))
        data += self.streetTexture  # Street texture

        self.debug('packing... side walk texture length: {0}'.format(len(self.sideWalkTexture)))
        data += struct.pack('<B', len(self.sideWalkTexture))  # Side walk texture length
        self.debug('packing... side walk texture: {0}'.format(self.sideWalkTexture))
        data += self.sideWalkTexture  # Side walk texture

        self.debug('packing... curb texture length: {0}'.format(len(self.curbTexture)))
        data += struct.pack('<B', len(self.curbTexture))  # Curb texture length
        self.debug('packing... curb texture: {0}'.format(self.curbTexture))
        data += self.curbTexture  # Curb texture

        for component in self.streetColor:
            self.debug('packing... street color: {0}'.format(component))
            data += struct.pack('B', int(component * 255))  # Street color

        for component in self.sidewalkColor:
            self.debug('packing... side walk color: {0}'.format(component))
            data += struct.pack('B', int(component * 255))  # Side walk color

        for component in self.curbColor:
            self.debug('packing... curb color: {0}'.format(component))
            data += struct.pack('B', int(component * 255))  # Curb color

        return data

@@ -328,33 +328,33 @@
        self.side
-w
+W
 alkColor = (1, 1
@@ -525,458 +525,8 @@
 de%0A%0A
-    def setStreetTexture(self, texture):%0A        self.streetTexture = texture%0A%0A    def setSidewalkTexture(self, texture):%0A        self.sidewalkTexture = texture%0A%0A    def setCurbTexture(self, texture):%0A        self.curbTexture = texture%0A%0A    def setStreetColor(self, color):%0A        self.streetColor = color%0A%0A    def setSidewalkColor(self, color):%0A        self.sidewalkColor = color%0A%0A    def setCurbColor(self, color):%0A        self.curbColor = color%0A%0A
     
@@ -698,17 +698,17 @@
 elf.side
-w
+W
 alkTextu
@@ -993,33 +993,33 @@
        self.side
-w
+W
 alkColor = color
@@ -2753,17 +2753,17 @@
 elf.side
-w
+W
 alkColor

Fix typo in DNAStreet causing side walk textures not to be stored