<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Winston</title>
    <description>The latest articles on DEV Community by Winston (@winstonyallow).</description>
    <link>https://dev.to/winstonyallow</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F195130%2F3bda9d91-ecb1-4353-93f1-73e105ec0cff.png</url>
      <title>DEV Community: Winston</title>
      <link>https://dev.to/winstonyallow</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/winstonyallow"/>
    <language>en</language>
    <item>
      <title>Godot Engine: Extendable Editor</title>
      <dc:creator>Winston</dc:creator>
      <pubDate>Mon, 05 Aug 2019 22:47:33 +0000</pubDate>
      <link>https://dev.to/winstonyallow/godot-engine-extendable-editor-5cc3</link>
      <guid>https://dev.to/winstonyallow/godot-engine-extendable-editor-5cc3</guid>
      <description>&lt;p&gt;In this series I want to share a few things that I love about the &lt;a href="https://godotengine.org/"&gt;Godot Game Engine&lt;/a&gt;. Today's post is about extending the editor itself.&lt;/p&gt;

&lt;p&gt;When using open source software I sometimes hear the statement "You can do anything and adjust it to your needs since it is open source". While this may be true, it can be very hard to actually adjust things to fit your needs. However it can also be very easy! Godot is great to extend. You have multiple methods available to adjust it to your needs. It feels like the engine was made with extendability in mind.&lt;/p&gt;

&lt;p&gt;The Godot Editor is basically a game running in the Godot Engine. When you are already familiar with Godot then it is really easy to get started with extending the editor itself.&lt;/p&gt;

&lt;p&gt;There are multiple methods to extend the editor. They range from easy to very complex (but powerful).&lt;/p&gt;

&lt;h2&gt;
  
  
  GDScript Tool Mode
&lt;/h2&gt;

&lt;p&gt;This method is one of the easiest methods to extend the editor. You can add the &lt;code&gt;tool&lt;/code&gt; keyword to the top of any script. Every script with this keyword will not only run in the game but also inside the editor (when a node with that script is in the scene). What you can do with this is a bit limited as the script must be attached to a node in a scene. This method is really useful to create helpers for yourself.&lt;/p&gt;

&lt;p&gt;I use this method quite often to quickly add a preview that updates itself based on some values. Here is a small example from one of my games:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight swift"&gt;&lt;code&gt;&lt;span class="n"&gt;tool&lt;/span&gt;
&lt;span class="n"&gt;extends&lt;/span&gt; &lt;span class="kt"&gt;BaseEnemy&lt;/span&gt;

&lt;span class="nf"&gt;export&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kt"&gt;ENEMY_COLOR&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;var&lt;/span&gt; &lt;span class="nv"&gt;color&lt;/span&gt; &lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="kt"&gt;ENEMY_COLOR&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="kt"&gt;RED&lt;/span&gt; &lt;span class="n"&gt;setget&lt;/span&gt; &lt;span class="n"&gt;set_color&lt;/span&gt;

&lt;span class="kd"&gt;func&lt;/span&gt; &lt;span class="nf"&gt;set_color&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;new_value&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;int&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;
    &lt;span class="n"&gt;color&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;new_value&lt;/span&gt;
    &lt;span class="nf"&gt;set_enemy_sprite&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kt"&gt;SPRITES&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;color&lt;/span&gt;&lt;span class="p"&gt;])&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Here is what the code does: Whenever the enemies &lt;code&gt;color&lt;/code&gt; property is changed the sprite is updated to match the new color. This allows to immediately see the changes you make inside the editor.&lt;/p&gt;

&lt;h2&gt;
  
  
  Plugins in GDScript
&lt;/h2&gt;

&lt;p&gt;Plugins are much more powerful than the toolmode. In contrast to tool scripts they are executed when the editor starts and the plugin is enabled. They are not part of your scenes, instead they run independently inside the editor. Here are a few things you can do with plugins:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Add custom node types&lt;/li&gt;
&lt;li&gt;Add docks and menu items to display custom UI Elements in the editor&lt;/li&gt;
&lt;li&gt;Make a custom importer/exporter for your own format&lt;/li&gt;
&lt;li&gt;Manipulate nodes in the currently edited scene&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;I personally used plugins to create a custom map editor for a game.&lt;/p&gt;

