Notes for Developers 📝
Hello Team,
As we dive into the exciting world of game development with ts-defold, there are a few key points to keep in mind to ensure smooth sailing throughout the development process. Here's a quick rundown:
1. Language Features vs. Runtime APIs
Remember, although you're writing TypeScript, the code won't be executed as TypeScript directly. It will be transpiled to Lua. Therefore, it's crucial to distinguish between language features and runtime APIs. Here are some examples to guide you:
-
Language Feature Example:
[1, 2, 3].forEach((el: number, index: number) => {
// Your code here
});This construct is a language feature and will work similarly in Lua, albeit with some syntactical adjustments.
-
Runtime API Example:
console.log("Hello, world!");The
console.log()function is specific runtimes likenode | bun | browser. In Lua, you'll need to utilizeprint()for similar functionality.
2. Mindful Transpilation
Be mindful of how your TypeScript code translates into Lua during transpilation. While many constructs will carry over smoothly, some may require additional steps or adjustments. Always double-check the Lua output to ensure everything aligns as expected.
3. Guidance and Collaboration
In our development journey, don't hesitate to reach out to Cole whenever uncertainty arises. Whether you're unsure about a particular aspect of the code or need clarification on a concept, Cole is here to help. Asking questions ensures that everyone is on the same page and fosters a collaborative environment.
Additionally, let's prioritize documentation. Ensure that your code is well-documented, and self documenting with detailed variable name and comprehensive documentation files stored in the designated 'docs' folder. Clear documentation not only aids understanding but also facilitates smoother collaboration among team members.
Remember, we're a team, and by seeking guidance and maintaining thorough documentation, we pave the way for remarkable achievements together.
4. Code Style and Clarity
In our quest for clean and maintainable code, let's adhere to the TypeScript style guide:
Camel Case: Embrace camel case for variable names, ensuring consistency and readability throughout the codebase.
Descriptive Variable Names: Don't shy away from long and descriptive variable names reminiscent of Java conventions. Clarity in naming enhances understanding, even if it means sacrificing brevity.
Avoiding Excessive Comments: Consider excessive comments as a code smell. Instead of adding comments to explain complex code, step back and refactor for clarity. Code should be self-explanatory, reducing the need for extensive comments.
Developer Experience (DX) over Performance: Prioritize developer experience over squeezing out performance. While a clever one-liner might seem efficient, consider whether breaking it down into multiple lines would enhance readability and future maintainability.
By embracing these principles, we not only write code that is easier to understand but also set ourselves up for smoother collaboration and future enhancements.
Let's strive for code that speaks for itself and ensures a delightful developer experience for all involved.
5. File structure
project lay out. I like to run a project structure that localizes concerns so like this.
├── defold_project
│ ├── player
│ │ ├── player.go
│ │ ├── player.script
│ │ ├── player.lua
│ │ ├── player.test.lua
│ │ ├── art
│ │ │ ├── img1.png
│ │ │ ├── img2.png
│ │ │ ├── img3.png
│ │ │ ├── player.atlas
├── input
│ ├── game.input_binding
└── .gitignore
with this my *.script file would be as you expect with an init, update and such. my *.lua would then contain the everything with the player (doing this to make testing easier)
Happy coding!