Skip to content

Commit

Permalink
moved combined to util
Browse files Browse the repository at this point in the history
  • Loading branch information
octopoulos committed Jan 6, 2021
1 parent 6459dd5 commit 676827c
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 38 deletions.
38 changes: 0 additions & 38 deletions script/sync.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,6 @@
from time import time
from typing import Any

from PIL import Image, ImageFile

from commoner import create_group, default_int, makedirs_safe, pinfo, read_text_safe, write_text_safe
from css_minify import css_minify

Expand Down Expand Up @@ -133,40 +131,6 @@ def __init__(self, **kwargs):
# FILES
#######

def combine_pieces(self, folder: str):
"""Combine chess pieces png files into 1 file
"""
if 'metro' in folder:
height = 160
width = 160
else:
height = 80
width = 80
combined = Image.new('RGBA', (width * 12, height), (0, 255, 0, 0))
output = f'{folder}.png'

i = 0
pieces = 'bknpqr'
for color in 'bw':
for piece in pieces:
name = f'{color}{piece}'
image = Image.open(join(folder, f'{name}.png'))
offset = (i * width, 0)
combined.paste(image, offset)
i += 1

combined.save(output, format='png')
pinfo('a', end='')

def combine_themes(self, folder: str):
"""Combine all pieces of each theme
"""
sources = os.listdir(folder)
for source in sources:
filename = join(folder, source)
if os.path.isdir(filename):
self.combine_pieces(filename)

def compress_3d(self, data: str) -> str:
"""Compress THREE javascript
"""
Expand Down Expand Up @@ -547,8 +511,6 @@ def main_sync(parser: ArgumentParser=None):
args_dict = vars(args)

sync = Sync(**args_dict)
if 0:
sync.combine_themes(join(BASE, 'theme'))
sync.synchronise()


Expand Down
39 changes: 39 additions & 0 deletions script/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,54 @@
from os.path import join
from time import time

from PIL import Image, ImageFile

from commoner import create_group


BASE_PATH = os.path.abspath(os.path.dirname(__file__) + '/../')
DATA_PATH = join(BASE_PATH, 'data')


def combine_pieces(folder: str):
"""Combine chess pieces png files into 1 file
"""
if 'metro' in folder:
height = 160
width = 160
else:
height = 80
width = 80
combined = Image.new('RGBA', (width * 12, height), (0, 255, 0, 0))
output = f'{folder}.png'

i = 0
pieces = 'bknpqr'
for color in 'bw':
for piece in pieces:
name = f'{color}{piece}'
image = Image.open(join(folder, f'{name}.png'))
offset = (i * width, 0)
combined.paste(image, offset)
i += 1

combined.save(output, format='png')
pinfo('a', end='')


def combine_themes(folder: str):
"""Combine all pieces of each theme
"""
sources = os.listdir(folder)
for source in sources:
filename = join(folder, source)
if os.path.isdir(filename):
combine_pieces(filename)


def add_arguments_util(parser: ArgumentParser):
add = create_group(parser, 'util')
add('--combine', action='store_true', help='combine piece themes')
add('--inspector', nargs='?', default=0, const=1, type=int, help='run the inspector')


Expand Down

0 comments on commit 676827c

Please sign in to comment.