&lt;h2&gt;
  
  
  C++ Modules
&lt;/h2&gt;

&lt;p&gt;This is the most powerful method I have used so far. You can create your own engine modules in C++. Godot uses scons for building. Godots build system and structure makes it relatively easy to add your own modules.&lt;/p&gt;

&lt;p&gt;You can basically access everything with C++. Additionally C++ does run faster than GDScript. In most cases this is not really important. However I ran into two cases where I needed to use C++:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Extending a physics body. GDScript simply wasn't fast enough for my usecase.&lt;/li&gt;
&lt;li&gt;Using thirdparty C++ libraries. I needed methods to operate on graphs (like shortest path, checking if graph is directed, checking if it is acyclic and so on). I didn't want to built this all by myself, so I added a thridparty C++ library as a module.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;It is nice to have this possibility. However for most things GDScript is sufficient.&lt;/p&gt;

&lt;h2&gt;
  
  
  Thank you for reading! ✨
&lt;/h2&gt;

&lt;p&gt;This is the third post in my series "Things I love about Godot". I already have some ideas for the following posts. If you have any questions or suggestions please let me know! If you would like more details or a tutorial regarding a specific aspect feel free to ask.&lt;/p&gt;

</description>
      <category>godot</category>
      <category>godotengine</category>
      <category>gamedev</category>
    </item>
    <item>
      <title>Godot Engine: TSCN</title>
      <dc:creator>Winston</dc:creator>
      <pubDate>Tue, 30 Jul 2019 20:58:20 +0000</pubDate>
      <link>https://dev.to/winstonyallow/godot-engine-tscn-lfb</link>
      <guid>https://dev.to/winstonyallow/godot-engine-tscn-lfb</guid>
      <description>&lt;p&gt;In this series I want to share a few things that I love about the &lt;a href="https://godotengine.org/"&gt;Godot Game Engine&lt;/a&gt;. Today I will write about the TSCN file format.&lt;/p&gt;

&lt;p&gt;In fact this post is not only about the TSCN format. It is about the fact that most file formats in godot are human readable text formats.&lt;/p&gt;

&lt;h2&gt;
  
  
  What is TSCN?
&lt;/h2&gt;

&lt;p&gt;TSCN is the file format used by godot to store scene files. The format is explained very well in the official &lt;a href="https://docs.godotengine.org/en/3.1/development/file_formats/tscn.html"&gt;documentation&lt;/a&gt;. I will not cover these details here.&lt;/p&gt;

&lt;p&gt;It basically is a text file specifying the contents of a scene. It contains the complete node tree of the scene and can also contain subresources.&lt;/p&gt;

&lt;h2&gt;
  
  
  Other files stored as text format
&lt;/h2&gt;

&lt;p&gt;Most things in godot are stored (or can be stored) in plain text:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Resources (&lt;code&gt;.tres&lt;/code&gt; files)&lt;/li&gt;
&lt;li&gt;Project Settings (&lt;code&gt;project.godot&lt;/code&gt; file)&lt;/li&gt;
&lt;li&gt;Import Settings (&lt;code&gt;.import&lt;/code&gt; files)&lt;/li&gt;
&lt;li&gt;Scene files exported by other applications (&lt;code&gt;.escn&lt;/code&gt; files)&lt;/li&gt;
&lt;li&gt;probably some more that I have missed&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Performance
&lt;/h2&gt;

&lt;p&gt;The TSCN files are stored as binary &lt;code&gt;.scn&lt;/code&gt; files in the internal &lt;code&gt;.import&lt;/code&gt; folder. This way they load very fast. &lt;/p&gt;

&lt;h2&gt;
  
  
  Why I love the text files
&lt;/h2&gt;

&lt;p&gt;I use git for all my projects. The text file format works perfectly with git. Every change I do in my scenes can be tracked by git. While every little change in the scene can be tracked this can also be too much. I like to group logically connected changes together to not clutter my git history too much.&lt;/p&gt;

&lt;p&gt;Another point I love is that I can search for things easily. Forgot in which file the enemy named "KlingonShip01" was? Simply search in all files in the project directory! As everything is stored in plain sight it is very easy to find things.&lt;/p&gt;

&lt;p&gt;Last but not least I love the simple structure of these files. It is not only easy to read, it is also easy to generate. For my current space game I wrote a small python script that generates scenes. It looks up the positions of planets and stars in an online database. Based on this gathered data it generates godot scene files.&lt;/p&gt;

&lt;h2&gt;
  
  
  Thank you for reading! ✨
&lt;/h2&gt;

&lt;p&gt;This is the second post in my series "Things I love about Godot". I will probably cover the editor interface and more in the following posts. If you have any questions or suggestions please let me know!&lt;/p&gt;

</description>
      <category>gamedev</category>
      <category>godot</category>
    </item>
    <item>
      <title>Godot Engine: GDScript</title>
      <dc:creator>Winston</dc:creator>
      <pubDate>Sun, 28 Jul 2019 15:39:07 +0000</pubDate>
      <link>https://dev.to/winstonyallow/godot-engine-gdscript-3ik8</link>
      <guid>https://dev.to/winstonyallow/godot-engine-gdscript-3ik8</guid>
      <description>&lt;p&gt;I want to share a few things that I love about the &lt;a href="https://godotengine.org/"&gt;Godot Game Engine&lt;/a&gt;. Today I will write about gdscript.&lt;/p&gt;

&lt;p&gt;This post is not meant as a tutorial. Check out the &lt;a href="https://docs.godotengine.org/en/3.1/getting_started/scripting/gdscript/index.html"&gt;documentation&lt;/a&gt; to learn more about gdscript. In this post I will point out the things that I love about gdscript.&lt;/p&gt;

&lt;h2&gt;
  
  
  Integration
&lt;/h2&gt;

&lt;p&gt;When I first started to use Godot I was quite sceptical about gdscript. Why create a new language when there are so many other existing languages? The answer for me is the awesome integration. It is built with the game engine in mind.&lt;/p&gt;

&lt;p&gt;There are so many nicely integrated features! Here is a small snippet that shows some of them:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight swift"&gt;&lt;code&gt;&lt;span class="n"&gt;onready&lt;/span&gt; &lt;span class="k"&gt;var&lt;/span&gt; &lt;span class="nv"&gt;detector&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="err"&gt;$&lt;/span&gt;&lt;span class="kt"&gt;DetectorArea&lt;/span&gt;
&lt;span class="n"&gt;export&lt;/span&gt; &lt;span class="k"&gt;var&lt;/span&gt; &lt;span class="nv"&gt;health&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mf"&gt;10.0&lt;/span&gt;

&lt;span class="n"&gt;remote&lt;/span&gt; &lt;span class="kd"&gt;func&lt;/span&gt; &lt;span class="nf"&gt;apply_damage&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;amount&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;
    &lt;span class="n"&gt;health&lt;/span&gt; &lt;span class="o"&gt;-=&lt;/span&gt; &lt;span class="n"&gt;amount&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The &lt;code&gt;onready&lt;/code&gt; keyword can be used to delay the initialization of a variable until the node is part of the scene tree. This is very helpful if you need to access another node from the scene tree for the initialization.&lt;/p&gt;

&lt;p&gt;The &lt;code&gt;$&lt;/code&gt; is syntactic sugar to access a node in the scene tree by name.&lt;/p&gt;

&lt;p&gt;The &lt;code&gt;export&lt;/code&gt; keyword is used to make a variable editable in the editor. &lt;em&gt;Example usecase:&lt;/em&gt;&lt;br&gt;
&lt;em&gt;Having many enemies with the same behaviour but different amounts of health. You can simply change the exported value for individual instances inside the editor UI!&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;Godot supports high level multiplayer networking. There are keywords like &lt;code&gt;remote&lt;/code&gt; to make functions callable over the network with gdscript.&lt;/p&gt;
&lt;h2&gt;
  
  
  Syntax
&lt;/h2&gt;

&lt;p&gt;The syntax is inspired by python. As I love python it was very easy for me to adapt to gdscript. Like python gdscript also makes use of indentation.&lt;/p&gt;
&lt;h2&gt;
  
  
  Optional type hints
&lt;/h2&gt;

