Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unity SDK: codegen to generate "enums" from .ts to .cs #144

Merged
merged 12 commits into from
Dec 27, 2022

Conversation

lpsandaruwan
Copy link
Contributor

@endel
Copy link
Member

endel commented Dec 12, 2022

Hi @lpsandaruwan, thanks for the PR! I've just tried your branch and giving you some feedback below:

I did compiled the repo (npm run build), and used the following command to generate the output for the Enums.ts file you've created:

./bin/schema-codegen test/codegen/sources/Enums.ts --csharp --output codegen/enum/

I noticed the generated codegen/enum/ShipType.cs file had incorrect types and values:

public struct ShipType {
	public const string Transport = undefined;
	public const string Miner = undefined;
	public const string Colonizer = undefined;
}

The expected output for ShipType would be:

public struct ShipType {
	public const int Transport = 0;
	public const int Miner = 1;
	public const int Colonizer = 2;
}

The MessageType had the correct types and values:

public struct MessageType {
	public const string DeployMiner = "deploy-miner";
	public const string ColonizePlanet = "colonize-planet";
}

Lastly, I've tried adding another enum declaration on Enums.ts file (with fixed values rather than inferred as ShipType is)

export enum ShipType {/* ... */}
export enum MessageType {/* ... */}

export enum FixedValueEnum {
    One = 1,
    Two = 2,
    Three = 3,
}

After running schema-codegen again, the FixedValueEnum did not get generated, but their fields got appended to the MessageType structure:

public struct MessageType {

	public const string DeployMiner = "deploy-miner";
	public const string ColonizePlanet = "colonize-planet";
	public const string One = 1;
	public const string Two = 2;
	public const string Three = 3;
}

On this case, it should've defined a FixedValueEnum file with the contents:

public struct FixedValueEnum {
	public const int One = 1;
	public const int Two = 2;
	public const int Three = 3;
}

Please let me know if you have any question, happy to discuss them! Cheers

@endel endel merged commit 6280055 into colyseus:master Dec 27, 2022
endel added a commit that referenced this pull request Dec 27, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants