Skip to content

Add Drop Target Bank support#333

Merged
freezy merged 19 commits into
masterfrom
mech-drop-target
Oct 26, 2021
Merged

Add Drop Target Bank support#333
freezy merged 19 commits into
masterfrom
mech-drop-target

Conversation

@jsm174
Copy link
Copy Markdown
Collaborator

@jsm174 jsm174 commented Oct 24, 2021

This PR allows for a Drop Target Bank component to be added to the table.

Basically it adds support for a reset coil and selecting the drop targets that are in the bank.

The runtime inspector has some other neat features such as dropping and resetting the targets, monitoring the reset coil and switches.

A few things are left to do on this PR:

  • Figure out why when adding a DropTargetBank from the Toolbox, it creates additional ones with the same "DropTargetBank1" name,
  • Linking Drop Target Names to the DropTargetData
  • Link BankSize to the DropTargetData
  • Create and Replace Drop Target Bank Icons (@freezy I think can auto generate from svg?)
  • Figure out better way to access switch status other than faking with IsDropped
  • Add test cases for DropTargetData

@codecov
Copy link
Copy Markdown

codecov Bot commented Oct 24, 2021

Codecov Report

Merging #333 (1b168af) into master (67aca1d) will not change coverage.
The diff coverage is n/a.

Impacted file tree graph

@@           Coverage Diff           @@
##           master     #333   +/-   ##
=======================================
  Coverage   83.43%   83.43%           
=======================================
  Files         125      125           
  Lines        6736     6736           
=======================================
  Hits         5620     5620           
  Misses       1116     1116           
Impacted Files Coverage Δ
...Pinball.Engine/VPT/Flipper/FlipperMeshGenerator.cs 98.09% <ø> (ø)
VisualPinball.Engine/VPT/Light/Light.cs 58.82% <ø> (ø)
...all.Engine/VPT/Primitive/PrimitiveMeshGenerator.cs 97.56% <ø> (ø)
...Pinball.Engine/VPT/Surface/SurfaceMeshGenerator.cs 95.45% <ø> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 46f27fe...1b168af. Read the comment docs.

Copy link
Copy Markdown
Owner

@freezy freezy left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Awesome! As discussed, no data and item classes necessary for stuff that doesn't come from VPX.

Here a few more TODO items:

  • Remove .DS_Store and preferably add them to .gitignore as well :)
  • Add a documentation page

I haven't tested it yet, but will soon once I'm done with the teleporter.

Comment thread VisualPinball.Engine/VPT/DropTargetBank/DropTargetBank.cs Outdated
Comment thread VisualPinball.Engine/VPT/DropTargetBank/DropTargetBankData.cs Outdated
Comment thread VisualPinball.Engine/VPT/Table/TableContainer.cs Outdated
Comment thread VisualPinball.Engine/VPT/ItemType.cs Outdated
Comment thread VisualPinball.Unity/VisualPinball.Unity.Editor/Import/VpxSceneConverter.cs Outdated
Comment thread VisualPinball.Unity/VisualPinball.Unity/VPT/HitTarget/DropTargetApi.cs Outdated
Comment thread VisualPinball.Unity/VisualPinball.Unity/VPT/HitTarget/DropTargetApi.cs Outdated
@jsm174 jsm174 force-pushed the mech-drop-target branch 4 times, most recently from 0c96bb3 to 21957d7 Compare October 25, 2021 00:11
Comment thread VisualPinball.Unity/VisualPinball.Unity.Patcher/Patcher/Tables/Terminator2.cs Outdated
Comment thread VisualPinball.Unity/VisualPinball.Unity.Patcher/Matcher/TablePatcher.cs Outdated
Comment thread VisualPinball.Unity/VisualPinball.Unity/VPT/IApi.cs Outdated
Comment thread VisualPinball.Unity/VisualPinball.Unity/VPT/ItemApi.cs Outdated
@jsm174
Copy link
Copy Markdown
Collaborator Author

jsm174 commented Oct 25, 2021

@freezy - thoughts on this?

I want to generate a unique name for the prefabs. Instead of DropTargetBank, DropTargetBank, etc.

This works, but can it be better:

if (CreateButton("Drop Target\nBank", Icons.DropTargetBank(color: iconColor), iconSize, buttonStyle))
{
	CreatePrefab<DropTargetBankComponent>("Drop Target Banks", "Prefabs/DropTargetBank");
}

public string GetNewPrefabName<T>(Dictionary<string, T> dict, string prefix)
{
	var n = 0;
	do
	{
		var elementName = $"{prefix}{++n}";
		if (!dict.ContainsKey(elementName.ToLower()))
		{
			return elementName;
		}
	} while (true);
}

private void CreatePrefab<T>(string groupName, string path)
{
	var converter = new VpxSceneConverter(TableComponent);
	TableComponent.TableContainer.Refresh();

	var itemDictionary = new Dictionary<string, T>();

	foreach (var component in TableComponent.GetComponentsInChildren<T>())
	{
		if (component is Component)
		{
			itemDictionary.Add((component as Component).name.ToLower(), component);
		}
	}

	var parentGo = converter.GetGroupParent(groupName);

	var prefab = Resources.Load<GameObject>(path);
	var go = PrefabUtility.InstantiatePrefab(prefab) as GameObject;

	if (go) {
		go.transform.SetParent(parentGo.transform, false);
	}

	go.name = GetNewPrefabName(itemDictionary, go.name);

	Selection.activeGameObject = go;
}

@freezy
Copy link
Copy Markdown
Owner

freezy commented Oct 25, 2021

Yeah, that's more or less what I'm doing in TableContainer.GetNewName<T>(string prefix) too. However, I would restrict T as where T : Component so you don't need to cast. Also, your GetNewPrefabName() should go into the if (go) block above, no?

@jsm174
Copy link
Copy Markdown
Collaborator Author

jsm174 commented Oct 25, 2021

Yeah, that's more or less what I'm doing in TableContainer.GetNewName<T>(string prefix) too. However, I would restrict T as where T : Component so you don't need to cast. Also, your GetNewPrefabName() should go into the if (go) block above, no?

Awesome. Yeh, still trying to understand some of the advanced C# stuff.

I'll commit the updates later, and then I think all that's left is documentation!

@jsm174
Copy link
Copy Markdown
Collaborator Author

jsm174 commented Oct 25, 2021

Yeah, that's more or less what I'm doing in TableContainer.GetNewName<T>(string prefix) too. However, I would restrict T as where T : Component so you don't need to cast. Also, your GetNewPrefabName() should go into the if (go) block above, no?

done!

Comment thread VisualPinball.Unity/VisualPinball.Unity.Patcher/Matcher/TablePatcher.cs Outdated
@freezy freezy merged commit bde3d72 into master Oct 26, 2021
@freezy freezy deleted the mech-drop-target branch October 26, 2021 20:53
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.

2 participants