&lt;p&gt;The (pretty new) &lt;a href="https://docs.godotengine.org/en/3.1/getting_started/scripting/gdscript/static_typing.html"&gt;type hints&lt;/a&gt; in gdscript are easy to use and completely optional. I often quickly prototype something without type hints. For everything beyond prototyping I use type hints wherever possible.&lt;/p&gt;

&lt;p&gt;The editor has a concept of "safe lines". It is perfectly possible to only use types in a few places. Lines where the type check found no errors are marked as safe. This is indicated by a green line number. Lines where the type check can not be performed (because of missing type hints) do not have this green line number. Errors found by the type check are shown directly in the editor.&lt;/p&gt;

&lt;p&gt;Often the type can be inferred (making the code much shorter).&lt;br&gt;
&lt;em&gt;Example: &lt;code&gt;var foo := "bar"&lt;/code&gt; instead of &lt;code&gt;var foo: String = "bar"&lt;/code&gt;&lt;/em&gt;&lt;/p&gt;
&lt;h2&gt;
  
  
  The &lt;code&gt;match&lt;/code&gt; statement
&lt;/h2&gt;

&lt;p&gt;I like to think of &lt;code&gt;match&lt;/code&gt; like an enhanced version of a &lt;code&gt;switch&lt;/code&gt; statement. Let me demonstrate some of it's awesomeness with an array named &lt;code&gt;bookshelf&lt;/code&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight swift"&gt;&lt;code&gt;&lt;span class="n"&gt;match&lt;/span&gt; &lt;span class="nv"&gt;bookshelf&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
    &lt;span class="p"&gt;[]:&lt;/span&gt;
        &lt;span class="nf"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"Empty bookshelf"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s"&gt;"The Hitchhiker's Guide to the Galaxy"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="o"&gt;..&lt;/span&gt;&lt;span class="p"&gt;]:&lt;/span&gt;
        &lt;span class="nf"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"The first book in your shelf is awesome!"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
        &lt;span class="nf"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"Nothing else is important."&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s"&gt;"LOTR 1"&lt;/span&gt;&lt;span class="p"&gt;],&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s"&gt;"LOTR 2"&lt;/span&gt;&lt;span class="p"&gt;],&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s"&gt;"LOTR 3"&lt;/span&gt;&lt;span class="p"&gt;]:&lt;/span&gt;
        &lt;span class="nf"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"You own exactly one book."&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
        &lt;span class="nf"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"It is a book from the Lord of the Rings."&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="k"&gt;var&lt;/span&gt; &lt;span class="nv"&gt;lonely_book&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;_&lt;/span&gt; &lt;span class="p"&gt;]:&lt;/span&gt;
        &lt;span class="nf"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"There are two books."&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
        &lt;span class="nf"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"The first book is named "&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;lonely_book&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In the above &lt;code&gt;match&lt;/code&gt; statement I used array patterns. The &lt;code&gt;..&lt;/code&gt; is used for open ended arrays. Using &lt;code&gt;var&lt;/code&gt; inside a pattern binds the corresponding value to the new variable. The &lt;code&gt;_&lt;/code&gt; wildcard matches anything (and can be part of complex patterns).&lt;/p&gt;

&lt;p&gt;There are &lt;a href="https://docs.godotengine.org/en/3.1/getting_started/scripting/gdscript/gdscript_basics.html#match"&gt;many types of usable match patterns&lt;/a&gt;, from simple values to complex dictionary patterns!&lt;/p&gt;

&lt;p&gt;In my opinion &lt;code&gt;match&lt;/code&gt; is an extremely powerful structure. However it can lead to code that is hard to read. Use it with care. Think about how and why you use it. I personally love &lt;code&gt;match&lt;/code&gt; but often simpler structures can be used. I only worked on two or three actual projects where it made sense to use it.&lt;/p&gt;

&lt;h2&gt;
  
  
  Thank you for reading! ✨
&lt;/h2&gt;

&lt;p&gt;This is my first blog post here on DEV. My plan is to create a series of posts with things I love about Godot. If you have any questions or suggestions please let me know!&lt;/p&gt;

</description>
      <category>gamedev</category>
      <category>godot</category>
    </item>
  </channel>
</rss>
