import os
import re
import shutil

class Item:

    def __init__(self, path, index, no_name):
        self.path = path
        self.index = index
        self.no_name = no_name
        self.next = None

    def __str__(self):
        return str(self.index) + "\t" + self.path

    def __len__(self):
        ii = 0
        current = self
        while current != None:
            ii += 1
            current = current.next
        return ii

    def insert(self, path, index=None):
        head = self
        previous = head.advance_to_index_predecessor(index)
        if index == None:
            index = previous.index + 1
        item = Item(path, index, self.no_name)
        if previous != None:
            item.next = previous.next
            previous.next = item
        else:
            item.next = head
            head = item
        item.increase_indices()
        return head

    def advance_to_index_predecessor(self, index=None):
        previous = None
        current = self
        while current != None:
            if index != None and current.index >= index:
                break
            previous = current
            current = current.next
        return previous

    def increase_indices(self):
        current = self.next
        previous_index = self.index
        while current != None and current.index == previous_index:
            current.index += 1
            previous_index += 1
            current = current.next

    def remove_path(self, path):
        head = self
        current = head
        previous = None
        while current != None:
            if os.path.samefile(path, current.path):
                if previous != None:
                    previous.next = current.next
                else:
                    head = current.next
                break
            previous = current
            current = current.next
        return head

    def bunch(self):
        index = 1
        current = self
        while current != None:
            current.index = index
            index += 1
            current = current.next

    def erase_index(self):
        self.index = None

    def save(self, directory_path, prefix_length, delimiter, copy, simulate,
             verbosity):
        name = self.extract_name()
        name = name.lstrip(delimiter)
        prefix = self.build_prefix(prefix_length)
        if self.no_name:
            file_name = prefix + self.extract_extension(name)
        else:
            file_name = prefix + delimiter + name
        path = os.path.join(directory_path, file_name)
        self.write_path(path, copy, simulate, verbosity)

    def build_prefix(self, prefix_length):
        prefix = ""
        if self.index != None:
            prefix = str(self.index).zfill(prefix_length)
        return prefix

    def extract_extension(self, name):
        return "." + name.split(".")[-1]

    def write_path(self, path, copy, simulate, verbosity):
        if not os.path.isfile(path) or not os.path.samefile(self.path, path):
            if not simulate:
                if copy:
                    shutil.copy(self.path, path)
                else:
                    shutil.move(self.path, path)
            if verbosity > 0:
                print "Wrote:", self.path, "=>", path

    def get_largest_index(self):
        current = self
        while current.next:
            current = current.next
        return current.index

    def extract_name(self):
        file_name = os.path.basename(self.path)
        match = re.match("^[0-9]*(.*)", file_name)
        return match.group(1)
<?php

define("STYLE_SHEET", "style.css");
define(
   "PAGE_TITLE",
   "Elemental Parents &#187; Lightweight Hierarchical Database");

display_page();
function display_page() { echo build_page(); }

function build_page()
{
   $markup = "<html>\n\n";
   $markup .= build_head();
   $markup .= build_body();
   $markup .= "</html>";
   return $markup;
}

function build_body()
{
   $markup = file_get_contents("elmp.html") . "\n";
   return $markup;
}

function build_head()
{
   $markup = "<head>\n";
   $markup .= "<title>" . PAGE_TITLE . "</title>\n";
   $markup .= build_style_sheet_tag();
   $markup .= "</head>\n\n";
   return $markup;
}

function build_style_sheet_tag()
{
   $markup = "<link href=\"";
   $markup .= STYLE_SHEET;
   $markup .= "\" rel=\"stylesheet\" type=\"text/css\"/>\n";
   return $markup;
}
<?php

define("OPEN_ELEMENT_CHAR", "(");
define("CLOSE_ELEMENT_CHAR", ")");

define("NAME_COMPONENT", 0);
define("ID_COMPONENT", 1);
define("DATA_COMPONENT", 2);
define("COMPONENT_COUNT", 3);

