Cleanup around sprite properties
This commit is contained in:
parent
cfa7723513
commit
5c9e3c91d5
|
|
@ -114,6 +114,7 @@ sub ShowSprite {
|
|||
my $a = GetAsset($file);
|
||||
if($t eq 'ASprite') {
|
||||
# Unload the asset so that future versions of the same name will be fresh copies
|
||||
# This is necessary for instances where the frame position doesn't match
|
||||
UnloadAsset($file);
|
||||
|
||||
# Start animation
|
||||
|
|
@ -124,26 +125,32 @@ sub ShowSprite {
|
|||
my($name, $val)=$o=~/^\s*(\S+?)=(\S*)/;
|
||||
$name = $o unless($name);
|
||||
$name = lc($name);
|
||||
if($name eq 'reverse') {
|
||||
$a->type('Reverse');
|
||||
} elsif($name eq 'circular') {
|
||||
$a->type('Circular');
|
||||
if($name eq 'reverse' || $name eq 'circular') {
|
||||
if($t eq 'ASprite') {
|
||||
$a->type($name);
|
||||
} else {
|
||||
LogData(WARN, "%s - Non animated sprite can't have %s property", GetScriptPosition(), $name);
|
||||
}
|
||||
} elsif($name eq 'max_loops') {
|
||||
if($t eq 'ASprite') {
|
||||
$a->max_loops($val);
|
||||
} else {
|
||||
LogData(WARN, "%s - Non animated sprite can't have %s property", GetScriptPisition(), $name);
|
||||
}
|
||||
} elsif($name eq 'flip') {
|
||||
# Don't want to flip back and forth every time
|
||||
UnloadAsset($file);
|
||||
my $s=$a->surface();
|
||||
$a->surface( Surface_Flip($s) );
|
||||
} elsif($name eq 'ticks') {
|
||||
if($t eq 'ASprite') {
|
||||
$val = 1 unless($val);
|
||||
if($val != 1) {
|
||||
# Keep a personal copy to support sprites at different speeds from the same asset
|
||||
UnloadAsset($file);
|
||||
}
|
||||
$a->ticks_per_frame($val);
|
||||
} else {
|
||||
LogData(WARN, "Unknown option in ShowSprite '$o' - '$name'='$val'");
|
||||
LogData(WARN, "%s - Non animated sprite can't have %s property", GetScriptPosition(), $name);
|
||||
}
|
||||
} else {
|
||||
LogData(WARN, "%s - Unknown sprite property '%s'", GetScriptPosition(), $name);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -13,7 +13,7 @@ use PerlRPG::Drawing;
|
|||
|
||||
use vars qw/@ISA @EXPORT @EXPORT_OK %game_vars/;
|
||||
@ISA = qw/Exporter/;
|
||||
@EXPORT = qw/CompileScripts RunScript RunScriptTick GetGameVar SetGameVar DefGameVar EvalString/;
|
||||
@EXPORT = qw/CompileScripts RunScript RunScriptTick GetGameVar SetGameVar DefGameVar EvalString GetScriptPosition/;
|
||||
@EXPORT_OK = @EXPORT;
|
||||
|
||||
my %labels;
|
||||
|
|
@ -118,19 +118,28 @@ sub RunScript {
|
|||
}
|
||||
}
|
||||
|
||||
sub GetScriptPosition {
|
||||
return "$current_file:$current_line";
|
||||
}
|
||||
|
||||
# Run script from current position until a wait condition
|
||||
sub RunScriptTick {
|
||||
return 1 if($lastsayer);
|
||||
for(;;) {
|
||||
my $script = GetAsset($current_file); # current_file can change in RunScriptLine, so reload each time
|
||||
my $file = $current_file;
|
||||
my $line = $current_line++;
|
||||
my $line = $current_line;
|
||||
if($line >= @$script) {
|
||||
LogData(ERROR, "Script file ended");
|
||||
SetGameVar('GameRunning', 0);
|
||||
return;
|
||||
}
|
||||
if(RunScriptLine($file, $line, $script->[$line])) {
|
||||
my $r=RunScriptLine($file, $line, $script->[$line]);
|
||||
if($current_line == $line && $current_file eq $file) {
|
||||
# Advance the line number if RunScriptLine didn't move us
|
||||
$current_line++;
|
||||
}
|
||||
if($r) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue