public SpriteLink(Resource res, Message buf) { res.super(); int ver = buf.uint8(); if (ver != 1) throw (new Resource.LoadException("Unknown spritelink version: " + ver, getres())); Map<Integer, Factory> refs = new IntMap<Factory>(16); while (true) { int id = buf.int16(); if (id < 0) break; char t = (char) buf.uint8(); Factory f; switch (t) { case 't': f = new ByTile(res, buf, refs); break; case 'r': f = new ByRes(res, buf, refs); break; default: throw (new Resource.LoadException("Unknown spritelink type: `" + t + "'", getres())); } refs.put(id, f); } this.f = refs.get(buf.int16()); }
private ByTile(Resource res, Message buf, Map<Integer, Factory> refs) { tag = new String[buf.uint8()]; sub = new Factory[tag.length]; for (int i = 0; i < tag.length; i++) { tag[i] = buf.string(); sub[i] = refs.get(buf.int16()); } def = refs.get(buf.int16()); }
public void fill(Message msg) { String mmname = msg.string().intern(); if (mmname.equals("")) mnm = null; else mnm = mmname; int[] pfl = new int[256]; while (true) { int pidx = msg.uint8(); if (pidx == 255) break; pfl[pidx] = msg.uint8(); } Message blob = msg.inflate(); id = blob.int64(); for (int i = 0; i < tiles.length; i++) tiles[i] = blob.uint8(); for (int i = 0; i < z.length; i++) z[i] = blob.int16(); for (int i = 0; i < ol.length; i++) ol[i] = 0; while (true) { int pidx = blob.uint8(); if (pidx == 255) break; int fl = pfl[pidx]; int type = blob.uint8(); Coord c1 = new Coord(blob.uint8(), blob.uint8()); Coord c2 = new Coord(blob.uint8(), blob.uint8()); int ol; if (type == 0) { if ((fl & 1) == 1) ol = 2; else ol = 1; } else if (type == 1) { if ((fl & 1) == 1) ol = 8; else ol = 4; } else { throw (new RuntimeException("Unknown plot type " + type)); } for (int y = c1.y; y <= c2.y; y++) { for (int x = c1.x; x <= c2.x; x++) { this.ol[x + (y * cmaps.x)] |= ol; } } } invalidate(); }