Coder Social home page Coder Social logo

Comments (9)

Drake53 avatar Drake53 commented on August 22, 2024

You can define your own lua API to gain access to the rect variable. Currently there's no built-in way to automatically generate this API, so you either have to define it manually, or write your own generator (using the data from MapRegions).

The API would look something like this:

/// @CSharpLua.Template = "gg_rct_Spawn1Reg"
public static rect Spawn1Reg;

from war3net.

Bia10 avatar Bia10 commented on August 22, 2024

oh i see so to get this straight....

the war3net api knows what a region is, knows how to read it from .w3r, however this information is not parsed on build by default and as such the template doesn't known about it.

from war3net.

Drake53 avatar Drake53 commented on August 22, 2024

The .w3r does get parsed on build in order to generate the gg_rct variables. You just need to generate some extra code to access them from C#.

from war3net.

Bia10 avatar Bia10 commented on August 22, 2024

could you please show how to access the data which are parsed during build?

i build generator doing parsing myself and it works but i am clueless how i access the data obtained during build

from war3net.

Drake53 avatar Drake53 commented on August 22, 2024

Since we're talking about generating C# code, you generally don't want to do this during build, but if you do not know what file is used during build, you can still choose to do so. If you already know what .w3r file is used, you may want to create a new Exe project for this.

To get the file used by build (note that the war3map.lua script is already compiled at this point):

mapBuilder.OnArchiveBuilding += (s, e) =>
{
    var mapRegionsFile = e.MpqFiles.Single(file => file.Name == MpqHash.GetHashedFileName(MapRegions.FileName));
    var mapRegions = MapRegions.Parse(mapRegionsFile.MpqStream);
}

from war3net.

Bia10 avatar Bia10 commented on August 22, 2024

Since we're talking about generating C# code, you generally don't want to do this during build, but if you do not know what file is used during build, you can still choose to do so. If you already know what .w3r file is used, you may want to create a new Exe project for this.

I don't understand why things have to be so complicated could you explain why you reason as such?

To get the file used by build (note that the war3map.lua script is already compiled at this point):

mapBuilder.OnArchiveBuilding += (s, e) =>
{
    var mapRegionsFile = e.MpqFiles.Single(file => file.Name == MpqHash.GetHashedFileName(MapRegions.FileName));
    var mapRegions = MapRegions.Parse(mapRegionsFile.MpqStream);
}

MpqFile knowns nothing about MpqStream neither does MpqStream accepts MpqFile as first argument

from war3net.

Drake53 avatar Drake53 commented on August 22, 2024

I implemented a generator here: https://github.com/Drake53/War3Map.RegionsTest

The problem with MpqFile is that War3Net.Build also uses old versions of War3Net.Build.Core and War3Net.IO.Mpq, so I created a new project that uses the latest version of War3Net.Build.Core.

The generator will create a file "Regions.cs" in the War3Map.Template.Generated project.

The only thing you need to change is the path to the .w3r file. If the file is inside a .w3m or .w3x file, you must change:

var mapRegionsPath = ""; // TODO
using var mapRegionsFileStream = File.OpenRead(mapRegionsPath);

to:

var mapArchivePath = ""; // TODO
using var mapRegionsFileStream = MpqFile.OpenRead(Path.Combine(mapArchivePath, MapRegions.FileName));

from war3net.

Bia10 avatar Bia10 commented on August 22, 2024

Thanks ill try it later,

However my confusion still remains why cannot the generation of constants/custom units/regions etc.. happen at build time?

What are the reasons it has to separate from build? If the data from regions were obtained during build why would I have to access the region file yet again after build?

I simply don't understand the reasoning behind the priorities of the build process, why build first and generate constants later? Why is not build and generate constants at same time possible?

from war3net.

Drake53 avatar Drake53 commented on August 22, 2024

In theory it is possible to do at build time, but right now it's not possible because War3Net.Build package is outdated, so you cannot use the latest versions of other packages it depends on.

What you need to understand is that there are two ways to handle the data from .w3r (and other) files:

  • Build/Compile: Create the regions as lua variables for the war3map.lua file;
  • Generator: Create the regions as C# variables for the C# API (using CSharpLua.Template to reference the lua variables).

It's not practical to perform these two steps at the same time, because if you don't know what the generated API looks like, you cannot use it, so if you immediately build/compile after generating the API, then you might as well skip the generator step.

It's more practical to have a third step:

  1. Run the generator.
  2. Update your C# code to use the generated API.
  3. Build/Compile.

It sounds like you want to combine step 1 and 3, because in this case you already know what the generated API will look like (gg_rct_Spawn1Reg variable will be created), so you do step 2 first. However, if you try to use this variable before running the generator, you'll get an error in visual studio because the variable does not exist yet, so in my opinion it's more convenient to do step 1 first.

EDIT: I updated the example project. Regions are only created in lua if the region has weather effect or sound effect. If the region has neither, the variable must be created in C#.

from war3net.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.