from EarthSculptor to Panda

This is the function from my Map class:

from re import match
def isFloat(n):
  if match("^-?([0-9]*\\.)?[0-9]+$", n):
    return True
  return False
def isInt(n):
  if match("^-?[0-9]+$", n):
    return True
  return False

#...

class Map(object):

#...

  def loadES(self, file):
    """Imports a map from the EarthSculptor format"""
    self.reset()
    o = {}
    if(not isinstance(file,Filename)):
      file = Filename(file)
    if(not file.exists()):
      raise IOError, "Cannot find map file! ("+str(file)+")" 
    self.name = file.getBasenameWoExtension()
    f = open(file.toOsSpecific()) #python's open() command uses OS specific paths
    for l in f:
      l = l.strip()
      if(not l.startswith("//")):
        if(l.find(" ") == -1):
          o[l] = True
        else:
          ll = l.split(" ",1)
          if(ll[1].find(" ") == -1 or ll[1].find(""") != -1):
            t = ll[1].replace(""","")
            if(isInt(t)):
              t = int(t)
            elif(isFloat(t)):
              t = float(t)
          else:
            t = []
            for i in ll[1].split(" "):
              if(isInt(i)):
                t.append(int(i))
              elif(isFloat(i)):
                t.append(float(i))
              else:
                t.append(i)
          o[ll[0]] = t
    f.close()
    # Now, I access the things like:
    print o["mapHeight"]
    print [ o["tileTextureSize"] / float(s) for s in o["detailScales"]]

Also, you might have already noticed that the used colors are in some weird number format. I wrote some functions to convert to and from those color types:

def LongColorToRGB(es_color):
  hexstr = '%08x' % int(es_color)
  r, g, b = hexstr[2:4], hexstr[4:6], hexstr[6:]
  r, g, b = [int(n, 16)/255.0 for n in (r, g, b)]
  return (r, g, b)

def RGBToLongColor(rgb_tuple):
  r, g, b = [int(n*255.0) for n in rgb_tuple]
  colorstring = '%02x%02x%02x%02x' % (255,r,g,b)
  return int(colorstring)

Good luck. :slight_smile:

Well, I doubt that. My earthsculptor code is messy and it is scattered all over my game. :slight_smile: