Author Topic: How to into Github?  (Read 878 times)

Insanegame27

  • Full Member
  • ***
  • Posts: 144
  • Karma: +7/-3
  • I am the Bopmaster, master of Bops.
    • View Profile
How to into Github?
« on: June 17, 2016, 12:20:33 PM »
Could I have a noobs explanation of exactly how to use Github? If, for example, I wanted to add a tiny amount of food production to the saddlery to simulate harnesses and the such being used to farm more easily and efficiently, What steps would I need to go through?
Now I have a mental image of horses lined up in a goods factory, building things on an assembly line.

Andrew

  • Game Master / Lead Developer
  • Administrator
  • Sr. Member
  • *****
  • Posts: 1797
  • Karma: +75/-7
  • Mildly Amused
    • View Profile
    • Lemuria Community Fan Site
Re: How to into Github?
« Reply #1 on: June 17, 2016, 12:46:20 PM »
First, you'll need to create an account on GitHub, after that, you'll go to the repository that's linked from this forum, and find the file you want to edit to create this change. Then click the pencil icon and start on your edit. This will automatically create a fork of the project in your own repository when you save the edit.

From there, you can create a pull request, which is you asking that your fork be merged with Tom's repository.

If you were to look at the repository right now, you'd see that there are two pull requests already, one from Weaver/Aelwyn changing the combat and economy system, and another from myself (Zanaras) adding a bunch of Dungeon stuff. These are just requests though, which means that Tom still has to approve/reject them.

And, even if he accepts them, it doesn't mean they're in the game just like that, but it means they'll most likely go up in the next big update.
Standing for the creation of interesting things since Year 1, Week 5, Day 4.
Favorite cold beverage: Strawberry Shake
My hobbies: Fixing computers, video games, anime, manga, some other stuff, sleep (in no particular order)

Insanegame27

  • Full Member
  • ***
  • Posts: 144
  • Karma: +7/-3
  • I am the Bopmaster, master of Bops.
    • View Profile
Re: How to into Github?
« Reply #2 on: June 17, 2016, 01:08:35 PM »
I added a PR, did I do it right?
Now I have a mental image of horses lined up in a goods factory, building things on an assembly line.

Andrew

  • Game Master / Lead Developer
  • Administrator
  • Sr. Member
  • *****
  • Posts: 1797
  • Karma: +75/-7
  • Mildly Amused
    • View Profile
    • Lemuria Community Fan Site
Re: How to into Github?
« Reply #3 on: June 17, 2016, 01:21:54 PM »
Certainly looks like you did. Well done.
Standing for the creation of interesting things since Year 1, Week 5, Day 4.
Favorite cold beverage: Strawberry Shake
My hobbies: Fixing computers, video games, anime, manga, some other stuff, sleep (in no particular order)

Tom

  • Head Developer
  • Administrator
  • Hero Member
  • *****
  • Posts: 6325
  • Karma: +102/-15
    • View Profile
    • Might & Fealty
Re: How to into Github?
« Reply #4 on: June 17, 2016, 02:19:27 PM »
I am actually really slow to react to pull requests.

The reason is that I am not actually running off the github repository. So I need to more or less manually merge with my actual git repository.

feyeleanor

  • Full Member
  • ***
  • Posts: 191
  • Karma: +7/-3
    • View Profile
    • Clan Dubhaine
Re: How to into Github?
« Reply #5 on: September 06, 2016, 06:27:09 PM »
I'd like to sort out some of the annoyances around resupply.

a. Enable Mercenary resupply

b. Rework |Resupply All| so as to:
  • resupply from dead soldiers
  • resupply from settlement
  • resupply from camp followers

c. Rework |disband| for camp followers so that supplies are apportioned equally across remaining camp followers

d. Rework changing camp follower equipment so that supplies are apportioned equally across remaining camp followers


Would these changes be welcome?

Tom

  • Head Developer
  • Administrator
  • Hero Member
  • *****
  • Posts: 6325
  • Karma: +102/-15
    • View Profile
    • Might & Fealty
Re: How to into Github?
« Reply #6 on: September 07, 2016, 10:00:33 AM »
I don't understand half of them because such code is already there, though it may be imperfect. You want to fix / improve it?

In general, anything that is small changes of improvement is very welcome.

Troublesome is anything that changes database values (buildings, weapons, etc.) because it needs an extra script to apply the change to the live system, and so far nobody has written a template for that. Maybe I should spend half an hour to do just that, if I find the time.

Andrew

  • Game Master / Lead Developer
  • Administrator
  • Sr. Member
  • *****
  • Posts: 1797
  • Karma: +75/-7
  • Mildly Amused
    • View Profile
    • Lemuria Community Fan Site
Re: How to into Github?
« Reply #7 on: September 07, 2016, 10:04:07 AM »
If those are things that aren't already handled (I know mercenaries are handled semi-uniquely, but I'm uncertain to what extent), it makes sense, would relieve annoyance (where'd my stuff go?!), and doesn't go against the core ideas of the game. Passes my, "Is this idea good" checks. I'm not Tom, but I'd say they'd be welcomed. I'm not sure why Tom would have a problem with any of those either, given they don't change core mechanics or massively disrupt the balance of the game. And Tom replies while I'm posting. Nice. And then I manage to post while posting myself. Keyboard shortcuts are not my friend this afternooon.  :-\

None of these should require changing database specifics for costs/stats, from my understanding at least. They should only change the way the game interacts with the database.

Tom, I am seriously tempted to offer to pay you to make a template though. . . . How much would that cost?
 
Actually, I just saw that you talked a bit about this on GitHub. Give me a moment (next post) and let me know how far off base I am.
« Last Edit: September 07, 2016, 03:30:00 PM by Andrew »
Standing for the creation of interesting things since Year 1, Week 5, Day 4.
Favorite cold beverage: Strawberry Shake
My hobbies: Fixing computers, video games, anime, manga, some other stuff, sleep (in no particular order)

Andrew

  • Game Master / Lead Developer
  • Administrator
  • Sr. Member
  • *****
  • Posts: 1797
  • Karma: +75/-7
  • Mildly Amused
    • View Profile
    • Lemuria Community Fan Site
Re: How to into Github?
« Reply #8 on: September 07, 2016, 04:24:38 PM »
So... a script that 1) loads an array, 2) checks if things in that array exist already in the database, 3) updates the existing entries if they do, 4) creates them if they don't, and 5) commits it all.

Which, unless I'm massively off base, is basically this portion of the LoadBuildingData.php, from when I presume you made this yourself to handle irrigation ditches and fisheries and lumber yards:

Code: [Select]
   public function load(ObjectManager $manager) {
      $all = new ArrayCollection();
      foreach ($this->buildings as $name=>$data) {
         $type = $manager->getRepository('BM2SiteBundle:BuildingType')->findOneByName($name);
         if (!$type) {
            $type = new BuildingType();
            $manager->persist($type);
         }
         $type->setName($name);
         $type->setBuildHours($data['work']);
         $type->setAutoPopulation($data['auto'])->setMinPopulation($data['min']);
         $type->setPerPeople($data['ratio']);
         $type->setDefenses(isset($data['defenses'])?$data['defenses']:0);
         $type->setSpecialConditions(isset($data['conditions'])?true:false);
         if (isset($data['icon'])) {
            $type->setIcon($data['icon']);
         }
         $all->add($type);
         $this->addReference('buildingtype: '.strtolower($name), $type);
         foreach ($this->resources[$name] as $resourcename => $resourcedata) {
            $rt = $manager->getRepository('BM2SiteBundle:ResourceType')->findOneByName($resourcename);
            if (!$rt) {
               echo "can't find $resourcename needed by $name.\n";
            }
            $br = null;
            foreach ($type->getResources() as $r) {
               if ($r->getResourceType() == $rt) {
                  $br = $r;
                  break;
               }
            }
            if (!$br) {
               $br = new BuildingResource;
               $manager->persist($br);
            }
            $br->setBuildingType($type);
            $br->setResourceType($rt);
            $br->setRequiresConstruction(isset($resourcedata['construction'])?$resourcedata['construction']:0);
            $br->setRequiresOperation(isset($resourcedata['operation'])?$resourcedata['operation']:0);
            $br->setProvidesOperation(isset($resourcedata['provides'])?$resourcedata['provides']:0);
            $br->setProvidesOperationBonus(isset($resourcedata['bonus'])?$resourcedata['bonus']:0);
         }
      }
      // FIXME: this does not yet clean out old data (for updates)
      foreach ($this->buildings as $name=>$data) {
         if (isset($data['requires'])) {
            $me = $all->filter(function($type) use ($name) {
               return $type->getName() == $name;
            })->first();
            foreach ($data['requires'] as $requires) {
               $enabler = $all->filter(function($type) use ($requires) {
                  return $type->getName() == $requires;
               })->first();
               if ($enabler) {
                  if (!$me->getRequires()->contains($enabler)) {
                     $me->getRequires()->add($enabler);
                  }
               } else {
                  echo "can't find $requires needed by $name.\n";
               }
            }
         }
      }
      $manager->flush();
   }

This is what I was trying to point out elsewhere but, maybe I was tired or something, and included another that doesn't have this portion. The only bit I'm uncertain on is whether you'd need to include the "(ObjectManager $manager)" when you pass variables to the method, because if I'm understanding this right, which one you're doing should already be declared in the code, and wether it'd be $manager->flush() or $em->flush().

You could then adapt it to something like, if we were going to load in Seats of Power today, for instance...

Code: [Select]
  public function updateBuildings20160907(ObjectManager $manager) {
      $buildings = array(
            'Local Seat'      => array('auto' =>   0, 'min' =>    100, 'work' =>   5000, 'ratio' =>   500, 'defenses' => 5, 'requires' => array('Carpenter','Dirt Streets'), 'conditions'=>true),
            'Regional Seat'      => array('auto' =>   0, 'min' =>   1000, 'work' => 500000, 'ratio' =>   250, 'defenses' => 10, 'requires' => array('Local Seat','Mason','Blacksmith','Paved Streets','Inn','School','Town Hall','Guardhouse','Wood Wall'), 'conditions'=>true),
            'Imperial Seat'      => array('auto' =>   0, 'min' =>   3000, 'work' =>1000000, 'ratio' =>   100, 'defenses' => 10, 'requires' => array('Regional Seat','Stone Wall','Library','Saddler','Barracks'), 'conditions'=>true),
         );
      $resources = array(
            'Local Seat'      => array('wood'=>array('construction'=>2000), 'metal'=>array('construction'=>300), 'money'=>array('construction'=>100, 'provides'=>2, 'bonus'=>1), 'food'=>array('bonus'=>1)),
            'Regional Seat'      => array('wood'=>array('construction'=>8000), 'metal'=>array('construction'=>1000), 'money'=>array('construction'=>1000, 'bonus'=>3), 'food'=>array('bonus'=>3)),
            'Imperial Seat'      => array('wood'=>array('construction'=>20000), 'metal'=>array('construction'=>2500), 'money'=>array('construction'=>2500, 'operation'=>10, 'bonus'=>6), 'food'=>array('bonus'=>6)),
         );
      $all = new ArrayCollection();
      foreach ($buildings as $name=>$data) {
         $type = $manager->getRepository('BM2SiteBundle:BuildingType')->findOneByName($name);
         if (!$type) {
            $type = new BuildingType();
            $manager->persist($type);
         }
         $type->setName($name);
         $type->setBuildHours($data['work']);
         $type->setAutoPopulation($data['auto'])->setMinPopulation($data['min']);
         $type->setPerPeople($data['ratio']);
         $type->setDefenses(isset($data['defenses'])?$data['defenses']:0);
         $type->setSpecialConditions(isset($data['conditions'])?true:false);
         if (isset($data['icon'])) {
            $type->setIcon($data['icon']);
         }
         $all->add($type);
         $this->addReference('buildingtype: '.strtolower($name), $type);
         foreach ($resources[$name] as $resourcename => $resourcedata) {
            $rt = $manager->getRepository('BM2SiteBundle:ResourceType')->findOneByName($resourcename);
            if (!$rt) {
               echo "can't find $resourcename needed by $name.\n";
            }
            $br = null;
            foreach ($type->getResources() as $r) {
               if ($r->getResourceType() == $rt) {
                  $br = $r;
                  break;
               }
            }
            if (!$br) {
               $br = new BuildingResource;
               $em->persist($br);
            }
            $br->setBuildingType($type);
            $br->setResourceType($rt);
            $br->setRequiresConstruction(isset($resourcedata['construction'])?$resourcedata['construction']:0);
            $br->setRequiresOperation(isset($resourcedata['operation'])?$resourcedata['operation']:0);
            $br->setProvidesOperation(isset($resourcedata['provides'])?$resourcedata['provides']:0);
            $br->setProvidesOperationBonus(isset($resourcedata['bonus'])?$resourcedata['bonus']:0);
         }
      }
      // FIXME: this does not yet clean out old data (for updates)
      foreach ($this->buildings as $name=>$data) {
         if (isset($data['requires'])) {
            $me = $all->filter(function($type) use ($name) {
               return $type->getName() == $name;
            })->first();
            foreach ($data['requires'] as $requires) {
               $enabler = $all->filter(function($type) use ($requires) {
                  return $type->getName() == $requires;
               })->first();
               if ($enabler) {
                  if (!$me->getRequires()->contains($enabler)) {
                     $me->getRequires()->add($enabler);
                  }
               } else {
                  echo "can't find $requires needed by $name.\n";
               }
            }
         }
      }
      $manager->flush();
   }

