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 parser = argparse.ArgumentParser(description="Copy a sequence of files to Crossfire faces, adequately named. Also "
19  "generate the .face file.\nFiles are supposed to be ordered by direction "
20  "then animation frame, that is the second file is direction 2, "
21  "the 9th the second frame of direction 1's animation.\nNo check on whether "
22  "the files are actually valid PNG files or not is done.")
23 parser.add_argument('files', nargs='+')
24 parser.add_argument('--faceset', default="base", type=str, help='faceset to generate the face for, default "base"')
25 parser.add_argument('--face', required=True, type=str, help='name of the face to generate')
26 parser.add_argument('--facings', default=8, type=int, help='number of facings for the face, 1, 2, 4 or 8, default 8')
27 parser.add_argument('--magicmap', type=str, help='color to assign the face on the magicmap, default none so no magic '
28  'map information')
29 
30 args = parser.parse_args()
31 
32 frames_per_direction = len(args.files) / args.facings
33 if frames_per_direction != int(frames_per_direction):
34  print("Error: number of files {0} must be divisible by facings {1}".format(len(args.files), args.facings))
35  exit(1)
36 
37 if args.facings == 1:
38  facings = [1]
39 elif args.facings == 2:
40  facings = [1, 5]
41 elif args.facings == 4:
42  facings = [1, 3, 5, 7]
43 else:
44  facings = [1, 2, 3, 4, 5, 6, 7, 8]
45 
46 print("Making face for '{0}', with {1} facings and {2} frames per facing.".format(args.face, args.facings,
47  int(frames_per_direction)))
48 
49 facing = 1
50 frame = 1
51 anim_file = "animation {0}\nfacings {1}\n".format(args.face, args.facings)
52 anims = []
53 magicmap = []
54 for f in range(0, len(facings) + 1):
55  anims.append([])
56  magicmap.append([])
57 for file in args.files:
58  shutil.copyfile(file, "{0}.{1}.1{2}{3}.png".format(args.face, args.faceset, facing, frame))
59  anims[facing].append("{0}.1{1}{2}\n".format(args.face, facing, frame))
60  if args.magicmap:
61  magicmap[facing] += "face {0}.1{1}{2}\nmagicmap {3}\nend\n".format(args.face, facing, frame, args.magicmap)
62 
63  facing += 1
64  if facing == len(facings) + 1:
65  facing = 1
66  frame += 1
67 
68 for a in anims:
69  anim_file += "".join(a)
70 anim_file += "mina\n"
71 for m in magicmap:
72  anim_file += "".join(m)
73 
74 out = open("{0}.face".format(args.face), 'w')
75 out.write(anim_file)
76 out.close()
CFBank.open
def open()
Definition: CFBank.py:70
make_face_from_files.int
int
Definition: make_face_from_files.py:26