Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

System placement fix #7

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions footer.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<script>window.jQuery || document.write('<script src="assets/js/vendor/jquery-1.11.1.min.js"><\/script>')</script>
<!-- <script src="js/plugins.js"></script> -->
<script src="http://code.createjs.com/easeljs-0.7.1.min.js"></script>
<script src="assets/js/vendor/jquery.playsound.js"></script>
<script src="assets/js/main.js"></script>
</body>
Expand Down
2 changes: 1 addition & 1 deletion inc/arrays.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
"Trader's Union",
"Syndicate",
"Lunar Industries", //From Duncan Jones' Moon. See this.

"NERSHA",
);

$phoneticAlphabet = array("Alpha", "Bravo", "Charlie", "Delta", "Echo", "Foxtrot", "Golf", "Hotel", "India", "Juliet", "Kilo", "Lima", "Mike", "November", "Oscar", "Papa", "Quebec", "Romeo", "Sierra", "Tango", "Uniform", "Victor", "Whiskey", "X-ray", "Yankee", "Zulu");
Expand Down
32 changes: 20 additions & 12 deletions inc/classes/syst.php
Original file line number Diff line number Diff line change
Expand Up @@ -118,10 +118,10 @@ public function getConnections($id) {
public function getMapLines(){
$db = new database();
$db->query("SELECT
dest.coord_x AS x1,
dest.coord_y AS y1,
origin.coord_x AS x2,
origin.coord_y AS y2
dest.coord_x AS dest_x,
dest.coord_y AS dest_y,
origin.coord_x AS origin_x,
origin.coord_y AS origin_y
FROM ssim_jump
LEFT OUTER JOIN ssim_syst AS origin ON ssim_jump.dest = origin.id
LEFT OUTER JOIN ssim_syst AS dest ON ssim_jump.origin = dest.id");
Expand Down Expand Up @@ -152,20 +152,28 @@ public function getJumpData($dest, $origin) {
return $db->single();
}
}

public function addNewSyst($syst) {
if ($this->canAddNewSyst($syst)) {
//New syst handler
$host = $this->getSyst($syst);

if (floor(rand(1,10)) < 5) {
$newX = $host->coord_x + floor(rand(-20,20));
$newY = $host->coord_y + floor(rand(-20,20));
} else {
$newX = $host->coord_x - floor(rand(-20,20));
$newY = $host->coord_y - floor(rand(-20,20));
$placementfactor = floor(rand(1,4));
if ($placementfactor === 4) { //+,+
$newX = $host->coord_x + floor(rand(-5,5));
$newY = $host->coord_y + floor(rand(-5,5));
} elseif ($placementfactor === 3) { //-,-
$newX = $host->coord_x - floor(rand(-5,5));
$newY = $host->coord_y - floor(rand(-5,5));
} elseif ($placementfactor === 2) { //+,-
$newX = $host->coord_x + floor(rand(-5,5));
$newY = $host->coord_y - floor(rand(-5,5));
} else { //-,+
$newX = $host->coord_x - floor(rand(-5,5));
$newY = $host->coord_y + floor(rand(-5,5));
}

if (floor(rand(1,10)) < 5) { //Chance for the new system to inherit the govt
//Chance for the new system to inherit the host govt
if (floor(rand(1,10)) < 5) {
$govt = $host->govt;
} else {
$govt = new govt();
Expand Down
133 changes: 133 additions & 0 deletions view/easel-map-test.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,133 @@
<?php

include '../inc/config.php';
$user = new user();
$syst = new syst();
$spob = new spob();
$systs = $syst->getSyst(null, true);
$jumps = $syst->getMapLines();
?>

<div class="fiftyfifty">
<h1>Test Page</h1>
<ul class="options">
<li><a href='home' class='page'>Back</a></li>
</ul>
</div>

<div class="fiftyfifty">
<canvas id="c" style="background: white; float: right; clear: left; background: black;" width="800" height="800">
</canvas>

<script>
var canvas = document.getElementById("c");
var context = canvas.getContext("2d");

var stage = new createjs.Stage("c");
var grid = new createjs.Shape();

grid.graphics.setStrokeStyle(1);
grid.graphics.beginStroke('#111');

for (var x = 0.5; x < canvas.width; x += 10) {
grid.graphics.mt(x, 0);
grid.graphics.lt(x, canvas.height);
grid.graphics.endStroke();
stage.addChild(grid);
stage.update();
}

for (var y = 0.5; y < canvas.height ; y += 10) {
grid.graphics.mt(x, 0);
grid.graphics.lt(canvas.width, y);
grid.graphics.endStroke();
stage.addChild(grid);
stage.update();
}




var halfw = canvas.width/2;
var halfh = canvas.height/2;
var zoom = 40;

function sysDot(x, y, name, id) {
var newx = (x * zoom) + halfw;
var newy = ((y * zoom) - halfh) * -1;
var circle = new createjs.Shape();
var name = name;
var id = id;
circle.graphics.beginFill("white").dc(newx, newy, 5);
stage.addChild(circle);

var text = new createjs.Text(name,'10px Helvetica','white');
text.x = newx+10;
text.y = newy-10;
stage.addChild(text);

stage.update();

}

function jumpLink(dest_x, dest_y, origin_x, origin_y) {
var dx = (dest_x * zoom) + halfw;
var dy = ((dest_y * zoom) - halfh) * -1;
var ox = (origin_x * zoom) + halfw;
var oy = ((origin_y * zoom) - halfh) * -1;
var line = new createjs.Shape();
line.graphics.setStrokeStyle(1);
line.graphics.beginStroke('#b4c7ff');
line.graphics.moveTo(dx,dy);
line.graphics.lineTo(ox,oy);
line.graphics.endStroke();
stage.addChild(line);
stage.update();
}

console.log(stage);


var systems = <?php echo $systs; ?>;
var jumps = <?php echo $jumps; ?>;

for (i in jumps) {
jumpLink(
jumps[i].dest_x/2,
jumps[i].dest_y/2,
jumps[i].origin_x/2,
jumps[i].origin_y/2
);
}

for (i in systems) {
// sysDot(
// systems[i].coord_x/2,
// systems[i].coord_y/2,
// systems[i].name,
// systems[i].id
// );
var newx = ((systems[i].coord_x/2) * zoom) + halfw;
var newy = (((systems[i].coord_y/2) * zoom) - halfh) * -1;
var circle = new createjs.Shape();
var name = systems[i].name;
var id = systems[i].id;
circle.graphics.beginFill("white").dc(newx, newy, 5);
stage.addChild(circle);

circle.addEventListener("click", function(event) {
console.log(this.name)
});

var text = new createjs.Text(name,'10px Helvetica','white');
text.x = newx+10;
text.y = newy-10;
stage.addChild(text);
stage.update();
}




</script>
</div>
89 changes: 77 additions & 12 deletions view/test.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@
$pilot = new pilot();
$syst = new syst($pilot->pilot->syst);
$spob = new spob($pilot->pilot->spob);

$systs = $syst->getSyst(null, true);
$jumps = $syst->getMapLines();
?>

<div class="leftbar">
Expand All @@ -16,21 +17,85 @@
</div>

<div class="center">
<?php
$stations = $spob->generateStation(10);
foreach($stations as $station) {
echo $station['name'] ."<br>";
echo $station['desc'] ." (Techlevel: ".$station['techlevel'].")<br><br>";
<canvas id="c" style="background: white; float: right; clear: left; background: black;" width="800" height="800">
</canvas>

<script>
var canvas = document.getElementById("c");
var context = canvas.getContext("2d");
context.beginPath();
//context.clearRect(0, 0, canvasW, canvasH);
for (var x = 0.5; x < canvas.width; x += 10) {
context.moveTo(x, 0);
context.lineTo(x, canvas.height);
}
echo "<hr>";

$planets = $spob->generatePlanets(10);
foreach ($planets as $planet) {
echo $planet['name'] ."<br>";
echo $planet['desc'] ." (Techlevel: ".$planet['techlevel'].")<br><br>";
for (var y = 0.5; y < canvas.height ; y += 10) {
context.moveTo(0, y);
context.lineTo(canvas.width, y);
}

?>
context.strokeStyle = "#111";
context.stroke();

var halfw = canvas.width/2;
var halfh = canvas.height/2;
var zoom = 40;

function sysDot(x, y, color, title, id) {
var newx = (x * zoom) + halfw;
var newy = ((y * zoom) - halfh) * -1;
if (color == undefined) {
var color = '#FFF';
}
context.beginPath();
context.arc(newx, newy, 2, 0, 2 * Math.PI, false);
context.strokeStyle = color;
context.fillStyle = color;
context.fill();
context.stroke();
context.beginPath();
context.font = 'normal 10pt Helvetica';
context.fillStyle = color;
context.fillText(title+' ('+newx+','+newy+') ('+ id +')',newx+5,newy+5);
console.log('('+newx+','+newy+')'+title+'',newx+5,newy+5);
}

function jumpLink(dest_x, dest_y, origin_x, origin_y) {
var dx = (dest_x * zoom) + halfw;
var dy = ((dest_y * zoom) - halfh) * -1;
var ox = (origin_x * zoom) + halfw;
var oy = ((origin_y * zoom) - halfh) * -1;
context.beginPath();
context.moveTo(ox,oy);
context.lineTo(dx,dy);
context.lineWidth = 1;
context.strokeStyle = '#428bca';
context.stroke();
}

var systems = <?php echo $systs; ?>;
var jumps = <?php echo $jumps; ?>;

for (i in jumps) {
jumpLink(
jumps[i].dest_x/2,
jumps[i].dest_y/2,
jumps[i].origin_x/2,
jumps[i].origin_y/2
);
}

for (i in systems) {
sysDot(
systems[i].coord_x/2,
systems[i].coord_y/2,
systems[i].color,
systems[i].name,
systems[i].id
);
}
</script>
</div>

<?php
Expand Down