Wednesday, June 5, 2019

Project Start to Finish - Collaborative Pixel Canvas: Staring Up - Development Environment

Hello, my name is Justin Baker and this series of posts will follow the development of a personal project to develop a full stack application from start to finish. The idea for this project is to implement something akin to Reddit's /r/place.

This is a continuation of my previous where I detailed what tools I would be using. This post will continue where I left off and go over setting up my development environment for anyone that wants to follow along.


Tools Needed

To follow along you will need the following tools/programs installed.
  • Visual Studio Code (other Code editors or IDEs should also work)
  • NPM
  • Git
This should be all that is necessary for for the initial portion of this project. Once the core functionality of the canvas is complete I will provide details on setting up tools for the back end implementation.

Starting

Starting off I created a fresh Git Repository and cloned it to my machine. If you are new to Git this link should provide some helpful resources to getting started. Before I get to installing all of the modules that I'm going to use I'm going to create a .gitignore file so I don't have to worry about dependencies and generated files getting caught up in the git repository.

With the gitignore in place we can set up some initial folder structure so that as the project grows things remain organized and expandable. 



I will use these folder in the following manner.



Assets

  • Storing images, textures, sounds, and other files that are typically not text encoded.
Dist
  • Compiled and output files. Will generally hold the code produced for deployment.
Src
  • Source code for building our Phaser 3 project. Once we start writing code we will expand our folder structure for the requirements of building the front end. 
Static
  • I typically reserve a static folder for files that do not change often like CSS.

With the initial folders setup we will set up our node module with npm and start downloading our dependencies.

NPM

I'm just going to start with a simple npm init command and use the default options. This will create a package.json file that we will want tracked via our source control. Npm will make sure it is updated as move forward and install our dependencies. I will be installing everything as a development dependency because our code will be compiled/built into a single javascript file for us.

The command I will be running is
npm install live-server phaser npm-run-all ts-loader typescript webpack webpack-cli --save-dev

 Installed Modules

Phaser
  • The game framework used for rendering the canvas and handling input.
Typescript and ts-loader
  • The language being used to write our source code.
live-server
  • This module allows us to run a local webserver and update/refresh automatically as we make changes.
webpack and webpack-cli
  • Used to build our code and bundle it into a single file.

Config Files

We are almost at the point of being able to start coding, but we need to modify and create some of our config files. The files we will be creating a tsconfig.json and webpack.config.js

Webpack

This is providing some basic settings for webpack and will be directing our output to the dist folder.
const path = require('path');

module.exports = {
  entry: './src/app.ts',
  module: {
    rules: [
      {
        test: /\.tsx?$/,
        use: 'ts-loader',
        exclude: /node_modules/
      }
    ]
  },
  resolve: {
    extensions: [ '.ts', '.tsx', '.js' ]
  },
  output: {
    filename: 'app.js',
    path: path.resolve(__dirname, 'dist')
  },
  mode: 'development'
};
 tsconfig

This file provide some basic information, like base directory, to be used by the TypeScript compiler.
{
  "compilerOptions": {
    "target": "es5",
    "baseUrl": "./src"
  },
  "include": [
    "**/*"
  ]
}
Additionally we will be added some commands to be run with npm on our module. To do this we will modify package.json. Specifically the scripts section of the file will be replaced with the following code
  "scripts": {
    "build": "webpack",
    "watch": "webpack --watch",
    "host": "live-server --port=8085",
    "start": "npm-run-all build --parallel watch host"
  },
This will allows us to type npm start in our base directory and build/compile our project and automatically host it on a local server that will automatically refresh when any files are modified.

 Notes

This is how I set things up on my local machine. I am using Windows and PowerShell as my terminal. Let me know if there any issues that could arise when trying to setup Phaser & Typescript in another environment.
 

Monday, May 20, 2019

Project Start to Finish - Collaborative Pixel Canvas: Staring Up - Initial Requirements

Hello, my name is Justin Baker and this series of posts will follow the development of a personal project to develop a full stack application from start to finish. The idea for this project is to implement something akin to Reddit's /r/place.

This is a continuation of my previous where I detailed what tools I would using. This post will continue where I left off and detail some initial requirements for this project.

Requirements 

There will be two major components for this project. The first that I will focus on will be the front end that is responsible for displaying the current state of the canvas. The second is the backend that will be responsible for maintaining the history of changes to the canvas, validating input, synchronizing users, etc.

I will focus on higher level requirements and detail more specific requirements when I move onto more specific implementation.

Front-End Requirements

  •  Display a grid of colored squares, representing an arbitrary x by x pixel canvas.
  • Support user system
    • Register
    • Login
    • Guest
  • Allow user to select cell and change the color.
    • May be restricted by timer and color choice to have reasonable bandwith usage.
  • Display cell info.
    • Last modified: [Timestamp]
    • Modified by: [User]
    • Activity level [color] (use mean and deviation to determine color?)
  • Zoom in and out.
    • Panning when zoomed in.
  • Support Desktop browsers & be at least viewable on mobile.
  • Update in real time or regularly with authoritative server state.

Back-End Requirements

  •  Maintain database for the following
    • Users
      • Login & Authentication
      • Input history
    • Tiles
      • Tiles will make up canvas
      • History of edits
  • Server side validation 
    • Ensure changes are propagated to all clients
    • Enforce timers on tile changes
    • Only accept valid changes
These requirements can be flushed out more as the project progresses and I decide to add or remove features. However, as a solo project I want to prioritize getting something working and will leave it at this for now.

On my next post I'll go over setting up a development environment and to start working with Phaser.

Tuesday, May 7, 2019

Project Start to Finish - Collaborative Pixel Canvas: Staring Up - Selecting Tools

Hello, my name is Justin Baker and this series of posts will follow the development of a personal project to develop a full stack application from start to finish. The idea for this project is to implement something akin to Reddit's /r/place.

This project is serving a purpose to demonstrate my ability to bring a project to fruition from design to release and to show my problem solving process. Secondarily this project is as opportunity to better familiarize myself with various development technologies that I'm interested in.

Starting Up

To start this project I need to determine what tools I will be using. This project is focusing on a set of development tools and making them work with the project, rather than selecting technologies that would best fit the project since one of my major goals is learning these. Because of this I'm not starting with requirements and will focus on the technologies that I want to use.

Development Technologies

  • OS: Windows 10
    • My primary computer runs Windows, I don't have the funds or space to have dedicated Linux development machine and I don't want to deal with the Linux subsystem or dual booting.
  • IDE: Visual Studio Code
    • Visual Studio Code is a great lightweight IDE that is multi-platform with tons of plugins. I have recently been finding using VSC to be preferable to big hulking IDEs like Visual Studio & Eclipse.
  • Languages: TypeScript
    • My previous largest project using JavaScript was my game Golem Smash! I did not enjoy the dynamic typing and throughout development I was interested in checking out TypeScript to get around this part of Javascript. Now that I'm doing a project on my own with a fresh codebase I am free to pursue that interest of using TypeScript.
  • Front End: Phaser & Angular
    • Given that I want to use TypeScript the front end technologies that I decided to use was pretty straight forward. Phaser is a game Framework that can take care of rendering and provides a familiar API. Working directly with the Canvas API was an option, but for the scope of the project the added weight of Phaser won't be much of an issue.

      For the rest of the front end I am intending to use Angular. Angular was written in TypeScript and makes TypeScript development easy. 
  • Back End: TBD
    • I am not particularly set on what technologies I'd like to use for handling the back end. I intend to focus on implementing the core components on the front end and then determine a set of requirements.
  • Hosting: TBD
    • I am currently hosting most of my projects with Heroku. As development progresses I will consider options best fit for the project. 
These tools should be enough for the core of the project. My next couple posts on this project will focus on setting some initial requirements and setting up my development environment.

Project Start to Finish - Collaborative Pixel Canvas: Staring Up - Development Environment

Hello, my name is Justin Baker and this series of posts will follow the development of a personal project to develop a full stack applicatio...