红警DIY论坛

 找回密码
 注册

QQ登录

只需一步,快速开始

搜索
查看: 2091|回复: 7

[工具]批量生成适用于dta客户端的MPMaps.ini信息以及全景图

[复制链接]
发表于 2022-5-7 12:37:07 | 显示全部楼层 |阅读模式
本帖最后由 囧韓方序囧 于 2022-5-7 20:30 编辑

要使用这个程序,你需要安装python3下载最新版就行
还需要cncmaps renderer翻到最后一页,用最新版 发帖时的最新版
然后你需要把py文件放到你的地图文件夹,进入IDLE编辑

需要编辑的内容都在里面了,主要修改游戏目录、渲染器目录、预制的内容,以及初始序号就行

然后run module运行即可

运行速度非常快,直接占满cpu

运行完之后会在目录里生成output.txt,把里面的东西拷贝到MPMaps.ini即可

直接生成的文件太大,dta客户端把持不住,需要进行压缩
使用压缩包里的批量缩放图片.exe,把整个文件夹拖进去, 重设大小建议800*800,输出格式选择png。最后把压缩好的图片拷贝回去即可

效果展示:

本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有账号?注册

x
发表于 2022-5-8 21:28:08 | 显示全部楼层
看懂了一点点但没有完全看懂,dalao太强了
发表于 2022-5-9 10:42:58 | 显示全部楼层
这种东西好久以前Kerbiter就发过了,而且用configparser不是更方便吗

  1. """

  2. File name: MPMapsBuilder3.py
  3. Original author: MirageTD / Chrono Vortex
  4. Modififed by: Kerbiter#3128@Discord / Metadorius@GitHub
  5. Date created: 10/11/2018
  6. Date last modified: 08/06/2020
  7. Python version: 3.8

  8. """
  9. from pathlib import Path
  10. import glob
  11. from PIL import Image
  12. from operator import itemgetter

  13. try:
  14.     from configparser import ConfigParser, ParsingError
  15. except ImportError:
  16.     from ConfigParser import ConfigParser, ParsingError


  17. class CaseConfigParser(ConfigParser):
  18.     """Case-sensitive ConfigParser."""

  19.     def optionxform(self, optionstr):
  20.         return optionstr

  21. SEP = '\n=======================================================\n'


  22. ask_names = True if (i := input("Ask for missing names [y/N]? ")) and i.lower()[0] == 'y' else False
  23. ask_authors = True if (i := input("Ask for missing authors [y/N]? ")) and i.lower()[0] == 'y' else False
  24. skip = True if (i := input("Skip erroneous files instead of stopping [y/N]? ")) and i.lower()[0] == 'y' else False

  25. map_path = None
  26. cwd = Path.cwd()
  27. directory = Path.cwd()
  28. for folder in directory.parents:
  29.     client_folder = folder / 'Resources'
  30.     if client_folder.exists() and client_folder.is_dir():
  31.         map_path = str(cwd.relative_to(folder))

  32. if (new_map_path := input(f'Detected map path is {map_path}. You can leave the detected folder\n(press [Enter]) or enter a correct one instead.\n')):
  33.     map_path = new_map_path

  34. default_modes = input(f'Enter default gamemodes for maps with missing gamemodes\n(or press [Enter] to skip and enter them individually):\n')


  35. print(SEP)

  36. files = glob.glob('**/*.map', recursive=True)

  37. ### Add info from GamemodeInfo.ini to MPMaps.ini ###
  38. config = CaseConfigParser()
  39. config.read('GamemodeInfo.ini')

  40. ### Add info from new maps to MPMaps.ini ###
  41. for file in files:

  42.     config_temp = CaseConfigParser()
  43.     try:
  44.         config_temp.read(file)
  45.     except ParsingError as e:
  46.         print(f'Skipping map file: {e}')

  47.         if not skip:
  48.             raise

  49.     section_name = map_path + file
  50.     config.add_section(section_name)

  51.     # Can't get NumberStartingPoints from [Header] 'cause it MIGHT BE FUCKING WRONG >:(
  52.     num_players = 0
  53.     while config_temp.has_option('Waypoints', str(num_players)):
  54.         config.set(section_name, 'Waypoint' + str(num_players),
  55.                    config_temp.get('Waypoints', str(num_players)))
  56.         num_players += 1

  57.     config.set(section_name, 'MinPlayers', '1')
  58.     config.set(section_name, 'MaxPlayers', str(num_players))

  59.     map_name = Path(file).name
  60.     if config_temp.has_option('Basic', 'Name'):
  61.         map_name = config_temp.get('Basic', 'Name')
  62.     elif ask_names:
  63.         map_name = input(
  64.             f'NAME NOT DETECTED for {section_name}, please input: ')
  65.     config.set(section_name, 'Description', map_name)

  66.     if config_temp.has_option('Basic', 'Author'):
  67.         config.set(section_name, 'Author', config_temp.get('Basic', 'Author'))
  68.     elif ask_authors:
  69.         config.set(section_name, 'Author', str(
  70.             input(f'AUTHOR NOT DETECTED for {section_name}, please input: ')))

  71.     config.set(section_name, 'EnforceMaxPlayers', 'True')
  72.     config.set(section_name, 'Size', config_temp.get('Map', 'Size'))
  73.     config.set(section_name, 'LocalSize', config_temp.get('Map', 'LocalSize'))

  74.     image_name = file[:-3] + 'png'
  75.     try:
  76.         w, h = Image.open(image_name).size
  77.         config.set(section_name, 'PreviewSize', str(w) + ',' + str(h))
  78.     except FileNotFoundError:
  79.         print(f'Skipping writing PreviewSize for non-existing image {image_name}.')

  80.     map_game_mode = default_modes
  81.     if config_temp.has_option('Basic', 'GameMode'):
  82.         map_game_mode = config_temp.get('Basic', 'GameMode')
  83.     elif not map_game_mode:
  84.         map_game_mode = input(
  85.             f'GAMEMODE NOT DETECTED for {section_name}, please input: ')

  86.     print(f'Parsed map file {file} successfully.\n')


  87. print(SEP)

  88. ### Replace all entries in [MultiMaps] ###
  89. # Save & sort new entries
  90. entries = [map_path + e for e in files]
  91. entry_names = [config.get(e, 'Description').replace('[', '').replace(
  92.     ']', '').replace(' ', '').replace(',', '').replace("'", '') for e in entries]

  93. entry_pairs = sorted(list(zip(entry_names, entries)), key=itemgetter(0))

  94. # for i in range(len(entries)):
  95. #     entry_pairs.append((entry_names[i], entries[i]))
  96. # entry_pairs.sort(key=itemgetter(0))

  97. # Set new entries
  98. config.add_section('MultiMaps')
  99. for i in range(len(entry_pairs)):
  100.     config.set(
  101.         'MultiMaps', f'({entry_pairs[i][0]}){i}', entry_pairs[i][1])

  102. with open('MPMaps.ini', 'w') as configfile:
  103.     config.write(configfile, space_around_delimiters=False)

  104. input(f'\n\n{len(entry_pairs)} maps written to MPMaps.ini. Press [Enter] to exit.')
