-
Notifications
You must be signed in to change notification settings - Fork 1
mapファイルからpngを生成する機能を作成しました #25
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: develop
Are you sure you want to change the base?
Changes from 2 commits
006a410
22df12c
48e2db7
2bcabbb
7e277f1
c253710
e5c7127
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,95 @@ | ||
| import os | ||
| import re | ||
| import sys | ||
| from typing import List | ||
|
|
||
| from PIL import Image | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🚫 [mypy] reported by reviewdog 🐶 |
||
|
|
||
|
|
||
| # mapファイルのテキストデータを2次元配列に変換するメソッド | ||
| def changEArray(map_data: List[str]) -> List[List[str]]: | ||
|
polyacetal marked this conversation as resolved.
Outdated
|
||
| map_list = [] | ||
| # 各行を一マスごとに分割して配列に格納 | ||
| for i in range(len(map_data)): | ||
| if map_data[i] != "" and map_data[i][0] == "D": | ||
|
ssuzzukki marked this conversation as resolved.
Outdated
|
||
| map_list.append(re.split(",|\n", map_data[i].replace("D:", ""))) | ||
| elif map_data[i] != "" and map_data[i][0] == "H": | ||
| hot = re.split(",|\n", map_data[i].replace("H:", "")) | ||
| elif map_data[i] != "" and map_data[i][0] == "C": | ||
| cool = re.split(",|\n", map_data[i].replace("C:", "")) | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
|
|
||
| map_list[int(cool[1])][int(cool[0])] = "C" | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. "H"や”C"だとなんのことか分かりづらいので |
||
| map_list[int(hot[1])][int(hot[0])] = "H" | ||
|
|
||
| return map_list | ||
|
|
||
|
|
||
| # 一つのmapファイルをpngに変換するメソッド | ||
| def draWPng(file_name: str) -> None: | ||
|
polyacetal marked this conversation as resolved.
Outdated
|
||
| # mapファイルを開いてmap_dataにテキストを格納 | ||
| # print(file_name) | ||
| file = open("../" + file_name, "r") | ||
| map_data = file.read().split("\n") | ||
|
polyacetal marked this conversation as resolved.
Outdated
|
||
| file.close | ||
|
polyacetal marked this conversation as resolved.
Outdated
|
||
|
|
||
| map_list = changEArray(map_data) | ||
|
|
||
| # アイコン用の画像を開く | ||
| yuka = Image.open("../../icons/yuka.png") | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. パスは相対表記ではなく,
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. item,hot,coolは英語表記なのでyuka,kabeも合わせたい! |
||
| kabe = Image.open("../../icons/kabe.png") | ||
| item = Image.open("../../icons/item.png") | ||
| hot = Image.open("../../icons/hot.png") | ||
| cool = Image.open("../../icons/cool.png") | ||
|
|
||
| icon_size = yuka.width | ||
|
|
||
| # 画像の下地を描く | ||
| size = (len(map_list[0]) * icon_size, len(map_list) * icon_size) | ||
| img = Image.new("RGB", size, (255, 255, 255)) | ||
|
|
||
| # 各マスのデータに応じて画像を敷き詰める | ||
| for i in range(len(map_list)): | ||
| for j in range(len(map_list[i])): | ||
| if map_list[i][j] == "2": | ||
| # 壁 | ||
| img.paste(kabe, (j * icon_size, i * icon_size)) | ||
| elif map_list[i][j] == "3": | ||
| # アイテム | ||
| img.paste(item, (j * icon_size, i * icon_size)) | ||
| elif map_list[i][j] == "C": | ||
| # cool | ||
| img.paste(cool, (j * icon_size, i * icon_size)) | ||
| elif map_list[i][j] == "H": | ||
| # hot | ||
| img.paste(hot, (j * icon_size, i * icon_size)) | ||
| else: | ||
| # それ以外(床) | ||
| img.paste(yuka, (j * icon_size, i * icon_size)) | ||
|
|
||
| # 画像を保存 | ||
| img.save(file_name.split(".")[0] + ".png") | ||
| # img.show("test.png") | ||
|
|
||
|
|
||
| # 全てのmapファイルをpngに変換するメソッド | ||
| def draWAll() -> None: | ||
|
polyacetal marked this conversation as resolved.
Outdated
|
||
|
|
||
| dir_name = sys.argv[1] | ||
| file_list = os.listdir(dir_name) | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 実行時の引数をParseして処理する関数に切り出して |
||
|
|
||
| # mapファイルが入ったディレクトリに移動 | ||
| os.chdir(dir_name) | ||
|
|
||
| # 画像を格納するディレクトリを作成し移動 | ||
| os.mkdir("map_images") | ||
| os.chdir("map_images") | ||
|
|
||
| for i in range(len(file_list)): | ||
| draWPng(file_list[i]) | ||
|
|
||
| # もとのディレクトリに戻る | ||
| os.chdir("../../") | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. want: ディレクトリ移動ではなく, 相対パスで指定してマップファイルの読み取りと画像ファイルの書き出しをしてほしい. |
||
| print("完了しました") | ||
|
polyacetal marked this conversation as resolved.
Outdated
|
||
|
|
||
|
|
||
| draWAll() | ||
|
polyacetal marked this conversation as resolved.
Outdated
|
||
Uh oh!
There was an error while loading. Please reload this page.