Advertisement
at0_zz

LDOG

Aug 8th, 2015
273
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 4.04 KB | None | 0 0
  1. #!/usr/bin/python
  2. # -*- coding: utf-8 -*-
  3.  
  4. from xml.dom import minidom
  5. import re
  6. from PIL import Image, ImageDraw
  7. import math
  8.  
  9. MAP_X = 801
  10. MAP_Y = 801
  11.  
  12.  
  13. orange = 'rgb(249,118,3)'
  14. red = 'rgb(255,0,0)'
  15. green = 'rgb(51,255,51)'
  16. gray = 'rgb(192,192,192)'
  17. yellow = 'rgb(255,255,102)'
  18. brown = 'rgb(102,51,0)'
  19.  
  20. colors = dict(  SETTING_ORANGE          = orange, \
  21.                 FOLDER_ROADS_ORANGE     = orange, \
  22.                 FOLDER_ROADS_REDROCK    = red, \
  23.                 SETTING_REDROCK         = red, \
  24.                 FOLDER_CONCRETE_REDROCK = red, \
  25.                 SETTING_GREEN           = green, \
  26.                 FOLDER_ROADS_GREEN      = green, \
  27.                 FOLDER_ROCKS            = gray, \
  28.                 SETTING_YELLOW          = yellow, \
  29.                 FOLDER_CONCRETE_YELLOW  = yellow, \
  30.                 FOLDER_ROADS_YELLOW     = yellow, \
  31.                 SETTING_CAVE            = brown, \
  32.                 FOLDER_SCHUTT           = brown \
  33.              )
  34.  
  35. unknown_colors = 'rgb(255,0,127)'
  36.  
  37. details = {}
  38.  
  39. fp = open('details.txt')
  40. for line in fp:
  41.     arr = line.split(';')
  42.     if arr[0].isdigit():
  43.         id = arr[0]
  44.         category = arr[2]
  45.         left = int(arr[4])
  46.         top = int(arr[5])
  47.         right = int(arr[6])
  48.         bottom = int(re.sub("^\s+|\n|\r|\s+$", '', arr[7]))
  49.         details[id] = dict( category=category, \
  50.                             left=left, \
  51.                             top=top, \
  52.                             right=right, \
  53.                             bottom=bottom \
  54.                           )
  55.  
  56. # print(details)
  57.  
  58. fp.close()
  59.  
  60. zone = minidom.parse("zone")
  61.  
  62. CY2K_LS_AreaDetails = zone.getElementsByTagName("CY2K_LS_AreaDetails")[0]
  63. areas = CY2K_LS_AreaDetails.getElementsByTagName('details')
  64.  
  65. image = Image.new("RGB", (MAP_X,MAP_Y), (0,0,0,0))
  66.  
  67. draw = ImageDraw.Draw(image)
  68.    
  69. for area in areas:
  70.     iDetailDefID = area.getElementsByTagName("iDetailDefID")[0].firstChild.data
  71.    
  72.     if not iDetailDefID in details:
  73.         continue
  74.        
  75.     fPositionX = float(area.getElementsByTagName("fPositionX")[0].firstChild.data)
  76.     fPositionY = float(area.getElementsByTagName("fPositionY")[0].firstChild.data)
  77.     fRotation = float(area.getElementsByTagName("fRotation")[0].firstChild.data)
  78.     fScaleX = 1 # float(area.getElementsByTagName("fScaleX")[0].firstChild.data)
  79.     fScaleY = 1 # float(area.getElementsByTagName("fScaleY")[0].firstChild.data)
  80.    
  81.     detail = details[iDetailDefID]
  82.  
  83.     width = (detail['right'] - detail['left']) * fScaleX
  84.     height = (detail['bottom'] - detail['top']) * fScaleY
  85.    
  86.     # Ищем левый верхий угол
  87.     angleX = fPositionX - ( width / 2 )
  88.     angleY = fPositionY - ( height / 2 )
  89.    
  90.     if not detail['category'] in colors:
  91.         color = unknown_colors
  92.     else:
  93.         color = colors[detail['category']]
  94.    
  95.  
  96.     print('--------------------------------------------------------')
  97.    
  98.     print(' iDetailDefID: %s  COLOR: %s  CATEGORY: %s' \
  99.             % (iDetailDefID, color, detail['category']))
  100.            
  101.     print(' ScaleX * (right - left) = width              %s * (%s - %s) = %s'
  102.             % (fScaleX, detail['right'], detail['left'], width))
  103.            
  104.     print(' ScaleY * (bottom - top) = height             %s * (%s - %s) = %s'
  105.             % (fScaleY, detail['bottom'], detail['top'], height))
  106.            
  107.     print(' fPositionX - ( width / 2 ) = angleX          %s - (%s / 2) = %s '
  108.             % (fPositionX, width, angleX))
  109.            
  110.     print(' fPositionY - ( height / 2 ) = angleY          %s - (%s / 2) = %s '
  111.             % (fPositionY, height, angleY))
  112.    
  113.     x1 = int(angleX)
  114.     y1 = int(angleY)
  115.      
  116.     x2 = int(width + angleX)  
  117.     y2 = int(height + angleY)
  118.    
  119.     rect = Image.new("RGB", (x2, y2), color)
  120.     rect.rotate( fRotation, expand=1 )
  121.     image.paste(rect, (x1,y1))
  122.    
  123.     # draw.rectangle(( x1, y1, x2, y2), fill=color )
  124.     # .rotate( fRotation, expand=1 )
  125.      
  126.        
  127.    
  128. del draw
  129. image.save("proto_zone.png", "PNG")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement