Re-generating assets for Flame Game with Very Good Ventures template - flutter

So I'm building a Flame Game, and I found this template (the actual code that comes with the template is here) made by Very Good Ventures (it's the one used in the Pinball project made for Google I/O).
I'm just writing my code, and added my assets in the assets/ folder, so far I only need images so I deleted all the other assets that came with the template and the unnecessary folders. Thing is, I don't know how to re-generate the gen/assets.gen.dart file to reflect the changes I've made to the assets/ directory. I've tried running my app but I obviously get an error because the assets I'm trying to load are not defined.
I tried to look up what command is needed to regenerate the assets file, and most solutions I found included this line of code which requires the build_runner, flutter_gen and flutter_gen_runner dependencies.
Now, I don't mind adding new libraries if necessary, but if they are needed, shouldn't those be in the pubspec.yaml of the template to begin with? I even checked the Pinball project repo to see if they had to add those dependencies and their pubspec.yaml does not include any of the runners or flutter_gen.
Anyway, I still tried adding the libraries and running the command flutter packages pub run build_runner build, which manages to regenerate the assets.gen.dart file to include my images and delete unnecessary directories but I still get an error.
When I do
loadSprite(Assets.images.ramp.path);
(just like they do in the VGV template), I get a red screen error because apparently Assets.images.ramp.path gets evaluated to assets/images/assets/images/ramp.png (there's an extra assets/images/).
After checking the assets.gen.dart file it seems like the VGV template creates the class AssetGenImage extends AssetImage while the flutter packages ... command creates an AssetGenImage that doesn't extend AssetImage.
I'm pretty sure I'm missing something here, because both the VGV template and the I/O pinball project manage to regenerate the assets files without issue. I just don't really know what I'm supposed to be doing.
(just in case, I have not changed anything else in the pubspec.yaml apart from removing the lines that pointed to the other assets directories I didn't need like assets/audio/ and adding the 3 new dependencies)

so you are probably getting this error because Flame by default adds a the assets/images/ prefix path on its image loading code.
That is why on your error, you are seeing that part duplicated.
To properly use flutter gen, which generates the full path of the assets, you can simply "clear that prefix", which you can do just by doing so on your game class, you can do this as the first line of your onLoad method
images.prefix = '';

Related

How to exclude files from compilation in flutter?

I have a project that builds several similar apps, different apps require different resources. I have folder assets/images_project1 and images/project2. How can I exclude e.g. images/project2 from the compilation? I don't want to manually replace the folders every time. If files still, they increase the app size
According to this there is no built-in solution as of right now.
But the easiest thing to do is just manually comment folder in pubspec.yaml under the assets section.
Optionally you can use script from the mentioned question.

Unknown Type Errors when using functionblocks from my own library project

So I have a library project where I defined a couple of functionblocks and interfaces.
Now I want to use this library in a plc project (in the same twincat solution). So I do the whole save all, rebuild, save and install as a library spiel. If I try to declare a VAR in my MAIN it will result in unknown type errors. I have fiddled around a bit, and when I declare an interface withouth any properties or methods (in the lib) then I it does show up and can be used in the MAIN. But as soon as I add a property or method the class/FB/POU dissapears in the eyes of my MAIN...
I feel like I'm overlooking some option / atribute to help the PLC project to use the lib properly...
What am I missing here?
EDIT:
as you can see in the images, empty blocks are found, adding anything magically makes it dissapear
error
available classes
EDIT 2:
I solved my problem by copying the lib to a new solution. Something in the original project made it be broken. Why it did that is still a mystery...
Try following steps:
clean the solution where you programmed the library.
right click on the project and click check all objects
if this is successfull, install the library again, remove it from the reference section and re-add it.
Then clean again and build all.

When I create a flutter-plugin project,I can't find flutter

So I add flutter as library like this:
Should I delete these when I finished my plugin?
You are free (and actually there's nothing wrong about it) to add the flutter lib to your build.gradle. However keep a few things in mind:
I strongly advise you to add that folder (libs.android-arm) to your .gitignore (you don't want to upload or keep track of it).
You must remove/comment that line otherwise it won't build in other machines since that will reference a lib/path that doesn't exist.

A weird phenomenon in Ember-CLI dist/, I cannot modify anything inside it

In my Ember-cli project, I put some static assets, such as images and icons into the /dist/static/image directory. Then I build the project (I forgot the details in this part).
Then when I tried to modified some picture inside that folder (I wanted to change some parts to be transparent), I found that I cannot change anything inside.
For example, when I used a new pic to replace the old one, and then I run ember, I found that the new pic was replaced by the old one automatically.
I am not so sure about the internal mechanism, and I tried to use git, but that didn’t help.
/dist is just that - it gets wiped out on each build and reloaded with the distributable files. What you are looking for is /public

subfolders in iPhone localization folders

I would like to localize some images in my iPhone project. So I created files:
en.lproj/Images/iPad/btn-check-pressed~ipad.png
en.lproj/Images/iPadRetina/btn-check-pressed#2x~ipad.png
ru.lproj/Images/iPad/btn-check-pressed~ipad.png
ru.lproj/Images/iPadRetina/btn-check-pressed#2x~ipad.png
and so on and added them to my project. But Xcode shows "English 0 files localized", "Russian 0 files localized" in Localizations list.
It also shows a warning
Warning: Multiple build commands for output file /Users/User/Library/Developer/Xcode/DerivedData/TestLocalizationDefaultPNG-ckplzmcjurofxrccjuvyzjaqketc/Build/Products/Debug-iphonesimulator/TestLocalizationDefaultPNG.app/btn-check-pressed~ipad.png
for each of my files when I try to build the project. So, as far as I understand, it copies all files in one folder, and since my files have the same names - only one of them can survive. But, if I remove my subfolders:
en.lproj/btn-check-pressed~ipad.png
en.lproj/btn-check-pressed#2x~ipad.png
ru.lproj/btn-check-pressed~ipad.png
ru.lproj/btn-check-pressed#2x~ipad.png
everything works fine.
Is there is a way to keep subfolders? Here http://developer.apple.com/library/ios/#documentation/CoreFoundation/Conceptual/CFBundles/BundleTypes/BundleTypes.html in Listing 2-4 subfolder used for the audio files, so it should be.
It looks like the only way localization works in iOS is different. You base folders hierarchy should be by inverted: first goes actual folders structure and in each and every folder you want to localize, you put corresponding .lproj sub-folder with localized resources. So in your example it should be something like:
/Images
/iPad
/en.lproj
btn-check-pressed~ipad.png
/ru.lproj
btn-check-pressed~ipad.png
/iPadRetina
/en.lproj
btn-check-pressed#2x~ipad.png
/ru.lproj
btn-check-pressed#2x~ipad.png
This might be sub-optimal if you intended to have big hierarchy but this is the only way it works out of the box.
Of course you can always say that you don't need Xcode support and use some custom build rules to re-arrange files in you project in the way you like and then copy them into proper structure during build but I doubt it worths troubles.
Update: it looks like XCode (4.5) build script is the main villain.
According to my experiments build script should flattens resources structure at least for images. So the only way localized app can be inside is:
/YourApp
YouApp
info.plist
....
/en.lproj
btn-check-pressed~ipad.png
btn-check-pressed#2x~ipad.png
/ru.lproj
btn-check-pressed~ipad.png
btn-check-pressed#2x~ipad.png
The trick is that by default XCode (as of version 4.5) can flatten your project structure only if it is as described above and I don't see a standard way to change this behavior.
Of course, original comment about custom build scripts is still true.