I will say that I should be asleep as of my posting this, so I did not check that nearly as well as I should, but if I'm going the right direction, you'd remove the entire "foreach ($resources[$name] as $resourcename => $resourcedata) {. . .}" for other types, and change BM2SiteBundle:BuildingType to BM2SiteBundle:[Thing]Type, replacing [Thing] for equipment, entourage, so on, udpating the $type->set[Stuff] according to the properties included in each array for the respective types. From there, you'd just toss in $variable = array(stuff) for whatever you wanted to update. Preumably, if you wanted to (because GUI or some reason), you could probably build this into the game's admin role, so they go to a page, press a button, and the game handles everything from there.
« Last Edit: September 07, 2016, 04:28:12 PM by Andrew »
Standing for the creation of interesting things since Year 1, Week 5, Day 4.
Favorite cold beverage: Strawberry Shake
My hobbies: Fixing computers, video games, anime, manga, some other stuff, sleep (in no particular order)

Tom

  • Head Developer
  • Administrator
  • Hero Member
  • *****
  • Posts: 6325
  • Karma: +102/-15
    • View Profile
    • Might & Fealty
Re: How to into Github?
« Reply #9 on: September 08, 2016, 07:37:26 PM »
Which, unless I'm massively off base, is basically this portion of the LoadBuildingData.php, from when I presume you made this yourself to handle irrigation ditches and fisheries and lumber yards:

Yes, that is a good template. Note that it contains some specifics and needs to be updated slightly to work as a command (because there's no load method that gets the em passed automatically, move the code into execute and use the same $em = ... code you find in other commands).

Code: [Select]
$manager->flush() or $em->flush().
That's just inconsistency in naming essentially the same variable.


Quote
I will say that I should be asleep as of my posting this, so I did not check that nearly as well as I should, but if I'm going the right direction, you'd remove the entire "foreach ($resources[$name] as $resourcename => $resourcedata) {. . .}" for other types, and change BM2SiteBundle:BuildingType to BM2SiteBundle:[Thing]Type, replacing [Thing] for equipment, entourage, so on, udpating the $type->set[Stuff] according to the properties included in each array for the respective types. From there, you'd just toss in $variable = array(stuff) for whatever you wanted to update. Preumably, if you wanted to (because GUI or some reason), you could probably build this into the game's admin role, so they go to a page, press a button, and the game handles everything from there.

That would be wonderful, if there were at least a CRUD interface for this, but don't forget the database is heavily interlinked with dependencies like the resources here.

But most of what you write is spot on, yes.
[/code]

Andrew

  • Game Master / Lead Developer
  • Administrator
  • Sr. Member
  • *****
  • Posts: 1797
  • Karma: +75/-7
  • Mildly Amused
    • View Profile
    • Lemuria Community Fan Site
Re: How to into Github?
« Reply #10 on: October 05, 2016, 05:12:40 PM »
So, I'm working on designing an actual update command system, and doing a lot of research on this fun stuff. Basically, there will be 1 command you use to actually apply updates (e.g. app/console update:tweak [file]), and a suite of other commands specific to each possible type of update. The type of update will be dynamic based on what the target file inlcudes.

How this will work, assuming you're in the root directory:

1. Enter command: app/console update:tweak ./src/BM2/UpdateBundle/Data/[Update#]/FILE
2. update:tweak will then do an if(!file_exists($target)), if not return error and end command, else, continue
3. update:tweak will then use function get_include_contents to load the target file.
4. the target file will exist of a variable defining $updatetype and $updatearray defining changes
5. it'll then proceed to switch ($updatetype) for each different type of update that can be run--it's easier to target one database change at a time after all
6. dependent on the $updatetype it'll then call a second command to process the array into the game's database, if $updatetype returns no matches, it'll error out at this point as well.
7. assuming there's no formatting errors, it'll then flush everything and report the update as successful.

For the record: the reason the command is update:tweak is because update:update looks odd (especially given I'm going to have more commands...), and I'm toying with another command that will allow reversion of major changes to database structure. Not sure it's worthwhile if you have proper version control and backups, but it's a good thought experiment. I'm thinking if you tell the command where each resource file is that defines table structure, have it encode it to binary, then store it in the database, you could pull it out if you need to undo something. You'd have another command that can come through, decode it, and then save it to a directory. Heck, for that matter, you could possibly have it default to saving it to where it's SUPPOSED to go.

Once you start getting to that point though, you start reaching the territory where the database this thing uses should not be the same one the game uses for storage.

Another thought experiment I'm trying to figure out (don't help me with these), is how to implement a versioning system and within-game accessible logs. And past that, is the possibility of having it just have a form that you can access to minor tweaks. URL would probably be something like .com/en/update/$type/. On that same note, you could also have a /status/$type/ route for querying all the presently set settings for things. Ideas. And yes, I do want it to have the ability to drop things as well, but that's a touch more complex.

I'm actually tempted to make this thing it's own repo, and then license it for free use for anyone else who gets stuck on updating symfony things en masse. It'd use the same structure as the datafixtures for the array that's updating, so I'm sure someone would find it to be useful (with minor editing).
« Last Edit: October 05, 2016, 05:15:19 PM by Andrew »
Standing for the creation of interesting things since Year 1, Week 5, Day 4.
Favorite cold beverage: Strawberry Shake
My hobbies: Fixing computers, video games, anime, manga, some other stuff, sleep (in no particular order)

Andrew

  • Game Master / Lead Developer
  • Administrator
  • Sr. Member
  • *****
  • Posts: 1797
  • Karma: +75/-7
  • Mildly Amused
    • View Profile
    • Lemuria Community Fan Site
Re: How to into Github?
« Reply #11 on: October 06, 2016, 11:11:44 PM »
Upon further thinking, having it do multiple sub-commands is probably needlessly complicating things.

I've also figured out how to make it work on just having an array, rather than have a file both define the update type and the update information. This also makes it very easy to include multiple differing types of updates. You won't be able to do updates for the same data types (like buildings or entourage or equipment) in the same pass, but I'm not sure why you'd want to do that--seems pretty counterproductive to not have included them all in one file. Oh, and you could include multiple arrays in one update file as well, assuming they are, again, updating different types of data.

I've got the shell of the command ready, that requires you supply 1 or more files, checks that the things you told it are actually files, complains if they aren't, includes them if they are, and will then run (not yet added code) certain things depending on the arrays supplied. Individual updates will be submitted as $[DataType]Update arrays, formatted the same way they are in the DataFixtures. You can see what I have so far at: https://github.com/Zanaras/mightandfealty/blob/updatebundle/src/BM2/UpdateBundle/Command/TweakCommand.php
« Last Edit: October 06, 2016, 11:28:36 PM by Andrew »
Standing for the creation of interesting things since Year 1, Week 5, Day 4.
Favorite cold beverage: Strawberry Shake
My hobbies: Fixing computers, video games, anime, manga, some other stuff, sleep (in no particular order)

Andrew

  • Game Master / Lead Developer
  • Administrator
  • Sr. Member
  • *****
  • Posts: 1797
  • Karma: +75/-7
  • Mildly Amused
    • View Profile
    • Lemuria Community Fan Site
Re: How to into Github?
« Reply #12 on: October 07, 2016, 01:21:08 AM »
Hm... I want to work a way that allows you to remove things and pass those through the update files. Not sure if I want to make it a special case and have all removals processed through a variable, or if I want to work it into the already existing cases somehow.

If I go with the previous, it means I have one case that will perform it's own switch depending on what it finds. This could be handled with an array in an array, with a switch.

If I go with the latter creating the updates gets considerably more complex, as I need to tell it which part of an array to do certain things with. Which again, will be arrays in arrays.

I suppose it really just comes down to where I want to add the switch. Hrm...
Standing for the creation of interesting things since Year 1, Week 5, Day 4.
Favorite cold beverage: Strawberry Shake
My hobbies: Fixing computers, video games, anime, manga, some other stuff, sleep (in no particular order)