-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathsimterm-line.php
More file actions
90 lines (83 loc) · 2.24 KB
/
simterm-line.php
File metadata and controls
90 lines (83 loc) · 2.24 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
<?php
class SimTermLine
{
private $line;
private $commandPrep;
private $typePrep;
private $typeSpeed;
private $delay;
private $customDelay = false;
private $lineColor;
private $lineData;
private $lineAttrs;
public function __construct($plaintext, $commandPrep, $typePrep, $defaultDelay, $typingSpeed)
{
$this->line = $plaintext;
$this->commandPrep = $commandPrep;
$this->typePrep = $typePrep;
$this->delay = $defaultDelay;
$this->lineData = array();
$this->lineColor = "";
$this->lineAttrs = "";
$this->typeSpeed = $typingSpeed;
}
public function getData($filters=array())
{
/* One more trim */
$this->line = trim(preg_replace_callback('/##([^#]*)##/', array($this, 'modifier'), $this->line));
if ( (!empty($this->commandPrep)) && (strchr($this->commandPrep, $this->line[0]) !== false) )
$this->linedata['type'] = 'command';
elseif ( (!empty($this->typePrep)) && (strchr($this->typePrep, $this->line[0]) !== false) )
$this->linedata['type'] = 'type';
else
$this->linedata['type'] = 'line';
if (in_array($this->linedata['type'], array('command', 'type')))
$this->line = trim(substr($this->line, 1));
$this->linedata['attrs'] = trim($this->lineAttrs.' '.$this->lineColor);
foreach ($filters as $filter)
$this->line = call_user_func($filter, $this->line);
$this->linedata['text'] = $this->line;
$this->linedata['delay'] = $this->delay;
$this->linedata['speed'] = $this->typeSpeed;
$this->linedata['customDelay'] = $this->customDelay;
return $this->linedata;
}
public function modifier ($matches)
{
$commands = explode(',', $matches[1]);
foreach ($commands as $command)
{
$eq = explode('=', $command);
switch ($eq[0])
{
case 'red':
case 'yellow':
case 'green':
case 'blue':
case 'grey':
$this->lineColor=$eq[0];
break;
case 'underline':
$this->lineAttrs.=' underlined';
break;
case 'blink':
$this->lineAttrs.=' blink';
break;
case 'active':
$this->lineAttrs.=' active';
break;
case 'speed':
$this->typeSpeed=$eq[1];
break;
case 'color':
$this->lineColor=$eq[1];
break;
case 'delay':
$this->delay = $eq[1];
$this->customDelay = true;
break;
}
}
return "";
}
};