Skip to content

Commit

Permalink
refactored for latest Dart API, and pub layout standard.
Browse files Browse the repository at this point in the history
  • Loading branch information
atebitftw committed Sep 17, 2012
1 parent ac6c056 commit f3d9c75
Show file tree
Hide file tree
Showing 52 changed files with 140 additions and 162 deletions.
5 changes: 0 additions & 5 deletions .children

This file was deleted.

12 changes: 12 additions & 0 deletions .gitignore
@@ -0,0 +1,12 @@
# Dart Excludes
*~
*.js
*.js_
.children
.project
.gitmodules
*.map
*.lock
*.tmp
packages
packages/
17 changes: 0 additions & 17 deletions .project

This file was deleted.

9 changes: 0 additions & 9 deletions README.md
Expand Up @@ -38,15 +38,6 @@ The web version uses the Buckshot UI library:

https://github.com/prujohn/Buckshot

### From the console ###
To run the game, run the ZConsole.dart app, either from the VM in shell,
or from the Dart Editor (user-input works in the Dart Editor console too).

You can change the game file within ZConsole.dart or you can run it form the
command line with an arguement:

dart ZConsole.dart path/to/minizork.z3

## Want to author your own IF games? ##
http://inform7.com/

Expand Down
8 changes: 8 additions & 0 deletions doc/getting_started.md
@@ -0,0 +1,8 @@
## From the console ##
To run a game of MiniZork, run the ZConsole.dart app, either from the VM in shell,
or from the Dart Editor (user-input works in the Dart Editor console too).

You can change the game file within ZConsole.dart or you can run it form the
command line with an arguement:

