Skip to content

Commit

Permalink
Fix Rust wasm loading in node tools, bump extra.crg1_arc, fix some ty…
Browse files Browse the repository at this point in the history
…pe errors
  • Loading branch information
magcius committed Oct 24, 2024
1 parent d1c23ff commit 9d84c00
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 39 deletions.
34 changes: 17 additions & 17 deletions src/Morrowind/tools/NIFParseGen.ts
Original file line number Diff line number Diff line change
Expand Up @@ -590,7 +590,7 @@ class EnumValue {
public name: string;
public value: number;

constructor(context: NifXML, node: Element) {
constructor(context: NifXML, node: dom.Element) {
this.name = node.getAttribute("name")!;
if (node.hasAttribute("value"))
this.value = parseInt(node.getAttribute("value")!);
Expand All @@ -604,13 +604,13 @@ class Enum implements Type {
public storage: Type;
public value: EnumValue[] = [];

constructor(context: NifXML, node: Element) {
constructor(context: NifXML, node: dom.Element) {
this.name = node.getAttribute("name")!;
this.storage = context.getType(node.getAttribute("storage")!);

for (let p = node.firstChild; p !== null; p = p.nextSibling)
if (p.nodeType === p.ELEMENT_NODE && p.nodeName === "option")
this.value.push(new EnumValue(context, p as Element));
this.value.push(new EnumValue(context, p as dom.Element));
}

public generateBody(): string {
Expand Down Expand Up @@ -639,7 +639,7 @@ class BitfieldMember {

public memberName: string;

constructor(context: NifXML, node: Element) {
constructor(context: NifXML, node: dom.Element) {
this.name = node.getAttribute("name")!;
this.pos = parseInt(node.getAttribute("pos")!);
this.width = parseInt(node.getAttribute("width")!);
Expand All @@ -655,15 +655,15 @@ class Bitfield extends ClassType {
public storage: Type;
public member: BitfieldMember[] = [];

constructor(context: NifXML, node: Element) {
constructor(context: NifXML, node: dom.Element) {
super();

this.name = node.getAttribute("name")!;
this.storage = context.getType(node.getAttribute("storage")!);

for (let p = node.firstChild; p !== null; p = p.nextSibling)
if (p.nodeType === p.ELEMENT_NODE && p.nodeName === "member")
this.member.push(new BitfieldMember(context, p as Element));
this.member.push(new BitfieldMember(context, p as dom.Element));
}

public generateBody(context: NifXML): string {
Expand Down Expand Up @@ -731,7 +731,7 @@ class StructField {
public runtimeCheckCond = false;
public runtimeCheckVerCond = false;

constructor(context: NifXML, node: Element, public parentStruct: Struct) {
constructor(context: NifXML, node: dom.Element, public parentStruct: Struct) {
this.rawName = assertExists(node.getAttribute('name'));
this.rawType = assertExists(node.getAttribute('type'));
this.rawDefault = fixEmpty(node.getAttribute('default'));
Expand Down Expand Up @@ -892,17 +892,17 @@ class Struct extends ClassType {
public fields: StructField[] = [];
public isNiObject = false;

constructor(private context: NifXML, private node: Element) {
constructor(private context: NifXML, private node: dom.Element) {
super();

this.name = assertExists(node.getAttribute(`name`));
this.rawInherit = fixEmpty(node.getAttribute(`inherit`));
this.generic = node.getAttribute("generic") === "true";
this.isNiObject = node.nodeName === "niobject";

for (let p: Node | null = node.firstChild; p !== null; p = p.nextSibling)
for (let p: dom.Node | null = node.firstChild; p !== null; p = p.nextSibling)
if (p.nodeName === "field")
this.fields.push(new StructField(context, p as Element, this));
this.fields.push(new StructField(context, p as dom.Element, this));
}

public resolve(context: NifXML): void {
Expand Down Expand Up @@ -1044,7 +1044,7 @@ class NifXML {

const str = readFileSync(filePath, { encoding: 'utf8' });
const parser = new dom.DOMParser();
const doc = parser.parseFromString(str);
const doc = parser.parseFromString(str, 'application/xml');
this.parseXML(doc);

this.resolve();
Expand Down Expand Up @@ -1091,7 +1091,7 @@ class NifXML {
return type;
}

private parseElem(p: Element): void {
private parseElem(p: dom.Element): void {
if (p.nodeName === "enum" || p.nodeName === "bitflags") {
const type = new Enum(this, p);
this.registerType(type.name, type);
Expand All @@ -1106,7 +1106,7 @@ class NifXML {
}
}

private parseToken(elem: Element): void {
private parseToken(elem: dom.Element): void {
const name = assertExists(elem.getAttribute("name"));
const attrs = assertExists(elem.getAttribute("attrs")).split(' ');

Expand All @@ -1127,7 +1127,7 @@ class NifXML {
if (p.nodeType !== p.ELEMENT_NODE)
continue;

const c = p as Element;
const c = p as dom.Element;
if (c.nodeName === name) {
const token = assertExists(c.getAttribute("token"));
const string = assertExists(c.getAttribute("string"));
Expand All @@ -1141,12 +1141,12 @@ class NifXML {
return assertExists(this.macroRegistry.get(attr));
}

public parseXML(doc: Document): void {
for (let p = doc.documentElement.firstChild; p !== null; p = p.nextSibling) {
public parseXML(doc: dom.Document): void {
for (let p = doc.documentElement!.firstChild; p !== null; p = p.nextSibling) {
if (p.nodeType !== p.ELEMENT_NODE)
continue;

this.parseElem(p as Element);
this.parseElem(p as dom.Element);
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/ZeldaWindWaker/Main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -814,7 +814,7 @@ class SceneDesc {
modelCache.fetchObjectData(`Always`);
modelCache.fetchStageData(`Stage`);

modelCache.fetchFileData(`extra.crg1_arc`, 8);
modelCache.fetchFileData(`extra.crg1_arc`, 9);
modelCache.fetchFileData(`f_pc_profiles.crg1_arc`);

const particleArchives = [
Expand Down
17 changes: 17 additions & 0 deletions src/rustlib.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,23 @@ import init, * as rust from '../rust/pkg/noclip_support';

export { rust };

declare const process: unknown;

export async function loadRustLib() {
if (typeof process !== 'undefined') {
// XXX(jstpierre): This terrible set of workarounds is required on node because fetch doesn't support file URLs.
// We can't use normal require() because rspack is "smart" and will try to bundle it for web, when I really only
// want this code to run in tools mode on node.js.
// https://github.com/nodejs/undici/issues/2751

const requireX: any = (globalThis as any)['require'];
const fs = requireX('fs');
const path = requireX('path');
const url = requireX('url');
const wasmPath = path.join(path.dirname(url.fileURLToPath(import.meta.url)), '../rust/pkg/noclip_support_bg.wasm');
const wasm = fs.readFileSync(wasmPath);
rust.initSync(wasm);
}

await init();
}
21 changes: 0 additions & 21 deletions tslint.json

This file was deleted.

0 comments on commit 9d84c00

Please sign in to comment.