18
18
using System . Text ;
19
19
using StoryGenerator . DoorProperties ;
20
20
using System . Threading ;
21
+ using System . Globalization ;
21
22
22
23
23
24
namespace StoryGenerator . Utilities
@@ -343,16 +344,20 @@ public class PutAction : IAction
343
344
{
344
345
public ScriptObjectName Name { get ; private set ; }
345
346
public ScriptObjectName DestName { get ; private set ; }
347
+ public Vector2 ? DestPos { get ; private set ; } // put destination position
348
+ public float Y { get ; private set ; }
346
349
public int ScriptLine { get ; private set ; }
347
350
public bool PutInside { get ; private set ; }
348
351
public IObjectSelector Selector ;
349
352
350
353
351
- public PutAction ( int scriptLine , IObjectSelector selector , string name , int instance , string destName , int destInstance , bool putInside )
354
+ public PutAction ( int scriptLine , IObjectSelector selector , string name , int instance , string destName , int destInstance , bool putInside , Vector2 ? destPos , float y = - 1 )
352
355
{
353
356
ScriptLine = scriptLine ;
354
357
Name = new ScriptObjectName ( name , instance ) ;
355
358
DestName = new ScriptObjectName ( destName , destInstance ) ;
359
+ DestPos = destPos ;
360
+ Y = y ;
356
361
PutInside = putInside ;
357
362
Selector = selector ;
358
363
@@ -2463,7 +2468,7 @@ private IEnumerable<IStateGroup> ProcessPutAction(PutAction a, State current)
2463
2468
if ( fbbe != null )
2464
2469
{
2465
2470
// We need to calculate putback position
2466
- foreach ( Vector3 pos in GameObjectUtils . CalculatePutPositions ( current . InteractionPosition , sod . GameObject , sodDest . GameObject , a . PutInside , false ) )
2471
+ foreach ( Vector3 pos in GameObjectUtils . CalculatePutPositions ( current . InteractionPosition , sod . GameObject , sodDest . GameObject , a . PutInside , false , a . DestPos , a . Y ) )
2467
2472
{
2468
2473
State s = new State ( current , a , current . InteractionPosition , ExecutePut ) ;
2469
2474
s . AddScriptGameObject ( a . Name , sod . GameObject , pos , current . InteractionPosition , false ) ;
@@ -4000,7 +4005,7 @@ public static void ParseScript(List<ScriptExecutor> sExecutors, IList<string> sc
4000
4005
ParseScriptForChar ( sExecutors [ i ] , scriptLines , i , actionEquivProvider ) ;
4001
4006
}
4002
4007
}
4003
-
4008
+
4004
4009
private static void ParseScriptForChar ( ScriptExecutor sExecutor , IList < string > scriptLines , int charIndex ,
4005
4010
ActionEquivalenceProvider actionEquivProvider )
4006
4011
{
@@ -4014,7 +4019,7 @@ private static void ParseScriptForChar(ScriptExecutor sExecutor, IList<string> s
4014
4019
if ( sl != null )
4015
4020
sLines . Add ( sl ) ;
4016
4021
}
4017
- sExecutor . sLines = new List < ScriptLine > ( sLines ) ;
4022
+ // sExecutor.sLines = new List<ScriptLine>(sLines);
4018
4023
for ( int i = 0 ; i < sLines . Count ; i ++ )
4019
4024
{
4020
4025
ScriptLineToAction ( sExecutor , i , sLines ) ;
@@ -4124,7 +4129,37 @@ private static void ScriptLineToAction(ScriptExecutor sExecutor, int index, ILis
4124
4129
case InteractionType . PUTIN :
4125
4130
if ( string . IsNullOrEmpty ( name1 ) )
4126
4131
throw new ScriptReaderException ( $ "No second argument for [{ sl . Interaction } ]") ;
4127
- sExecutor . AddAction ( new PutAction ( sl . LineNumber , sExecutor . GetObjectSelector ( name1 , instance1 ) , name0 , instance0 , name1 , instance1 , sl . Interaction == InteractionType . PUTIN ) ) ;
4132
+
4133
+ if ( sl . Parameters . Count > 2 )
4134
+ {
4135
+ string strpos = sl . Parameters [ sl . Parameters . Count - 1 ] . Item1 ;
4136
+ Debug . Log ( "POSITION: " + strpos ) ;
4137
+ string [ ] positions = strpos . Split ( ',' ) ;
4138
+ if ( positions . Length == 3 )
4139
+ {
4140
+ NumberFormatInfo fmt = new NumberFormatInfo ( ) ;
4141
+ fmt . NegativeSign = "-" ;
4142
+ Vector2 pos = new Vector2 ( float . Parse ( positions [ 0 ] , fmt ) , float . Parse ( positions [ 2 ] , fmt ) ) ;
4143
+ float y = float . Parse ( positions [ 1 ] , fmt ) ;
4144
+ sExecutor . AddAction ( new PutAction ( sl . LineNumber , sExecutor . GetObjectSelector ( name1 , instance1 ) , name0 , instance0 , name1 , instance1 , sl . Interaction == InteractionType . PUTIN , pos , y ) ) ; //TODO: add destPos
4145
+ }
4146
+ else if ( positions . Length == 2 )
4147
+ {
4148
+ NumberFormatInfo fmt = new NumberFormatInfo ( ) ;
4149
+ fmt . NegativeSign = "-" ;
4150
+ Vector2 pos = new Vector2 ( float . Parse ( positions [ 0 ] , fmt ) , float . Parse ( positions [ 1 ] , fmt ) ) ;
4151
+ sExecutor . AddAction ( new PutAction ( sl . LineNumber , sExecutor . GetObjectSelector ( name1 , instance1 ) , name0 , instance0 , name1 , instance1 , sl . Interaction == InteractionType . PUTIN , pos , - 1 ) ) ; //TODO: add destPos
4152
+ }
4153
+ else
4154
+ {
4155
+ sExecutor . AddAction ( new PutAction ( sl . LineNumber , sExecutor . GetObjectSelector ( name1 , instance1 ) , name0 , instance0 , name1 , instance1 , sl . Interaction == InteractionType . PUTIN , null , - 1 ) ) ;
4156
+ }
4157
+ }
4158
+ else
4159
+ {
4160
+ sExecutor . AddAction ( new PutAction ( sl . LineNumber , sExecutor . GetObjectSelector ( name1 , instance1 ) , name0 , instance0 , name1 , instance1 , sl . Interaction == InteractionType . PUTIN , null , - 1 ) ) ;
4161
+ }
4162
+
4128
4163
break ;
4129
4164
case InteractionType . PUTOBJBACK :
4130
4165
sExecutor . AddAction ( new PutBackAction ( sl . LineNumber , name0 , instance0 ) ) ;
@@ -4215,6 +4250,8 @@ private static ScriptLine ParseLineForChar(int charIndex, string line, int lineN
4215
4250
string pattAction = @"\[(\w+)\]" ;
4216
4251
string pattParams = @"<([\w\s]+)>\s*\((\d+)\)\s*(:\d+:)?" ;
4217
4252
string pattchar = @"<char(\d+)>" ;
4253
+ string pattPos = @"(-?\d+\.?\d*(E-\d+)?),(-?\d+\.?\d*(E-\d+)?),(-?\d+\.?\d*(E-\d+)?)" ;
4254
+ string pattPosXZ = @"(-?\d+\.?\d*(E-\d+)?),(-?\d+\.?\d*(E-\d+)?)" ;
4218
4255
4219
4256
string [ ] sentences = line . Split ( '|' ) ;
4220
4257
@@ -4237,7 +4274,6 @@ private static ScriptLine ParseLineForChar(int charIndex, string line, int lineN
4237
4274
// Debug.Log (lineNo + ',' + sentence);
4238
4275
4239
4276
4240
-
4241
4277
// Parse action
4242
4278
r = new Regex ( pattAction ) ;
4243
4279
m = r . Match ( sentence ) ;
@@ -4263,7 +4299,6 @@ private static ScriptLine ParseLineForChar(int charIndex, string line, int lineN
4263
4299
}
4264
4300
m = m . NextMatch ( ) ;
4265
4301
}
4266
-
4267
4302
if ( paramList . Count == 1 )
4268
4303
{
4269
4304
string newActionStr ;
@@ -4278,6 +4313,36 @@ private static ScriptLine ParseLineForChar(int charIndex, string line, int lineN
4278
4313
if ( actionEquivProvider . TryGetEquivalentAction ( actionStr , paramList [ 0 ] . Item1 , paramList [ 1 ] . Item1 , out newActionStr ) )
4279
4314
actionStr = newActionStr ;
4280
4315
}
4316
+ /*else if (paramList.Count == 3) //TODO: either continue with this or remove/use parse position
4317
+ {
4318
+ string newActionStr;
4319
+ if (actionEquivProvider.TryGetEquivalentAction(actionStr, paramList[0].Item1, paramList[1].Item1, paramList[2].Item1, out newActionStr))
4320
+ actionStr = newActionStr;
4321
+ }*/
4322
+
4323
+ // Parse position x,y,z
4324
+ r = new Regex ( pattPos ) ;
4325
+ m = r . Match ( sentence ) ;
4326
+
4327
+ if ( m . Success )
4328
+ {
4329
+ // 2.5,3.4,1.5
4330
+ paramList . Add ( Tuple . Create ( m . Groups [ 0 ] . Value , 0 ) ) ;
4331
+ } else
4332
+ {
4333
+ // Parse position x,z
4334
+ r = new Regex ( pattPosXZ ) ;
4335
+ m = r . Match ( sentence ) ;
4336
+
4337
+ if ( m . Success )
4338
+ {
4339
+ // 2.5,3.4
4340
+ paramList . Add ( Tuple . Create ( m . Groups [ 0 ] . Value , 0 ) ) ;
4341
+ }
4342
+ }
4343
+
4344
+
4345
+
4281
4346
4282
4347
InteractionType action = ( InteractionType ) Enum . Parse ( typeof ( InteractionType ) , actionStr , true ) ;
4283
4348
return new ScriptLine ( ) { Interaction = action , Parameters = paramList , LineNumber = lineNo , modifier = modifier } ;
0 commit comments