Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[3D] Added option to Game View Editor SpawnContextMenu #185

Merged
merged 1 commit into from
Jul 5, 2023

Conversation

sili3011
Copy link
Contributor

to save positional and rotational changes of SpawnInstances to database.

Use case
Making changes to position and/or rotation of creatures or gameobjects in the Game View Editor and saving those changes to the database.

Previous workflow:
Selecting spawn in game view, modifying it, opening the table with double click on spawn and typing changed values by hand into the form.

image

Workflow is tedious and error prone.

New workflow:
Selecting spawn in game view, modifying it, right click anywhere and select option "Update values".

image


CopyGuidCommand = new DelegateCommand<SpawnInstance>(inst => clipboardService.SetText(inst.Guid.ToString()));
CopyPositionXCommand = new DelegateCommand<SpawnInstance>(inst => clipboardService.SetText(inst.WorldObject!.Position.X.ToString()));
Copy link
Owner

Choose a reason for hiding this comment

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

I wonder, is it worth to have this as three separate menu items instead of one "Copy Position" which would copy comma separated values? x, y, z Just wondering, if it is better to have them separate I am fine I guess.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Before implementing the "Update values" option i just had a copy option for all the values that needed updating, so I could just click "Copy foo", open DB Table Editor, and paste the copied value into the column foo. I deleted most of the options as those got obsolete because of the new "Update values", but figured the positions could still be useful to keep. I think you are right, combining them, now that there is the new save option, is probably the way to go.

@@ -74,7 +74,7 @@ public override Quaternion GetRotation(SpawnInstance item)
if (item is CreatureSpawnInstance cr)
return Quaternion.CreateFromAxisAngle(Vectors.Up, cr.Creature!.Orientation);
else if (item is GameObjectSpawnInstance go)
return go.GameObject!.Rotation;
return Quaternion.CreateFromAxisAngle(Vectors.Up, go.GameObject!.Orientation);
Copy link
Owner

@BAndysc BAndysc Jun 18, 2023

Choose a reason for hiding this comment

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

gameobjects can be rotated in all axes, why this change? (in the editor you press R for rotation, then X/Y/Z depending on the axis you want to rotate around)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah, this is a weird one and probably needs some testing. When i spawned my first few gameobjects and tried rotating them I didnt get the same results in game as in the editor. Then i found out that gameobject (just like creature) has also orientation and started using that, despite of course losing two axis. But I know what you mean, from a logic stand point this doesnt make sense, but it works. Will test some more and go back to inital implementation once its working how its supposed to.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

So there is something different in how the GameView renders some things and I think this i due to rotation parameters, but I cant put my finger where and why and I also kinda dont care enough :D this only happens when hand modifying some rotation values in isolation.

Game View Editor:

image

In game:

image

As you can see gameobjects can get stretched/squished, game seems to make sure that no matter the rotational values the gameobject always has the right proportions.

As this has nothing to do with my "fix" I reverted back to your initial implementation

ISpawnSelectionService spawnSelectionService,
IClipboardService clipboardService,
ITableEditorPickerService tableEditorPickerService,
IDatabaseQueryExecutor mySqlExecutor,
Copy link
Owner

Choose a reason for hiding this comment

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

I think here I'd use IMySqlExecutor instead of IDatabaseQueryExecutor, those are bad names I can see now...
IMySqlExecutor - executes queries on the world database
IMySqlHotfixExecutor - executes queries on the hotfixes database
IDatabaseQueryExecutor - has additional parameter which determines if the query should be executed in the world database or hotfixes database.

I can see why you chose the IDatabaseQueryExecutor here, however the intention was to keep IDatabaseQueryExecutor only for the WDE.DatabaseEditors project. While database structure varies between different wow core, I think we can safely assume that creatures/gameobjects tables will be always in the world database.


var typeString = creature != null ? "creature" : "gameobject";

trans.Table(typeString).InsertIgnore(new { Guid = inst.Guid });
Copy link
Owner

Choose a reason for hiding this comment

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

I think it is not a good idea to have an insert query here, this could insert an invalid row to the database (no creature entry, no phasemask, no spawnmask), beside you can only edit existing objects now, so probably better to remove it for now.

});
UpdateValuesCommand = new DelegateCommand<SpawnInstance>(async (inst) =>
{
var trans = Queries.BeginTransaction();
Copy link
Owner

Choose a reason for hiding this comment

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

Very good job on finding and using the syntax for writing SQL queries! :D

However, as you said, compatibility with different cores is a question. In case of creature/gameobject position I think the db structure is the same, but... there is a way of writing core-independent queries in the editor.

There is no code for generating core-independent update position query, but let me show how it works for other query - updating quest chaining.

IQueryGenerator<QuestChainDiff> queryGenerator; // get via constructor
var query = queryGenerator.Update(new QuestChainDiff() {
     Id = 1235,
     PrevQuestId = 1,
     NextQuestId = 2
});
mysqlExecutor.Execute(query);

how it works underneath: there are two implementations for IUpdateQueryProvider<QuestChainDiff>: TrinityQuestQueryProvider MangosQuestQueryProvider, which generate query like you generate it here.

So it would be great if you could create CreatureSpawnModelDiff struct with an entry, guid, positions, orientations, create a class CreatureUpdateQueryProvider : IUpdateQueryProvider<CreatureSpawnModelDiff>, and in SpawnContextMenu use IQueryGenerator<CreatureSpawnModelDiff>. (note: there is already a CreatureSpawnModelEssentials struct which is used by query generator for insert and delete, but it is not really suitable for updating as its fields are not nullable

This way we can write integrations test for query generators (look at DatabaseTester/QueryGeneratorTester.cs for existing tests).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I actually got the general gist of how to do it from TrinityQuestQueryProvider but didnt think that far that this of course also provides the opportunity to do a core-independant implementation. Thanks for pointing that out, I ll try adding that!

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done! Hope its to your liking. As far as I can see cmangos uses the same column names as trinity creature gameobject.

Copy link
Owner

@BAndysc BAndysc left a comment

Choose a reason for hiding this comment

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

Thank you for the contribution! I can see you grasped how the code works really fast! I've added few comments, it would be great if you could take a look at them.

…onal and rotational changes of SpawnInstances to database
Copy link
Owner

@BAndysc BAndysc left a comment

Choose a reason for hiding this comment

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

Sorry for the delay and thanks for the PR, merged! A small thing, I will split PositionRotationDiff into CreatureDiff and GameobjectDiff in a separate commit.

@BAndysc BAndysc merged commit e1f76c9 into BAndysc:master Jul 5, 2023
1 check failed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
2 participants