#!/usr/bin/newlisp ;; Creative Commons Attribution (by) License v2.5 ;; Full text - http://creativecommons.org/licenses/by/2.5/ ;; Contact - tyler.mace@versantvoice.com ;; Copyright (c) 2009, Versant Voice, Inc. ;; Context: SHELL ;; The shell will provide the interface the player will be ;; interacting with. The command line interface and a stat ;; panel will be included. ;; Context: MAIN ;; Splash screen, exit, versioning information, etc. (context 'SHELL) ;; Shell variables (setq scripts_directory "scripts/") (setq ps1 "secsec> ") (setq quit_command "quit") (setq current_command "") (setq last_command "") ;; Process command lambda ;; Takes a command as an argument and processes it (define (Process_Command command_string) (begin ;; Local variables (setq command_list (parse command_string)) (setq command (first command_list)) (setq command_args (rest command_list)) (setq all_scripts (directory SHELL:scripts_directory)) (setq usable_scripts (begin ;; Strip out "." and ".." and return only usable scripts (pop all_scripts (find "." all_scripts)) (pop all_scripts (find ".." all_scripts)) all_scripts ) ) ;; Debug information (println (append "Command: " command)) (println (append "Argument(s): " (join command_args ", "))) (println (append "Commands available: " (join usable_scripts ", "))) ;; Find our command script and run it, if available, else show available commands (if (find command usable_scripts) (begin ;; Gather script data (setq script_data (read-file (append SHELL:scripts_directory command))) ;; Evaluate script data (setq evaluated_script_data (eval-string script_data)) ) ) ) ) ;; Run shell lambda ;; Run our shell, looping to process commands as they're entered (define (Run_Shell) (begin ;; Process commands so long as player doesn't enter quit command (while (begin (print SHELL:ps1 ) (setq SHELL:current_command (read-line))) (begin ;; Is the player trying to quit? (if (= SHELL:current_command SHELL:quit_command) (MAIN:Exit_Game) ) ;; Process current command (SHELL:Process_Command SHELL:current_command) ) ) ) ) (context 'MAIN) ;; Main variables (setq game_name "SecSec") (setq game_major_version "0") (setq game_minor_version "2") (setq game_full_version (append game_major_version "." game_minor_version)) ;; Splash Screen lambda ;; Display version and other game information (define (Splash_Screen) (begin (println (append MAIN:game_name " - v" MAIN:game_full_version "\r\n")) ) ) ;; Exit lambda (define (Exit_Game) (begin (println "Exiting...") (exit) ) ) ;; Let's play! (MAIN:Splash_Screen) (SHELL:Run_Shell)