npetrovski / l2js-client

JavaScript client for Lineage 2
MIT License
105 stars 34 forks source link

refactor: remove GlobalEvents instance #41

Closed neo279 closed 2 years ago

neo279 commented 2 years ago

This PR solves issue with multiple clients in single process as it removes shared EventEmitter.

TODO:

Closes #27

npetrovski commented 2 years ago

Regarding the question for using node.js EventEmitter - I would say lets try to keep l2js-client as much as possible closer to what we have already implemented with the browsers. We can try to integrate a a polyfill wrapper, and if no native EventEmitter is available, we use the current one.

neo279 commented 2 years ago

@npetrovski I made it to work, can you review this carefully? I have tested this with move example successfully, including StartMoving event.

import l2, {clientFactory} from "./login";

const l2_2 = clientFactory({Username: "neo200"});

l2.on("LoggedIn", () => {
  console.log("client 1 in game")

  l2.on("StartMoving", () => {
    console.log("client 1 move")
  });
  const x = 50 + Math.floor(Math.random() * 50) + l2.Me.X;
  const y = 50 + Math.floor(Math.random() * 50) + l2.Me.Y;
  const z = l2.Me.Z;
  l2.moveTo(x, y, z);
});

l2_2.on("LoggedIn", () => {
  console.log("client 2 in game")
  l2_2.on("StartMoving", () => {
    console.log("client 2 move")
  });
  const x = 50 + Math.floor(Math.random() * 50) + l2_2.Me.X;
  const y = 50 + Math.floor(Math.random() * 50) + l2_2.Me.Y;
  const z = l2_2.Me.Z;
  l2_2.moveTo(x, y, z);
});

PS: It would be best to review the changes without the last commit as it changes unnecessary.

npetrovski commented 2 years ago

Very good job indeed - just few minor comments were added for fixing.

Regarding the code-style. Could you please share your exact VSC configuration.

I have mine with the following plugins installed:

ESLint 2.2.2 TSLint 1.3.3 Prettier - Code formatter 9.0.0 Prettier - ESLint 3.0.4

along with the workspace configuration like that:

{
  "editor.defaultFormatter": "esbenp.prettier-vscode",
  "editor.formatOnPaste": false,
  "editor.formatOnSave": true,
  "editor.codeActionsOnSave": {
    "source.fixAll.eslint": true
  },
  "eslint.format.enable": true,
  "eslint.validate": ["javascript"]
}
neo279 commented 2 years ago

Very good job indeed - just few minor comments were added for fixing.

Regarding the code-style. Could you please share your exact VSC configuration.

I have mine with the following plugins installed:

ESLint 2.2.2 TSLint 1.3.3 Prettier - Code formatter 9.0.0 Prettier - ESLint 3.0.4

along with the workspace configuration like that:

{
  "editor.defaultFormatter": "esbenp.prettier-vscode",
  "editor.formatOnPaste": false,
  "editor.formatOnSave": true,
  "editor.codeActionsOnSave": {
    "source.fixAll.eslint": true
  },
  "eslint.format.enable": true,
  "eslint.validate": ["javascript"]
}

Thank you!

I don't use VSCode for formatting, instead I use cli tools preferably with git precommit hooks. There is nice tool to do that https://pre-commit.com/.

We could come up with some standard for this project that would have configuration stored in the repository, so we can run cli tools, have npm scripts for it and also git pre-commit hooks ;)

alois-git commented 2 years ago

Can we merge that into the interlude branch ?