top of page
Search

Game development automation using Google Sheets and Python

  • Writer: hanishn
    hanishn
  • Nov 17, 2022
  • 4 min read

Originally presented as a short talk to IGDA Ann Arbor on November 11, 2022.


Basically I want to automate this process…


ree
ree

Please see the previous 2 blogs for the fine details.


Manual process:


●ScummVM with ‘Windham’ extension

Extract clusters to .cls (raw data)


ree

●Python + Image Magick

Upscale and convert to .PNG


ree

●Python + GIMP

Add noise


ree

●Stable Diffusion using Automatic1111 WebUI

AI Art paintover and paint-in

ree

●GIMP

Manually composite screens back together


ree

High level goals:

●Automate tedious and error prone steps

●Manage lots of image files

●Associate game data (text, rules, audio)

●Present a project snapshot

●Support collaboration

Hot load game data on any device

●Direct AI Art

Free (as in Beer)


Let’s just use Google Sheets: Organize the Data!


ree

Let’s just use Google Sheets: Grid Layout


Note the indirect address magic to get the cells from a column into a grid.

ree

Now I have a nice snapshot of the whole map in the original art.


ree

How do I get images into Google Sheets using Python?

●1) First you need a Google Developer Account - https://developers.google.com/

●2) Next you need a Project

●3) Then you need to turn on the Google APIs for your Project

●4) Also you need to set up a service account

●5) And you need to create credentials for the service account

●6) Finally you need to share your Google drive and/or docs with the service account

How do I get images into Google Drive and Sheets? Step by step:

●1) First you need a Google Developer Account - https://developers.google.com/


ree


●2) Next you need to create or add a Project



ree

ree

●3) Then you need to turn on the Google APIs for your Project


ree

ree

●4) Also you need to set up a service account

ree

ree

ree

ree

●5) And you need to create credentials for the service account


ree

ree

ree

ree

●6) Finally you need to share your Google drive and/or docs with the service account


ree

How do I get images into Google Sheets with Python? Prep

  • Python - There are lots of ways to get python, but a lot of the Stable Diffusion libraries use miniconda. So let's just use that.

ree

ree

ree

  • PIP - PIP is a package manager for python that makes it super easy to install dependencies.

ree

ree

ree

  • Google APIs - Super easy to install the google APIs using PIP.

ree

ree

How do I get images into Google Drive and Sheets? Import

●Imports, scopes, init APIs, load credentials, use sheet UUID

The first section is all about imports that the examples below use for interacting with google APIs, printing to the console, saving/loading files, and running external processes. The second section sets up scopes and permissions for accessing your google drive and sheets. The third section initializes the python interface to the google docs and sheets APIs. Finally, we have a link to the 'master control' google sheet.

ree

The UUID of the google sheet is right there in the URL.

ree

●Find/create folder

In google drive, the file system is 'flat' and a 'directory' is really just a label on a given file. The procedure for getting a folder is to first see if it exists, otherwise create one.

ree

●Find/create folder, find/create file

Similarly, a file can either be created or updated depending on whether it already existed. If you don't check for existence first, then you can end up with multiple files with the same name!

ree

Create a sub-sheet if it doesn’t already exist

Check to see if the subsheet exists. The only way I found way to try and access it and then handle the exception if the lookup fails. Also, for subsheet operations, you have to use the 'batch update' approach and embed JSON in the request.

ree

●Fill in header and rows in spreadsheet

Here we are setting up a template row and updating the subsheet with that.

ree

This is what the subsheet looks like with a header and a sample row.

ree

Linking images in google sheets with URL and =Image

Any image you want to see in a google sheet will have to be shared with your account. OR you can share the whole folder.

ree

The UUID for the image is buried in its URL.

ree

Use this image lookup template URL with the UUID of your image.

ree

And then you can reference a URL in another cell using the =image(...cellid...) approach.

ree

●Download and save to local file example

Here is an example of pulling a file from google drive and saving it locally.

ree

●Processing with Python and GIMP

Here is an example of running a simple 'command line' application from within Python.

ree

Here is a more complex example where we use 'subprocess' instead and do a bunch of string mangling with \\ and such to run an exe in a path with spaces and with multiple arguments including single-quote sections.

ree

And here is a gimp-fu python script.


ree


Now push the files back up and add to sheet

Here is an example of uploading an image to google drive and linking it back into the google sheet.

ree

Here’s the sheet we auto-populated


Neat! Now we can batch process 'cluster' files from Python and Google Sheets!

ree

Coming soon, questions, and comments….


●Driving Stable Diffusion from a spreadsheet and a Python daemon

●Art directing from a Google Sheet

●Automatic composition

●Running a game from data in a Google Sheet

●How are/could you use Google Sheets in your project?


 
 
 

Comments


bottom of page