Esempio n. 1
0
def write_ent(f, ent):
    # num animations
    util.write_short(f, len(ent))

    for aname, a in ent.items():
        util.write_fstring(f, aname)
        util.write_short(f, int(a['length']))
        util.write_short(f, int(a['looping'] != 'false'))
        util.write_short(f, len(a['keyframes']))

        for frame in a['keyframes']:
            util.write_short(f, int(frame['time']))

            util.write_short(f, len(frame['elements']))
            for el in frame['elements']:
                util.write_short(f, int(el['timeline']))
                util.write_short(f, int(el['key']))
                util.write_short(f, int(el['parent']))

            util.write_short(f, len(frame['bones']))
            for el in frame['bones']:
                util.write_short(f, int(el['timeline']))
                util.write_short(f, int(el['key']))
                util.write_short(f, int(el['parent']))

        util.write_short(f, len(a['timelines']))
        for tl in a['timelines']:
            util.write_short(f, len(tl))
            for els in tl:
                assert(len(els) == 1)
                el = els[0]
                util.write_fstring(f, el['file'])
                util.write_float(f, float(el['angle']) * math.pi / 180.0)
                util.write_float(f, float(el['pivot_x']))
                util.write_float(f, float(el['pivot_y']))
                util.write_float(f, float(el['scale_x']))
                util.write_float(f, float(el['scale_y']))
                util.write_float(f, float(el['x']))
                util.write_float(f, float(el['y']))
                util.write_short(f, int(el['spin']))
Esempio n. 2
0
                return None

            def is_property_set(idx, name):
                prop = get_property(idx, name)
                return prop and prop == "true"

            nspecs = max(tileid2entity.keys()) + 1
            util.write_ushort(f, nspecs)

            for ii in range(nspecs):
                # print ii, get_properties(ii)

                bitmask = 0
                if ii in tileid2entity:
                    spec = tileid2entity[ii]
                    util.write_fstring(f, spec[1].encode("ascii"))
                    util.write_fstring(f, "%d" % spec[0])

                    # seems like an obvious default
                    bitmask = bitmask_properties["visible"]
                    for k, v in bitmask_properties.items():
                        if is_property_set(ii, k):
                            # print 'setting %s on tile %d' % (k, ii)
                            bitmask |= v
                else:
                    # fill in a sparse gap
                    util.write_fstring(f, "")
                    util.write_fstring(f, "")

                # write the bitmask last
                util.write_ushort(f, bitmask)