复制代码
 楼主| 发表于 2022-5-9 11:37:30 | 显示全部楼层
trsdy 发表于 2022-5-9 10:42
这种东西好久以前Kerbiter就发过了,而且用configparser不是更方便吗

感觉我这个更好用一些
发表于 2022-5-15 15:42:13 | 显示全部楼层
囧韓方序囧 发表于 2022-5-9 11:37
感觉我这个更好用一些

Traceback (most recent call last):
  File "C:\Users\Desktop\ColdAI3rdWithCncnet1.5\Maps\Custom\map_generator.py", line 66, in <module>
    waypoint1 = [int(j.split(',')[-2].split('=')[-1]),int(j.split(',')[-1])]
IndexError: list index out of range

注册出现这个是啥情况
 楼主| 发表于 2022-5-18 20:42:06 | 显示全部楼层
迈克老狼 发表于 2022-5-15 15:42
Traceback (most recent call last):
  File "C:%users\Desktop\ColdAI3rdWithCncnet1.5\Maps\Custom\map ...

地图文件有问题吧,你发一下[Header]片段让我看看
发表于 2022-5-19 07:12:23 | 显示全部楼层
囧韓方序囧 发表于 2022-5-18 20:42
地图文件有问题吧,你发一下[Header]片段让我看看

你好
前面是
  1. ; Map created with FinalAlert 2(tm) Mission Editor
  2. ; Get it at http://www.westwood.com
  3. ; note that all comments were truncated

  4. [Header]
  5. Width=
  6. Height=
  7. StartX=
  8. StartY=
  9. Waypoint1=
  10. Waypoint2=
  11. Waypoint3=
  12. Waypoint4=
  13. Waypoint5=
  14. Waypoint6=
  15. Waypoint7=
  16. Waypoint8=
  17. NumberStartingPoints=
  18. NumCoopHumanStartSpots=


  19. [Preview]
  20. Size=0,0,280,75
复制代码





后面是:
  1. [Waypoints]
  2. 0=164080
  3. 1=98092
  4. 2=78112
  5. 3=58132
  6. 4=38152
  7. 5=108122
  8. 6=88142
  9. 7=68162
  10. 11=163063

  11. [YuriCountry]
  12. =
  13. IQ=0
  14. Edge=North
  15. Color=DarkRed
  16. Allies=YuriCountry
  17. Country=YuriCountry
  18. Credits=0
  19. NodeCount=0
  20. TechLevel=1
  21. PercentBuilt=0
  22. PlayerControl=no



  23. [Digest]
  24. 1=ojuEIkZjGmExxpweNBQ59ahRQ+8=

  25. [MultiplayerDialogSettings]
  26. AllyChangeAllowed=yes
  27. AlliesAllowed=yes
复制代码
发表于 2022-5-23 12:48:29 | 显示全部楼层
本帖最后由 迈克老狼 于 2022-5-23 12:54 编辑
囧韓方序囧 发表于 2022-5-18 20:42
地图文件有问题吧,你发一下[Header]片段让我看看

已经解决了 设置有问题,目录名不能有标点符号。
您需要登录后才可以回帖 登录 | 注册

本版积分规则

小黑屋|Archiver|手机版|管理员邮箱|红警DIY官方论坛

GMT+8, 2024-3-29 17:19 , Processed in 0.045757 second(s), 15 queries .

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

快速回复 返回顶部 返回列表