Comments (9)
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.
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.
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.
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.
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.
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.
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.
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.
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:
- Run the generator.
- Update your C# code to use the generated API.
- 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)
- Implement .wgc HOT 6
- Value '3' is not defined for enum of type ObjectDataFormatVersion HOT 2
- Issues with exporting to .json HOT 5
- Cannot cast Char to Tileset & anything to enum really HOT 4
- Invalid Cast Exception (Imported BLPs) HOT 6
- Unable to parse value '0.15' HOT 3
- 'Value '6115' is not defined for enum of type EditorVersion.' HOT 1
- Compiler can crash rather than offering error message HOT 1
- Map builder broken HOT 2
- All destructible on compiled maps are duplicated HOT 8
- MapBuilder method 'AddFiles' fails to add files correctly. HOT 1
- Update .w3i Info file parser HOT 5
- Map.Open does not read object names or tooltips HOT 3
- Editing custom tile pathing HOT 2
- War3 Server HOT 1
- Is it possible to build a Map as a folder instead of a .w3x file? HOT 2
- Zopfli Compression HOT 2
- Expose more should be internal API to become public HOT 2
- What's the difference between Field/LevelField/ArrayLevelField?
- OpenFile() in MpqArchive seems to keep file handle open even when calling Close/Dispose HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from war3net.