dart ZConsole.dart path/to/minizork.z3
Expand Up @@ -2,27 +2,24 @@
/** A basic console provider with word-wrap support. */
class ConsoleProvider implements IOProvider
{
final StringInputStream textStream;
final Queue<String> lineBuffer;
final Queue<String> outputBuffer;
final StringInputStream textStream = new StringInputStream(stdin);
final Queue<String> lineBuffer = new Queue<String>();
final Queue<String> outputBuffer = new Queue<String>();

final int cols = 80;

ConsoleProvider()
:
textStream = new StringInputStream(stdin),
lineBuffer = new Queue<String>(),
outputBuffer = new Queue<String>();

ConsoleProvider();

Future<Object> command(String JSONCommand){
var c = new Completer();

var msgSet = JSON.parse(JSONCommand);

var cmd = IOCommands.toIOCommand(msgSet[0]);

//print('msg received>>> $cmd');

switch(cmd){

//print('msg received>>> $cmd'); switch(cmd){
case IOCommands.PRINT:
output(msgSet[1], msgSet[2]);
c.complete(null);
Expand All @@ -45,7 +42,7 @@ class ConsoleProvider implements IOProvider
//no clear console api, so
//we just print a bunch of lines
for(int i=0; i < 50; i++){
print('');
print('');
}
c.complete(null);
break;
Expand Down Expand Up @@ -90,7 +87,7 @@ class ConsoleProvider implements IOProvider
s.writeFrom(saveBytes);
s.close();
c.complete(true);
}catch(FileIOException e){
}on FileIOException catch(e){
print('File IO error.');
c.complete(false);
}
Expand All @@ -115,7 +112,7 @@ class ConsoleProvider implements IOProvider
print('Restoring game "${fn}.sav"...');
File f2 = new File('games${Platform.pathSeparator}${fn}.sav');
c.complete(f2.readAsBytesSync());
}catch(FileIOException e){
}on FileIOException catch(e){
print('File IO error.');
c.complete(null);
}
Expand Down
Expand Up @@ -13,7 +13,8 @@ class DebugProvider implements IOProvider
lineBuffer = new Queue<String>(),
outputBuffer = new Queue<String>()
{
if (script.isEmpty()) return;
if (script.isEmpty()) { return;
}
var commands = script.split('.');

for(final command in commands){
Expand Down Expand Up @@ -72,14 +73,16 @@ class DebugProvider implements IOProvider

if (s.length > cols){
outputBuffer.addFirst('$s');
if (Debugger.enableDebug) print('$s');
if (Debugger.enableDebug) { print('$s');
}
s = new StringBuffer();
s.add('$nextWord ');
}else{
if (words.isEmpty()){
s.add('$nextWord ');
outputBuffer.addFirst('$s');
if (Debugger.enableDebug) print('$s');
if (Debugger.enableDebug) { print('$s');
}
s = new StringBuffer();
}else{
s.add('$nextWord ');
Expand All @@ -89,7 +92,8 @@ class DebugProvider implements IOProvider

if (s.length > 0){
outputBuffer.addFirst('$s');
if (Debugger.enableDebug) print('$s');
if (Debugger.enableDebug) { print('$s');
}
s = new StringBuffer();
}
}
Expand Down
@@ -1,10 +1,9 @@
#import('../lib/zmachine.dart');
#import('../../lib/zart.dart');
#import('dart:io');
#import('dart:json');
#import('dart:builtin');

#source('ConsoleProvider.dart');
#source('DebugProvider.dart');
#source('console_provider.dart');
#source('debug_provider.dart');

// A basic Console player for Z-Machine
// Assumes first command line arguement is path to story file,
Expand Down Expand Up @@ -43,11 +42,11 @@ void main() {

Z.load(gameData);

} catch (FileIOException fe){
} on FileIOException catch (fe){
//TODO log then print friendly
print('$fe');
exit(0);
} catch (Exception e){
} on Exception catch (e){
//TODO log then print friendly
print('$e');
exit(0);
Expand All @@ -73,10 +72,10 @@ void main() {

try{
Z.run();
}catch(GameException ge){
}on GameException catch(ge){
print('got it!\n $ge');
exit(0);
}catch(Exception e){
}on Exception catch(e){
print('$e');
exit(0);
}
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
18 changes: 0 additions & 18 deletions lib/IO/readme.md

This file was deleted.

File renamed without changes.
File renamed without changes.
28 changes: 14 additions & 14 deletions lib/IO/IFF.dart → lib/src/IO/iff.dart
Expand Up @@ -104,24 +104,24 @@ class Chunk{
const Chunk(this._str);

//Blorb chunks
static final IFRS = const Chunk('IFRS');
static final RIdx = const Chunk('RIdx');
static final ZCOD = const Chunk('ZCOD');
static final Exec = const Chunk('Exec');
static const IFRS = const Chunk('IFRS');
static const RIdx = const Chunk('RIdx');
static const ZCOD = const Chunk('ZCOD');
static const Exec = const Chunk('Exec');

//Quetzal chunks
static final IFZS = const Chunk('IFZS');
static final IFhd = const Chunk('IFhd');
static final CMem = const Chunk('CMem');
static final UMem = const Chunk('UMem');
static final Stks = const Chunk('Stks');
static final IntD = const Chunk('IntD');
static const IFZS = const Chunk('IFZS');
static const IFhd = const Chunk('IFhd');
static const CMem = const Chunk('CMem');
static const UMem = const Chunk('UMem');
static const Stks = const Chunk('Stks');
static const IntD = const Chunk('IntD');

//IFF Chunks
static final FORM = const Chunk('FORM');
static final AUTH = const Chunk('AUTH');
static final CPYR = const Chunk('(c) ');
static final ANNO = const Chunk('ANNO');
static const FORM = const Chunk('FORM');
static const AUTH = const Chunk('AUTH');
static const CPYR = const Chunk('(c) ');
static const ANNO = const Chunk('ANNO');

String toString() => _str;

Expand Down
32 changes: 16 additions & 16 deletions lib/IO/IOProvider.dart → lib/src/IO/io_provider.dart
Expand Up @@ -2,11 +2,11 @@
/**
* Represents a contract for IO (Presentation) providers.
*/
interface IOProvider {
class IOProvider {

//TODO use isolates between IO and engine.

Future<Object> command(String JSONCommand);
abstract Future<Object> command(String JSONCommand);
}

/** Enumerates supported IO command message */
Expand All @@ -15,20 +15,20 @@ class IOCommands{

const IOCommands(this._str);

static final PRINT = const IOCommands('PRINT');
static final STATUS = const IOCommands('STATUS');
static final CLEAR_SCREEN = const IOCommands('CLEAR_SCREEN');
static final SPLIT_SCREEN = const IOCommands('SPLIT_SCREEN');
static final SET_WINDOW = const IOCommands('SET_WINDOW');
static final SET_FONT = const IOCommands('SET_FONT');
static final SAVE = const IOCommands('SAVE');
static final RESTORE = const IOCommands('RESTORE');
static final READ = const IOCommands('READ');
static final READ_CHAR = const IOCommands('READ_CHAR');
static final QUIT = const IOCommands('QUIT');
static final PRINT_DEBUG = const IOCommands('PRINT_DEBUG');
static final ASYNC = const IOCommands('ASYNC');
static final SET_CURSOR = const IOCommands('SET_CURSOR');
static const PRINT = const IOCommands('PRINT');
static const STATUS = const IOCommands('STATUS');
static const CLEAR_SCREEN = const IOCommands('CLEAR_SCREEN');
static const SPLIT_SCREEN = const IOCommands('SPLIT_SCREEN');
static const SET_WINDOW = const IOCommands('SET_WINDOW');
static const SET_FONT = const IOCommands('SET_FONT');
static const SAVE = const IOCommands('SAVE');
static const RESTORE = const IOCommands('RESTORE');
static const READ = const IOCommands('READ');
static const READ_CHAR = const IOCommands('READ_CHAR');
static const QUIT = const IOCommands('QUIT');
static const PRINT_DEBUG = const IOCommands('PRINT_DEBUG');
static const ASYNC = const IOCommands('ASYNC');
static const SET_CURSOR = const IOCommands('SET_CURSOR');

static IOCommands toIOCommand(String cmd){
switch(cmd){
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
2 changes: 1 addition & 1 deletion lib/GameException.dart → lib/src/game_exception.dart
Expand Up @@ -11,7 +11,7 @@ class GameException implements Exception
String toString() {
try{
return 'Z-Machine exception: [0x${addr.toRadixString(16)}] $msg\n${Debugger.crashReport()}';
}catch (Exception e){
} on Exception catch (e){
return msg;
}
}
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
8 changes: 4 additions & 4 deletions lib/Operand.dart → lib/src/operand.dart
Expand Up @@ -57,16 +57,16 @@ class Operand
class OperandType {

/** 2 byte large constant (0-65535) */
static final int LARGE = 0x00;
static const int LARGE = 0x00;

/** 1 byte small constant (0-255) */
static final int SMALL = 0x01;
static const int SMALL = 0x01;

/** Variable lookup */
static final int VARIABLE = 0x02;
static const int VARIABLE = 0x02;

/** Omitted Flag, terminates Operand Type list */
static final int OMITTED = 0x03;
static const int OMITTED = 0x03;

static String asString(int type){
switch(type){
Expand Down
File renamed without changes.

0 comments on commit f3d9c75

Please sign in to comment.