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