Crossfire Server, Trunk
make_face_from_files.py
Go to the documentation of this file.
1 #!/bin/python
2 
3 #
4 # Crossfire -- cooperative multi-player graphical RPG and adventure game
5 #
6 # Copyright (c) 2021 the Crossfire Development Team
7 #
8 # Crossfire is free software and comes with ABSOLUTELY NO WARRANTY. You are
9 # welcome to redistribute it under certain conditions. For details, please
10 # see COPYING and LICENSE.
11 #
12 # The authors can be reached via e-mail at <crossfire@metalforge.org>.
13 #
14 
15 import argparse
16 import shutil
17 
18 def frame_code(frame):
19  if frame < 10:
20  return frame
21  return chr(ord('A') + frame - 10)
22 
23 
24 parser = argparse.ArgumentParser(description="Copy a sequence of files to Crossfire faces, adequately named. Also "
25  "generate the .face file.\nFiles are supposed to be ordered by direction "
26  "then animation frame, that is the second file is direction 2, "
27  "the 9th the second frame of direction 1's animation.\nNo check on whether "
28  "the files are actually valid PNG files or not is done.")
29 parser.add_argument('files', nargs='+')
30 parser.add_argument('--faceset', default="base", type=str, help='faceset to generate the face for, default "base"')
31 parser.add_argument('--face', required=True, type=str, help='name of the face to generate')
32 parser.add_argument('--facings', default=8, type=int, help='number of facings for the face, 1, 2, 4 or 8, default 8')
33 parser.add_argument('--magicmap', type=str, help='color to assign the face on the magicmap, default none so no magic '
34  'map information')
35 parser.add_argument('--license', type=str, help='License file to use for these faces')
36 
37 args = parser.parse_args()
38 
39 frames_per_direction = len(args.files) / args.facings
40 if frames_per_direction != int(frames_per_direction):
41  print("Error: number of files {0} must be divisible by facings {1}".format(len(args.files), args.facings))
42  exit(1)
43 
44 if args.facings == 1:
45  facings = [1]
46 elif args.facings == 2:
47  facings = [1, 5]
48 elif args.facings == 4:
49  facings = [1, 3, 5, 7]
50 else:
51  facings = [1, 2, 3, 4, 5, 6, 7, 8]
52 
53 print("Making face for '{0}', with {1} facings and {2} frames per facing.".format(args.face, args.facings,
54  int(frames_per_direction)))
55 
56 facing = 1
57 frame = 1
58 anim_file = "animation {0}\nfacings {1}\n".format(args.face, args.facings)
59 anims = []
60 magicmap = []
61 for f in range(0, len(facings) + 1):
62  anims.append([])
63  magicmap.append([])
64 for file in args.files:
65  shutil.copyfile(file, "{0}.{1}.1{2}{3}.png".format(args.face, args.faceset, facing, frame_code(frame)))
66  anims[facing].append("{0}.1{1}{2}\n".format(args.face, facing, frame_code(frame)))
67  if args.magicmap:
68  magicmap[facing] += "face {0}.1{1}{2}\nmagicmap {3}\nend\n".format(args.face, facing, frame_code(frame), args.magicmap)
69 
70  facing += 1
71  if facing == len(facings) + 1:
72  facing = 1
73  frame += 1
74 
75 for a in anims:
76  anim_file += "".join(a)
77 anim_file += "mina\n"
78 for m in magicmap:
79  anim_file += "".join(m)
80 
81 out = open("{0}.face".format(args.face), 'w')
82 out.write(anim_file)
83 out.close()
84 
85 if args.license:
86  shutil.copyfile(args.license, "{0}.{1}.LICENSE".format(args.face, args.faceset))
CFBank.open
def open()
Definition: CFBank.py:69
make_face_from_files.int
int
Definition: make_face_from_files.py:32
make_face_from_files.frame_code
def frame_code(frame)
Definition: make_face_from_files.py:18