Пример #1
0
  /**
   * @param type Type to retrieve.
   * @return Map of all the Node objects matching the given type, with their node index as keys.
   */
  public Map<Integer, Node> getNodes(NodeType type) {
    Map<Integer, Node> out = new TreeMap<>();
    String name = "";
    for (int i = 0; i < nodes.size(); i++) {
      Node n = getNode(i);
      if (n.type == NodeType.NITRISHAPE) {

        name = n.title;
      }
      if (n.type == type) {
        if (n.title == null) {
          n.title = name;
        }
        out.put(n.number, n);
      }
    }
    return out;
  }
Пример #2
0
 /**
  * A special function that returns sets of nodes each relating to a NiTriShape package. This
  * return a list of lists containing a NiTriShape and all the nodes following up until another
  * NiTriShape is encountered, which will start another list.
  *
  * @return List of NiTriShape node sets.
  */
 public ArrayList<ArrayList<Node>> getNiTriShapePackages() {
   ArrayList<ArrayList<Node>> out = new ArrayList<>();
   ArrayList<Node> NiTriShapePackage = new ArrayList<>();
   boolean on = false;
   String title = "";
   for (Node n : nodes) {
     if (n.type == NodeType.NITRISHAPE) {
       NiTriShapePackage = new ArrayList<>();
       out.add(NiTriShapePackage);
       title = n.title;
       NiTriShapePackage.add(n);
       on = true;
     } else if (on) {
       n.title = title;
       NiTriShapePackage.add(n);
     }
   }
   return out;
 }
Пример #3
0
  void loadHeader(LShrinkArray in) throws BadParameter {

    // Gamebryo header
    if (SPGlobal.debugNIFimport) {
      SPGlobal.logSync(header, "Loading nif file");
    }
    if (!in.getString(20).equals("Gamebryo File Format")) {
      byte first = in.extract(1)[0];
      if (!in.extractString((int) first, 20).equals("Gamebryo File Format")) {
        throw new BadParameter(fileName + " was not a NIF file.");
      }
    }

    in.extractLine();

    // BlockTypes
    numBlocks = in.extractInt(9, 4);
    if (SPGlobal.debugNIFimport && SPGlobal.logging()) {
      SPGlobal.logSync(header, "Num Blocks: " + numBlocks);
    }
    in.skip(in.extractInt(4, 1)); // Author name
    in.skip(in.extractInt(1)); // Export Info 1
    in.skip(in.extractInt(1)); // Export Info 2
    int numBlockTypes = in.extractInt(2);
    if (SPGlobal.debugNIFimport && SPGlobal.logging()) {
      SPGlobal.logSync(header, "Num Block Types: " + numBlockTypes);
    }
    blockTypes = new ArrayList<>(numBlockTypes);
    for (int i = 0; i < numBlockTypes; i++) {
      String blockType = in.extractString(in.extractInt(4));
      blockTypes.add(blockType);
      if (SPGlobal.debugNIFimport && SPGlobal.logging()) {
        SPGlobal.logSync(header, "  Added block type[" + i + "]: " + blockType);
      }
    }

    // Blocks list
    if (SPGlobal.debugNIFimport && SPGlobal.logging()) {
      SPGlobal.logSync(header, "Block Type list: ");
    }
    nodes = new ArrayList<>(numBlocks);
    for (int i = 0; i < numBlocks; i++) {
      int type = in.extractInt(2);
      Node n = new Node(NodeType.SPvalueOf(blockTypes.get(type)));
      n.number = i;
      nodes.add(n);
      if (SPGlobal.debugNIFimport && SPGlobal.logging()) {
        SPGlobal.logSync(
            header,
            "  Block list[" + i + "] has block type: " + type + ", " + blockTypes.get(type));
      }
    }

    // Block lengths
    for (int i = 0; i < numBlocks; i++) {
      nodes.get(i).size = in.extractInt(4);
    }

    if (SPGlobal.debugNIFimport && SPGlobal.logging()) {
      SPGlobal.logSync(header, "Block headers: ");
      for (int i = 0; i < numBlocks; i++) {
        SPGlobal.logSync(
            header,
            "  ["
                + i
                + "]: "
                + nodes.get(i).type
                + ", length: "
                + Ln.prettyPrintHex(nodes.get(i).size));
      }
    }

    // Strings
    if (SPGlobal.debugNIFimport && SPGlobal.logging()) {
      SPGlobal.logSync(header, "Block Titles: ");
    }
    int numStrings = in.extractInt(4);
    in.skip(4); // max Length string
    ArrayList<String> strings = new ArrayList<>(numStrings);
    for (int i = 0; i < numStrings; i++) {
      strings.add(in.extractString(in.extractInt(4)));
    }
    in.skip(4); // unknown int

    for (int i = 0; i < numBlocks; i++) {
      nodes.get(i).data = new LShrinkArray(in, nodes.get(i).size);
      in.skip(nodes.get(i).size);
    }

    // Set titles
    for (int i = 0; i < numBlocks; i++) {
      NodeType type = nodes.get(i).type;
      if (type == NodeType.NINODE
          || type == NodeType.NITRISHAPE
          || type == NodeType.BSINVMARKER
          || type == NodeType.BSBEHAVIORGRAPHEXTRADATA) {
        Node n = nodes.get(i);
        int stringIndex = n.data.getInts(0, 4)[0];
        n.title = strings.get(stringIndex);
        if (SPGlobal.debugNIFimport && SPGlobal.logging()) {
          SPGlobal.log(
              header, "  [" + i + "]: " + nodes.get(i).type + ", string: " + nodes.get(i).title);
        }
      }
    }
  }