define("ELMP_VERBOSE", True);
<?php

// The refrigerator picked up a mix of transmissions from Andromeda, one of
// them was a loop, "Attention All Humans..."

class Element
{
   public function __construct($id=NULL, $name=NULL, $content=NULL)
   {
      $this->id = $id;
      $this->name = $name;
      $this->content = $content;
   }

   public function __toString()
   {
      return "Element $this->id -- $this->name\n";
   }

   public function count()
   {
      return ((is_object($this->content)) ? $this->content->count() : 0) +
         (($this->next) ? $this->next->count() : 0) + 1;
   }

   public function measure_depth()
   {
      $current = $this;
      while ($current)
      {
         if (is_object($current->content))
         {
            $nodes[] = 1 + $current->content->measure_depth();
         }
         $current = $current->next;
      }
      return ($nodes) ? max($nodes) : 1;
   }

   // Run a user supplied function on every member of the tree.  Return the
   // concatenation of the values given by each recursive call.
   public function format($editor, $indent=False, $level=0)
   {
      $markup = call_user_func($editor, $this, $indent, $level);
      if (is_object($this->content))
      {
         $markup .= $this->content->format($editor, True, $level+1);
      }
      if ($this->next)
      {
         $markup .= $this->next->format($editor, False, $level);
      }
      else
      {
         $markup .= call_user_func($editor, $this->next, $indent, $level);
      }
      return $markup;
   }

   public function convert_to_raw_string()
   {
      $message = "($this->name $this->id";
      $message .= ($this->content || $this->next) ? " " : "";
      $message .= (is_object($this->content)) ?
         $this->content->convert_to_raw_string() : "";
      $message .= (!is_object($this->content)) ? "$this->content)" : ")";
      $message .= ($this->next) ? $this->next->convert_to_raw_string() : "";

      return $message;
   }

   public function convert_to_tabbed_string($level=0)
   {
      $string = str_repeat("   ", $level);
      $string .= "$this->id $this->name";
      $string .= (is_object($this->content)) ? " »\n" : ": $this->content\n";

      $string .= (is_object($this->content)) ?
         $this->content->convert_to_tabbed_string($level+1) : "";
      $string .= ($this->next) ?
         $this->next->convert_to_tabbed_string($level) : "";

      return $string;
   }
}
216.73.216.32
216.73.216.32
216.73.216.32
 
June 29, 2013

A few weeks ago, for Fishing Jam, I made a fishing simulation from what was originally designed to be a time attack arcade game. In the program, Dark Stew, the player controls Aphids, an anthropod who fishes for aquatic creatures living in nine pools of black water.



Fishing means waiting by the pool with the line in. The longer you wait before pulling the line out, the more likely a creature will appear. Aside from walking, it's the only interaction in the game. The creatures are drawings of things you maybe could find underwater in a dream.

The background music is a mix of clips from licensed to share songs on the Free Music Archive. Particularly, Seed64 is an album I used a lot of songs from. The full list of music credits is in the game's README file.

I'm still planning to use the original design in a future version. There would be a reaction-based mini game for catching fish, and the goal would be to catch as many fish as possible within the time limit. I also want to add details and obstacles to the background, which is now a little boring, being a plain, tiled, white floor.

If you want to look at all the drawings or hear the music in the context of the program, there are Windows and source versions available. The source should work on any system with Python and Pygame. If it doesn't, bug reports are much appreciated. Comments are also welcome :)

Dark Stew: Windows, Pygame Source

I wrote in my last post that I would be working on an old prototype about searching a cloud for organisms for Fishing Jam. I decided to wait a while before developing that game, tentatively titled Xenographic Barrier. Its main interactive element is a first-person scope/flashlight, so I'd like to make a Wii version of it.

I'm about to start working on a complete version of Ball & Cup. If I make anything interesting for it, I'll post something. There are a lot of other things I want to write about, like game analyses, my new GP2X and arcades in Korea, and there's still music to release. Lots of fun stuff coming!