Noel Berry

@noelfb
4.8K Followers
159 Following
523 Posts
sometimes, when i'm in the right mood, i make video games and art. created Celeste with friends, making new games with more friends. he/him
websitehttps://noelberry.ca
exokhttps://exok.com
Experimenting with the idea of running save files on the title screen for very smooth game-loading ...
I guess the "correct" thing to do is just not let instances hold a reference to their owner... but when I'm working on small projects it's often way, way simpler to be able to do that and I don't care about perfect data/control flow. I just want my objects created fully by the constructor!

You can create a pattern where child implementations just aren't supposed to do anything until an "OnAdded" is called, but that messes up readonly members and also makes it so they need to "cache" constructor arguments to be used later.

In C++ you could get around this with templates (pseudo code, can't remember syntax)

void Add<T>(constructor params) => children.Add(new T(this, constructor params));

and it wouldn't compile if you mess up the expected parameters. I kind of want that in C#.

I frequently have a design problem in C# where I want to instantiate objects with their data complete, but they also need to reference their owner for ease-of-use. But then the pattern ends up being ugly, like:

UI.Add(new Button(UI, "Confirm"));

Where that first argument is redundant + error-prone.

You can delay the assignment, so the Add method assigns the owner (ex. itemBeingAdded.UI = this) but then the child doesn't have the owner until after its constructor.

unlocking new areas in City of None
Copy native libs in a local C# project

Copy native libs in a local C# project. GitHub Gist: instantly share code, notes, and snippets.

Gist
Do any C# experts have an answer to this? I'm simply trying to copy native runtime libraries to the bin in a local project, but it seems impossible to do correctly: https://gist.github.com/NoelFB/7866db82e4e417da62e8440495e4a0ac
Copy native libs in a local C# project

Copy native libs in a local C# project. GitHub Gist: instantly share code, notes, and snippets.

Gist
experimenting with a new enemy in City of None ...

(haven't done the creature art yet, not sure what it's gonna look like)
it's kinda fun zooming all the way out on big screens while editing
experimenting with a radial menu 🤔 (among other things, in https://cityofnone.com/)